Skip to content

Commit

Permalink
Add oao clean
Browse files Browse the repository at this point in the history
  • Loading branch information
guigrpa committed Feb 28, 2017
1 parent c6ed417 commit 69e19ca
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rules:
mode: 'minimum'
object-property-newline: off
class-methods-use-this: off
arrow-parens: ['error', 'always']
arrow-parens: off
react/sort-comp: off
react/jsx-first-prop-new-line: off
react/jsx-indent: off
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

* Add **`oao clean`** to remove all `node_modules` directories in sub-packages.
* Extract Parallel Console (now published as `storyboard-listener-console-parallel` under the Storyboard monorepo).

## 0.7.0 (Feb. 27, 2017)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Commands:
status [options] Show an overview of the monorepo status
bootstrap [options] Install external dependencies and create internal links
clean [options] Delete all node_modules directories from sub-packages
add [options] <sub-package> <packages...> Add dependencies to a sub-package
remove [options] <sub-package> <packages...> Remove dependencies from a sub-package
upgrade [options] <sub-package> [packages...] Upgrade some/all dependencies of a package
Expand Down Expand Up @@ -98,6 +99,11 @@ Installs all sub-package dependencies using **yarn**. External dependencies are
Development-only dependencies can be skipped by enabling the `--production` option, or setting the `NODE_ENV` environment variable to `production`.


### `oao clean`

Removes `node_modules` directories from all sub-packages, as well as from the root package.


### `oao add <sub-package> <deps...>`

Adds one or several dependencies to a sub-package. For external dependencies, it passes through [`yarn add`'s flags](https://yarnpkg.com/en/docs/cli/add). Internal dependencies are linked. Examples:
Expand Down
9 changes: 9 additions & 0 deletions __mocks__/rimraf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-env jest */

module.exports = jest.fn((p, options, cb) => {
if (typeof options === 'function') {
options();
} else {
cb();
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"globby": "6.1.0",
"inquirer": "3.0.1",
"kebab-case": "1.0.0",
"rimraf": "^2.6.1",
"semver": "5.3.0",
"shelljs": "0.7.6",
"split": "1.0.0",
Expand Down Expand Up @@ -72,7 +73,7 @@
"xxl": "^1.1.0"
},
"jest": {
"resetMocks": true,
"clearMocks": true,
"testRegex": "src/.*__tests__/.*\\.(test|spec)\\.(js|jsx)$",
"coverageDirectory": ".nyc_output",
"coverageReporters": [
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/__snapshots__/clean.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLEAN command executes the correct rimraf calls 1`] = `
Array [
"test/fixtures/packages/oao/node_modules",
"test/fixtures/packages/oao-b/node_modules",
"test/fixtures/packages/oao-c/node_modules",
"test/fixtures/packages/oao-d/node_modules",
"test/fixtures/packages/oao-priv/node_modules",
"node_modules",
]
`;
2 changes: 0 additions & 2 deletions src/__tests__/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import all from '../all';
jest.mock('../utils/shell');

describe('ALL command', () => {
beforeEach(() => { jest.resetAllMocks(); });

it('executes the specified command on all sub-packages', async () => {
const helpers = require('../utils/shell');
await all('ls', { src: 'test/fixtures/packages/*' });
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const spyFinalSpec = (spy, pkgName) => {
};

describe('BOOTSTRAP command', () => {
beforeEach(() => { jest.resetAllMocks(); });

it('does not modify any package.json', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
const base = path.join(process.cwd(), 'test/fixtures/packages');
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/clean.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env jest */
/* eslint-disable global-require, import/no-dynamic-require */

import clean from '../clean';

jest.mock('rimraf');

describe('CLEAN command', () => {
it('executes the correct rimraf calls', async () => {
const rimraf = require('rimraf');
await clean({ src: 'test/fixtures/packages/*' });
const paths = rimraf.mock.calls.map(call => call[0].replace(/\\/g, '/'));
expect(paths).toMatchSnapshot();
});
});
2 changes: 0 additions & 2 deletions src/__tests__/outdated.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const spyFinalSpec = (spy, pkgName) => {
};

describe('OUTDATED command', () => {
beforeEach(() => { jest.resetAllMocks(); });

it('does not modify any package.json', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
const base = path.join(process.cwd(), 'test/fixtures/packages');
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/prepublish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const COPY_SPECS = [
const normalizePath = (p) => p.split(path.sep).join('/');

describe('PREPUBLISH command', () => {
beforeEach(() => { jest.resetAllMocks(); });

it('copies READMEs as appropriate', async () => {
const helpers = require('../utils/shell');
await prepublish({ src: 'test/fixtures/packages/*', copyAttrs: COPY_SPECS.join(',') });
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/resetAllVersions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jest.mock('../utils/writeSpecs');
const PACKAGE_NAMES = ['oao', 'oao-b', 'oao-c', 'oao-d', 'oao-priv'];

describe('RESET_ALL_VERSIONS command', () => {
beforeEach(() => { jest.resetAllMocks(); });

it('does not modify any package.json (except for the version number)', async () => {
const writeSpecs = require('../utils/writeSpecs').default;
const base = path.join(process.cwd(), 'test/fixtures/packages');
Expand Down
31 changes: 31 additions & 0 deletions src/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @flow

import path from 'path';
import rimraf from 'rimraf';
import { mainStory, chalk } from 'storyboard';
import { readAllSpecs } from './utils/readSpecs';

type Options = { src: string };

const run = async ({ src: srcPatterns }: Options) => {
const allSpecs = await readAllSpecs(srcPatterns);
const pkgNames = Object.keys(allSpecs);
await Promise.all(
pkgNames.map(
pkgName => new Promise((resolve, reject) => {
const { pkgPath } = allSpecs[pkgName];
const nodeModulesPath = path.join(pkgPath, 'node_modules');
mainStory.info(`Removing ${chalk.cyan.bold(nodeModulesPath)}...`);
rimraf(nodeModulesPath, err => {
if (err) {
reject(err);
return;
}
resolve();
});
})
)
);
};

export default run;
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import program from 'commander';
import './utils/initConsole';
import status from './status';
import bootstrap from './bootstrap';
import clean from './clean';
import addRemoveUpgrade from './addRemoveUpgrade';
import outdated from './outdated';
import prepublish from './prepublish';
Expand All @@ -33,6 +34,9 @@ createCommand('bootstrap', 'Install external dependencies and create internal li
.option('--prod --production', 'skip external and internal development-only dependencies (also via NODE_ENV=production)')
.action((cmd) => bootstrap(cmd.opts()));

createCommand('clean', 'Delete all node_modules directories from sub-packages')
.action((cmd) => clean(cmd.opts()));

createCommand('add <sub-package> <packages...>', 'Add dependencies to a sub-package')
.option('-D --dev', 'add to `devDependencies` instead of `dependencies`')
.option('-P --peer', 'add to `peerDependencies` instead of `dependencies`')
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,12 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.
dependencies:
glob "^7.0.5"

rimraf@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
dependencies:
glob "^7.0.5"

rimraf@~2.5.1, rimraf@~2.5.4:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
Expand Down

0 comments on commit 69e19ca

Please sign in to comment.