This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added eslint * Dependency upgrades
- Loading branch information
Showing
6 changed files
with
1,256 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.yarn | ||
.yarnrc.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.