Skip to content

Commit

Permalink
feat(cli): add @carbon/cli package (carbon-design-system#2982)
Browse files Browse the repository at this point in the history
* chore(project): run sync task for package.json

* chore(ci): update to include check for sync

* feat(cli): add carbon-cli package for workspace tasks

* chore(ci): update ci message to be generic

* chore(cli): add sketch to deny list

* chore(project): run sync task

* feat(cli): add ci-check command
  • Loading branch information
joshblack authored Jun 10, 2019
1 parent 9870dbb commit 46bfaeb
Show file tree
Hide file tree
Showing 36 changed files with 524 additions and 65 deletions.
Binary file added .yarn/offline-mirror/cliui-5.0.0.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/remark-word-wrap-2.0.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/string-width-3.1.0.tgz
Binary file not shown.
Binary file removed .yarn/offline-mirror/unist-util-parents-0.1.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/wrap-ansi-5.1.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/yargs-13.2.4.tgz
Binary file not shown.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
},
"scripts": {
"build": "lerna run build --stream --prefix --npm-client yarn",
"ci-check": "node tasks/ci-check.js",
"ci-check": "carbon-cli ci-check",
"clean": "lerna run clean && lerna clean --yes && rimraf node_modules",
"doctoc": "doctoc --title '## Table of Contents' docs",
"format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'",
"format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd,components}/**'",
"format:staged": "prettier --write",
"lint:styles": "stylelint '**/*.{css,scss}' --config ./packages/stylelint-config-elements",
"sync": "node tasks/sync.js",
"sync": "carbon-cli sync",
"test": "cross-env BABEL_ENV=test jest",
"test:e2e": "cross-env BABEL_ENV=test jest --testPathPattern=e2e --testPathIgnorePatterns='examples,/packages/components/,/packages/react/'"
},
Expand All @@ -35,6 +35,7 @@
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.4.4",
"@carbon/cli": "10.3.0",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"babel-jest": "^24.8.0",
Expand All @@ -50,8 +51,6 @@
"lerna": "^3.13.4",
"lint-staged": "^8.1.5",
"prettier": "^1.17.0",
"remark": "^10.0.1",
"remark-word-wrap": "^2.0.2",
"rimraf": "^2.6.3",
"stylelint": "^10.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/browserslist-config-carbon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ yarn add browserslist-config-carbon

We're always looking for contributors to help us fix bugs, build new features,
or help us improve the project documentation. If you're interested, definitely
check out our [Contributing Guide](/.github/CONTRIBUTING.md) ! 👀
check out our [Contributing Guide](/.github/CONTRIBUTING.md)! 👀

## 📝 License

Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ yarn add @carbon/bundler

We're always looking for contributors to help us fix bugs, build new features,
or help us improve the project documentation. If you're interested, definitely
check out our [Contributing Guide](/.github/CONTRIBUTING.md) ! 👀
check out our [Contributing Guide](/.github/CONTRIBUTING.md)! 👀

## 📝 License

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/__mocks__/**
**/__tests__/**
**/examples/**
**/tasks/**
45 changes: 45 additions & 0 deletions packages/cli/bin/carbon-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env node

/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

// Inspired by Create React App
// https://github.com/facebook/create-react-app/blob/next/packages/create-react-app/index.js

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', error => {
console.error(error);
});

var chalk = require('chalk');
var packageJson = require('../package.json');

var currentNodeVersion = process.versions.node;
var semver = currentNodeVersion.split('.');
var major = semver[0];

if (major < 8) {
console.error(
chalk.red(
`You are running Node ${currentNodeVersion}.\n` +
`carbon-upgrade requires Node 8 or higher, please update your ` +
`version of Node.`
)
);
process.exit(1);
}

var main = require('../src/cli');

main(process).catch(error => {
console.error(error);
process.exit(1);
});
28 changes: 28 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@carbon/cli",
"private": true,
"version": "10.3.0",
"license": "Apache-2.0",
"bin": {
"carbon-cli": "./bin/carbon-cli.js"
},
"repository": "https://github.com/carbon-design-system/carbon/tree/master/packages/cli",
"bugs": "https://github.com/carbon-design-system/carbon/issues",
"keywords": [
"ibm",
"carbon",
"carbon-design-system",
"components",
"react"
],
"publishConfig": {
"access": "public"
},
"dependencies": {
"@carbon/cli-reporter": "10.2.0",
"fs-extra": "^8.0.1",
"prettier": "^1.18.2",
"remark": "^10.0.1",
"yargs": "^13.2.4"
}
}
28 changes: 28 additions & 0 deletions packages/cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const cli = require('yargs');
const packageJson = require('../package.json');

const commands = [require('./commands/ci-check'), require('./commands/sync')];

async function main({ argv, cwd }) {
cli
.scriptName(packageJson.name)
.version(packageJson.version)
.usage('Usage: $0 [options]');

for (const command of commands) {
command.register(cli);
}

cli.strict().parse(argv.slice(2)).argv;
}

module.exports = main;
38 changes: 24 additions & 14 deletions tasks/ci-check.js → packages/cli/src/commands/ci-check.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { reporter } = require('@carbon/cli-reporter');
const childProcess = require('child_process');
const util = require('util');
const { workspace } = require('../workspace');

const exec = util.promisify(childProcess.exec);

async function main() {
async function check(args, env) {
reporter.info('Running checks in CI...');

const options = {
cwd: process.cwd(),
cwd: env.root.directory,
};
const tasks = [
'yarn format:diff',
Expand All @@ -34,19 +42,21 @@ async function main() {
clearInterval(interval);
console.log();
reporter.success('Done! 🎉');
} finally {
} catch (error) {
clearInterval(interval);
console.log();
console.log(error.message);
console.log(error.stdout);
process.exit(1);
}
}

main().catch(error => {
console.log();
reporter.error(error.message);
if (error.stdout !== '') {
console.error(error.stdout);
}
if (error.stderr !== '') {
console.error(error.stderr);
}
process.exit(1);
});
function register(cli) {
cli.command('ci-check', 'run CI checks', {}, workspace(check));
return cli;
}

module.exports = {
check,
register,
};
49 changes: 49 additions & 0 deletions packages/cli/src/commands/sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { workspace } = require('../workspace');

const tasks = {
npm: require('./sync/npm'),
package: require('./sync/package'),
readme: require('./sync/readme'),
};

async function sync(args, env) {
const { target } = args;
const { packages, root } = env;
const tasksToRun = target === 'all' ? Object.keys(tasks) : [target];

for (const name of tasksToRun) {
const task = tasks[name];
await task.run(env);
}
}

function register(cli) {
cli.command(
'sync [target]',
'sync files across workspaces',
yargs => {
yargs.positional('target', {
describe: 'choose a target to sync',
choices: ['all', 'npm', 'package', 'readme'],
default: 'all',
});
},
workspace(sync)
);

return cli;
}

module.exports = {
sync,
register,
};
43 changes: 43 additions & 0 deletions packages/cli/src/commands/sync/npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const fs = require('fs-extra');
const path = require('path');

const defaultIgnorePatterns = [
'**/__mocks__/**',
'**/__tests__/**',
'**/examples/**',
'**/tasks/**',
];

function run({ packagePaths }) {
return Promise.all(
packagePaths.map(async ({ packageJson, packagePath }) => {
const ignorePath = path.join(packagePath, '.npmignore');
const ignorePatterns = defaultIgnorePatterns.slice();

if (await fs.pathExists(ignorePath)) {
const ignoreFile = await fs.readFile(ignorePath, 'utf8');
const localIgnorePatterns = ignoreFile.split('\n').filter(pattern => {
return ignorePatterns.indexOf(pattern) === -1;
});

ignorePatterns.push(...localIgnorePatterns);
}

await fs.writeFile(ignorePath, ignorePatterns.join('\n'));
})
);
}

module.exports = {
name: 'npm',
run,
};
Loading

0 comments on commit 46bfaeb

Please sign in to comment.