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

Commit

Permalink
Merge pull request #10 from e5mode/release/1.0.2
Browse files Browse the repository at this point in the history
Release/1.0.2
  • Loading branch information
CodeDead committed Aug 17, 2020
2 parents c24c7c2 + 310d636 commit 7ebd13c
Show file tree
Hide file tree
Showing 7 changed files with 1,936 additions and 158 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.yarn
.yarnrc.yml
build
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
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

![GitHub package.json version](https://img.shields.io/github/package-json/v/e5mode/yarn-up-all)
![GitHub](https://img.shields.io/github/license/e5mode/yarn-up-all)
![GitHub Releases](https://img.shields.io/github/downloads/e5mode/yarn-up-all/1.0.1/total)
![GitHub Releases](https://img.shields.io/github/downloads/e5mode/yarn-up-all/1.0.2/total)

## Description

This is a Yarn2 (Berry) plugin that will update all dependencies of a project with one simple command.

### Installation
## Scripts

### `yarn build`

Creates a minified version of the `yarn-up-all` plugin and places it in the `./build` folder.

## Installation

Make sure that you have Yarn2 installed before using this plugin. You can install Yarn2 by running the following command in your terminal:

```Bash
yarn set version berry
```

In order to install the plugin, you can run the following command in your terminal:

```Bash
yarn plugin import https://github.com/e5mode/yarn-up-all/releases/download/1.0.1/index.js
yarn plugin import https://github.com/e5mode/yarn-up-all/releases/download/1.0.2/index.js
```

### Usage
Expand Down
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"name": "yarn-up-all",
"version": "1.0.1",
"version": "1.0.2",
"description": "Yarn2 plugin that will upgrade all dependencies to their latest version with one simple command",
"main": "src/index.js",
"repository": "https://github.com/e5mode/yarn-up-all.git",
"author": "CodeDead",
"license": "MIT",
"private": true,
"scripts": {
"build": "minify src -d build"
},
"dependencies": {
"@yarnpkg/cli": "^2.1.1",
"@yarnpkg/core": "^2.1.1",
"@yarnpkg/plugin-essentials": "^2.1.0"
},
"devDependencies": {
"babel-minify": "^0.5.1",
"clipanion": "^2.4.4",
"eslint": "^7.7.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"yup": "^0.29.3"
}
}
173 changes: 81 additions & 92 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,107 +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);

/**
* Retrieve dependencies and devDependencies
* @param workspace The current Workspace
* @returns {*[]} an array of dependencies
*/
const getDependencies = (workspace) => {
const dependencies = workspace.manifest.dependencies;
const devDependencies = workspace.manifest.devDependencies;
/**
* 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;
};

return [...dependencies, ...devDependencies];
};
class UpAllCommand extends Command {

/**
* 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;
};

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 = getDependencies(workspace);
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 7ebd13c

Please sign in to comment.