Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
* Code cleanup
Browse files Browse the repository at this point in the history
* Added eslint
* Dependency upgrades
  • Loading branch information
CodeDead committed Aug 16, 2020
1 parent 7873f21 commit fe7d745
Show file tree
Hide file tree
Showing 6 changed files with 1,256 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.yarn
.yarnrc.yml
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"commonjs": true,
"es2020": true,
"node": true
},
"extends": [
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 11
},
"rules": {
}
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
yarnPath: .yarn/releases/yarn-2.1.1.cjs
plugins:
- ./src/index.js
nodeLinker: node-modules
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
},
"devDependencies": {
"clipanion": "^2.4.4",
"yup": "^0.29.2"
"eslint": "^7.7.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"yup": "^0.29.3"
}
}
161 changes: 81 additions & 80 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,96 @@
module.exports = {
name: 'yarn-up-all-plugin',
factory: require => {
name: 'yarn-up-all-plugin',
factory: (require) => {
const { Configuration, Project } = require('@yarnpkg/core');
// eslint-disable-next-line import/no-extraneous-dependencies
const { Cli, Command } = require('clipanion');
// eslint-disable-next-line import/no-extraneous-dependencies
const yup = require('yup');
const Essentials = require('@yarnpkg/plugin-essentials');

const {Configuration, Project} = require('@yarnpkg/core');
const {Cli, Command} = require('clipanion');
const yup = require('yup');
const Essentials = require('@yarnpkg/plugin-essentials');
/**
* Resolve the name of a package
* @param scope The scope of the descriptor
* @param name The name of the descriptor
* @returns {string|*} The full package name
*/
const resolveFullPackageName = (scope, name) => (scope ? `@${scope}/${name}` : name);

/**
* Resolve the name of a package
* @param scope The scope of the descriptor
* @param name The name of the descriptor
* @returns {string|*} The full package name
*/
const resolveFullPackageName = (scope, name) => {
return scope ? `@${scope}/${name}` : name;
};
/**
* Get the descriptor
* @param dependencies The dependencies
* @param exclude The list of full package names that should be excluded
* @returns {*[]} The descriptors
*/
const getDescriptors = (dependencies, exclude) => {
const descriptions = [...dependencies.values()];
if (exclude) {
return descriptions
.filter((descriptor) => {
const data = resolveFullPackageName(descriptor[1].scope, descriptor[1].name);
return !exclude.includes(data);
});
}
return descriptions;
};

/**
* Get the descriptor
* @param dependencies The dependencies
* @param exclude The list of full package names that should be excluded
* @returns {*[]} The descriptors
*/
const getDescriptors = (dependencies, exclude) => {
const descriptions = [...dependencies.values()];
if (exclude) {
return descriptions
.filter(descriptor => {
const data = resolveFullPackageName(descriptor[1].scope, descriptor[1].name);
return !exclude.includes(data);
});
}
return descriptions;
};
class UpAllCommand extends Command {

class UpAllCommand extends Command {
/**
* Execute the command
* @returns {Promise<void>}
*/
async execute() {
if (!Essentials.default.commands) {
throw new Error('Yarn commands are not available!');
}

/**
* Execute the command
* @returns {Promise<*>}
*/
async execute() {
if (!Essentials.default.commands) {
throw new Error('Yarn commands are not available!');
}
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const { workspace } = await Project.find(configuration, this.context.cwd);

const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {workspace} = await Project.find(configuration, this.context.cwd);
const dependencies = [
...workspace.manifest.dependencies,
...workspace.manifest.devDependencies,
];

const dependencies = [...workspace.manifest.dependencies, ...workspace.manifest.devDependencies];
const descriptors = getDescriptors(dependencies, this.exclude ? this.exclude.split(" ") : null);
const descriptors = getDescriptors(dependencies, this.exclude ? this.exclude.split(' ') : null);

const packageNames = descriptors.map(e => {
return resolveFullPackageName(e[1].scope, e[1].name);
});
const packageNames = descriptors.map((e) => resolveFullPackageName(e[1].scope, e[1].name));

const cli = Cli.from(Essentials.default.commands);
return await cli.runExit(['up', ...packageNames], this.context);
}
}
const cli = Cli.from(Essentials.default.commands);
return cli.runExit(['up', ...packageNames], this.context);
}
}

UpAllCommand.addOption('exclude', Command.String('--exclude'));
UpAllCommand.addPath('up-all');
UpAllCommand.addOption('exclude', Command.String('--exclude'));
UpAllCommand.addPath('up-all');

UpAllCommand.schema = yup.object().shape({
exclude: yup.string()
});
UpAllCommand.schema = yup.object().shape({
exclude: yup.string(),
});

UpAllCommand.usage = Command.Usage({
description: 'Yarn2 plugin that will upgrade all dependencies to their latest version with one simple command',
details: 'This command will upgrade all dependencies to their latest version',
examples: [
[
`Upgrade all dependencies`,
`yarn up-all`
],
[
`Upgrade all dependencies but exclude a single dependency`,
`yarn up-all --exclude react-dom`
],
[
`Upgrade all dependencies but exclude multiple dependencies`,
`yarn up-all --exclude "react-dom react-router"`
]]
});
UpAllCommand.usage = Command.Usage({
description: 'Yarn2 plugin that will upgrade all dependencies to their latest version with one simple command',
details: 'This command will upgrade all dependencies to their latest version',
examples: [
[
'Upgrade all dependencies',
'yarn up-all',
],
[
'Upgrade all dependencies but exclude a single dependency',
'yarn up-all --exclude react-dom',
],
[
'Upgrade all dependencies but exclude multiple dependencies',
'yarn up-all --exclude "react-dom react-router"',
]],
});

return {
commands: [
UpAllCommand,
],
};
}
return {
commands: [
UpAllCommand,
],
};
},
};
Loading

0 comments on commit fe7d745

Please sign in to comment.