@carbon/cli 10.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +57 -0
  3. package/bin/carbon-cli.js +46 -0
  4. package/docker-compose.yml +13 -0
  5. package/package.json +56 -0
  6. package/src/changelog.js +217 -0
  7. package/src/cli.js +39 -0
  8. package/src/commands/bundle/bundlers.js +14 -0
  9. package/src/commands/bundle/javascript.js +142 -0
  10. package/src/commands/bundle.js +67 -0
  11. package/src/commands/changelog.js +70 -0
  12. package/src/commands/check.js +71 -0
  13. package/src/commands/ci-check.js +51 -0
  14. package/src/commands/component.js +130 -0
  15. package/src/commands/contribute/setup.js +232 -0
  16. package/src/commands/contribute/tools/getGitHubClient.js +73 -0
  17. package/src/commands/contribute.js +16 -0
  18. package/src/commands/inline.js +170 -0
  19. package/src/commands/publish.js +274 -0
  20. package/src/commands/release.js +302 -0
  21. package/src/commands/sassdoc/tools.js +405 -0
  22. package/src/commands/sassdoc.js +90 -0
  23. package/src/commands/sync/npm.js +43 -0
  24. package/src/commands/sync/package.js +122 -0
  25. package/src/commands/sync/readme.js +68 -0
  26. package/src/commands/sync/remark/remark-monorepo.js +425 -0
  27. package/src/commands/sync.js +39 -0
  28. package/src/compile.js +26 -0
  29. package/src/component/index.js +47 -0
  30. package/src/component/templates/component.template.js +19 -0
  31. package/src/component/templates/index.template.js +9 -0
  32. package/src/component/templates/mdx.template.mdx +37 -0
  33. package/src/component/templates/story.template.js +22 -0
  34. package/src/component/templates/test.template.js +35 -0
  35. package/src/git.js +38 -0
  36. package/src/logger.js +95 -0
  37. package/src/workspace.js +60 -0
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Copyright IBM Corp. 2018, 2018
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const { babel } = require('@rollup/plugin-babel');
11
+ const commonjs = require('@rollup/plugin-commonjs');
12
+ const { nodeResolve } = require('@rollup/plugin-node-resolve');
13
+ const { pascalCase } = require('change-case');
14
+ const fs = require('fs-extra');
15
+ const path = require('path');
16
+ const { rollup } = require('rollup');
17
+
18
+ async function bundle(entrypoint, options) {
19
+ const globals = options.globals ? formatGlobals(options.globals) : {};
20
+ const { name } = options;
21
+ const packageFolder = await findPackageFolder(entrypoint);
22
+
23
+ const outputFolders = [
24
+ {
25
+ format: 'esm',
26
+ directory: path.join(packageFolder, 'es'),
27
+ },
28
+ {
29
+ format: 'cjs',
30
+ directory: path.join(packageFolder, 'lib'),
31
+ },
32
+ {
33
+ format: 'umd',
34
+ directory: path.join(packageFolder, 'umd'),
35
+ },
36
+ ];
37
+
38
+ await Promise.all(outputFolders.map(({ directory }) => fs.remove(directory)));
39
+
40
+ const jsEntryPoints = outputFolders.map(({ directory, format }) => ({
41
+ file: path.join(directory, 'index.js'),
42
+ format,
43
+ }));
44
+
45
+ const packageJsonPath = path.join(packageFolder, 'package.json');
46
+ const packageJson = await fs.readJson(packageJsonPath);
47
+ const { dependencies = {} } = packageJson;
48
+
49
+ const bundle = await rollup({
50
+ input: entrypoint,
51
+ external: Object.keys(dependencies),
52
+ plugins: [
53
+ babel({
54
+ exclude: 'node_modules/**',
55
+ babelrc: false,
56
+ presets: [
57
+ [
58
+ '@babel/preset-env',
59
+ {
60
+ modules: false,
61
+ targets: {
62
+ browsers: ['last 1 version', 'ie >= 11', 'Firefox ESR'],
63
+ },
64
+ },
65
+ ],
66
+ ],
67
+ babelHelpers: 'bundled',
68
+ }),
69
+ nodeResolve(),
70
+ commonjs({
71
+ include: [/node_modules/],
72
+ extensions: ['.js'],
73
+ }),
74
+ ],
75
+ });
76
+
77
+ await Promise.all(
78
+ jsEntryPoints.map(({ format, file }) => {
79
+ const outputOptions = {
80
+ format,
81
+ file,
82
+ exports: 'auto',
83
+ };
84
+
85
+ if (format === 'umd') {
86
+ outputOptions.name = name;
87
+ outputOptions.globals = {
88
+ ...formatDependenciesIntoGlobals(dependencies),
89
+ ...globals,
90
+ };
91
+ }
92
+
93
+ return bundle.write(outputOptions);
94
+ })
95
+ );
96
+ }
97
+
98
+ function formatGlobals(string) {
99
+ const mappings = string.split(',').map((mapping) => {
100
+ return mapping.split('=');
101
+ });
102
+ return mappings.reduce(
103
+ (acc, [pkg, global]) => ({
104
+ ...acc,
105
+ [pkg]: global,
106
+ }),
107
+ {}
108
+ );
109
+ }
110
+
111
+ function formatDependenciesIntoGlobals(dependencies) {
112
+ return Object.keys(dependencies).reduce((acc, key) => {
113
+ const parts = key.split('/').map((identifier, i) => {
114
+ if (i === 0) {
115
+ return identifier.replace(/@/, '');
116
+ }
117
+ return identifier;
118
+ });
119
+
120
+ return {
121
+ ...acc,
122
+ [key]: pascalCase(parts.join(' ')),
123
+ };
124
+ }, {});
125
+ }
126
+
127
+ async function findPackageFolder(entrypoint) {
128
+ let packageFolder = entrypoint;
129
+
130
+ while (packageFolder !== '/' && path.dirname(packageFolder) !== '/') {
131
+ packageFolder = path.dirname(packageFolder);
132
+ const packageJsonPath = path.join(packageFolder, 'package.json');
133
+
134
+ if (await fs.pathExists(packageJsonPath)) {
135
+ break;
136
+ }
137
+ }
138
+
139
+ return packageFolder;
140
+ }
141
+
142
+ module.exports = bundle;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Copyright IBM Corp. 2019, 2019
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const path = require('path');
11
+ const { createLogger } = require('../logger');
12
+ const bundlers = require('./bundle/bundlers');
13
+
14
+ const logger = createLogger('bundle');
15
+
16
+ async function bundle({ entrypoint, name, globals }) {
17
+ logger.start('bundle');
18
+
19
+ const cwd = process.cwd();
20
+ const extension = path.extname(entrypoint);
21
+
22
+ if (!bundlers.has(extension)) {
23
+ logger.info(
24
+ `Invalid extension: \`${extension}\` on entrypoint: \`${entrypoint}\``
25
+ );
26
+ process.exit(1);
27
+ }
28
+
29
+ try {
30
+ const bundle = bundlers.get(extension);
31
+ await bundle(path.join(cwd, entrypoint), {
32
+ name,
33
+ globals,
34
+ });
35
+ } catch (error) {
36
+ logger.info(`Unexpected error occurred while bundling ${entrypoint}:`);
37
+ console.log(error);
38
+ process.exit(1);
39
+ }
40
+
41
+ logger.stop();
42
+ }
43
+
44
+ module.exports = {
45
+ command: 'bundle <entrypoint>',
46
+ desc: 'bundle the given .js entrypoint',
47
+ builder(yargs) {
48
+ yargs.positional('entrypoint', {
49
+ type: 'string',
50
+ describe: 'the entrypoint Javascript file',
51
+ });
52
+
53
+ yargs.options({
54
+ n: {
55
+ alias: 'name',
56
+ describe: 'the name of the module for the UMD build',
57
+ type: 'string',
58
+ },
59
+ g: {
60
+ alias: 'globals',
61
+ describe: 'global module names',
62
+ type: 'string',
63
+ },
64
+ });
65
+ },
66
+ handler: bundle,
67
+ };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright IBM Corp. 2019, 2019
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const clipboard = require('clipboardy');
11
+ const { prompt } = require('inquirer');
12
+ const { generate } = require('../changelog');
13
+ const { fetchLatestFromUpstream } = require('../git');
14
+ const { createLogger, displayBanner } = require('../logger');
15
+ const { getPackages } = require('../workspace');
16
+
17
+ const logger = createLogger('changelog');
18
+
19
+ /**
20
+ * Outputs a changelog for the list of packages in a lerna/yarn workspace for
21
+ * the given tag range. You can specify the range of commits to get the
22
+ * changelog for by using git tags, or the name of a branch. For example:
23
+ * v10.5.1..master or v10.5.0..v10.5.1
24
+ * @returns {void}
25
+ */
26
+ async function changelog({ range }) {
27
+ displayBanner();
28
+
29
+ logger.start('Fetching latest git information from upstream');
30
+ await fetchLatestFromUpstream();
31
+ logger.stop();
32
+
33
+ logger.start('Getting a list of all packages in the project');
34
+ const packages = await getPackages();
35
+ logger.stop();
36
+
37
+ const [lastTag, tag] = range.split('..');
38
+ logger.start(`Generating a changelog for range: ${range}`);
39
+ const changelog = await generate(packages, lastTag, tag);
40
+ logger.stop();
41
+
42
+ const { copy } = await prompt([
43
+ {
44
+ type: 'confirm',
45
+ name: 'copy',
46
+ message: 'Would you like to copy the changelog to your clipboard?',
47
+ },
48
+ ]);
49
+
50
+ if (copy) {
51
+ clipboard.writeSync(changelog);
52
+ // eslint-disable-next-line no-console
53
+ console.log('Done!');
54
+ } else {
55
+ // eslint-disable-next-line no-console
56
+ console.log(changelog);
57
+ }
58
+ }
59
+
60
+ module.exports = {
61
+ command: 'changelog <range>',
62
+ desc: 'generate the changelog for the given git tag range',
63
+ builder(yargs) {
64
+ yargs.positional('range', {
65
+ describe: 'the git tag range to generate a changelog for',
66
+ type: 'string',
67
+ });
68
+ },
69
+ handler: changelog,
70
+ };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Copyright IBM Corp. 2019, 2019
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const glob = require('fast-glob');
11
+ const path = require('path');
12
+ const { createLogger } = require('../logger');
13
+ const compile = require('../compile');
14
+
15
+ const logger = createLogger('check');
16
+
17
+ async function check({ glob: pattern, ignore = [], list = false }) {
18
+ const cwd = process.cwd();
19
+
20
+ logger.start('check');
21
+ logger.info(`Running in: ${cwd}`);
22
+ logger.info(`Checking pattern: '${pattern}', ignoring: '${ignore}'`);
23
+
24
+ const files = await glob(pattern, {
25
+ cwd,
26
+ ignore,
27
+ });
28
+
29
+ logger.info(`Compiling ${files.length} files...`);
30
+
31
+ try {
32
+ compile(files.map((file) => path.join(cwd, file)));
33
+
34
+ if (list) {
35
+ logger.info('Compiled the following files:');
36
+ console.log(files);
37
+ }
38
+
39
+ logger.info(`Successfully compiled ${files.length} files! 🎉`);
40
+ } catch (error) {
41
+ console.log(error);
42
+ process.exit(1);
43
+ } finally {
44
+ logger.stop();
45
+ }
46
+ }
47
+
48
+ module.exports = {
49
+ command: 'check <glob>',
50
+ desc: 'check that each file can be compiled',
51
+ builder(yargs) {
52
+ yargs.positional('glob', {
53
+ type: 'string',
54
+ describe: 'glob pattern for files to check',
55
+ });
56
+
57
+ yargs.options({
58
+ i: {
59
+ alias: 'ignore',
60
+ describe: 'provide a glob pattern of files to ignore',
61
+ type: 'string',
62
+ },
63
+ l: {
64
+ alias: 'list',
65
+ describe: 'list all the files that were compiled',
66
+ type: 'boolean',
67
+ },
68
+ });
69
+ },
70
+ handler: check,
71
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright IBM Corp. 2019, 2019
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /* eslint-disable no-console */
9
+
10
+ 'use strict';
11
+
12
+ const { reporter } = require('@carbon/cli-reporter');
13
+ const { exec } = require('child-process-promise');
14
+ const { workspace } = require('../workspace');
15
+
16
+ async function check(args, env) {
17
+ reporter.info('Running checks in CI...');
18
+
19
+ const options = {
20
+ cwd: env.root.directory,
21
+ stdio: 'inherit',
22
+ };
23
+ const tasks = [
24
+ `yarn carbon-cli check --ignore '**/@(node_modules|examples|components|react|fixtures|compat)/**' 'packages/**/*.scss'`,
25
+ `cross-env BABEL_ENV=test yarn test --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
26
+ `cross-env BABEL_ENV=test yarn test:e2e --ci --maxWorkers 2 --reporters=default --reporters=jest-junit`,
27
+ `cross-env PERCY_TOKEN=dd3392142006a6483c8f524697f39f052755fa9dc087ff4437cac3d64227abdd yarn run percy exec -- yarn workspace carbon-components-react test:e2e`,
28
+ ];
29
+
30
+ try {
31
+ for (const task of tasks) {
32
+ const now = Date.now();
33
+
34
+ reporter.info(`Running: ${task}`);
35
+ await exec(task, options);
36
+ reporter.success(`Done in: ${Date.now() - now}ms`);
37
+ }
38
+ } catch (error) {
39
+ console.log(error.stdout);
40
+ console.log(error.stderr);
41
+ console.log(error);
42
+ process.exit(1);
43
+ }
44
+ }
45
+
46
+ module.exports = {
47
+ command: 'ci-check',
48
+ desc: 'run CI checks',
49
+ builder: {},
50
+ handler: workspace(check),
51
+ };
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Copyright IBM Corp. 2019, 2019
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const { paramCase } = require('change-case');
11
+ const fs = require('fs-extra');
12
+ const { prompt } = require('enquirer');
13
+ const path = require('path');
14
+ const { loadTemplates } = require('../component');
15
+ const { createLogger } = require('../logger');
16
+
17
+ const logger = createLogger('component');
18
+
19
+ function clearConsole() {
20
+ process.stdout.write(
21
+ process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
22
+ );
23
+ }
24
+
25
+ async function component() {
26
+ const templates = await loadTemplates();
27
+ const questions = [
28
+ {
29
+ type: 'input',
30
+ name: 'name',
31
+ message: 'What is the name of this component?',
32
+ validate(value) {
33
+ if (value === '') {
34
+ return 'A name is required for the component';
35
+ }
36
+ return true;
37
+ },
38
+ },
39
+ {
40
+ type: 'input',
41
+ name: 'directory',
42
+ message: 'Specify the path for this component',
43
+ initial: '.',
44
+ },
45
+ {
46
+ type: 'multiselect',
47
+ name: 'options',
48
+ message: 'What else should we scaffold out for you?',
49
+ initial: ['tests', 'stories'],
50
+ choices: [
51
+ {
52
+ name: 'tests',
53
+ value: true,
54
+ },
55
+ {
56
+ name: 'stories',
57
+ value: true,
58
+ },
59
+ ],
60
+ result(names) {
61
+ return this.map(names);
62
+ },
63
+ },
64
+ ];
65
+
66
+ clearConsole();
67
+ const answers = await prompt(questions);
68
+
69
+ logger.start('Generating component...');
70
+
71
+ const directory = path.resolve(
72
+ process.cwd(),
73
+ answers.directory,
74
+ answers.name
75
+ );
76
+
77
+ logger.info(`Writing component directory to ${directory}`);
78
+
79
+ if (await fs.exists(directory)) {
80
+ throw new Error(`A directory already exists at ${directory}`);
81
+ }
82
+
83
+ logger.info('Scaffolding out default files...');
84
+
85
+ await fs.ensureDir(directory);
86
+ await fs.writeFile(
87
+ path.join(directory, 'index.js'),
88
+ templates.index.compile({ name: answers.name })
89
+ );
90
+ await fs.writeFile(
91
+ path.join(directory, `${answers.name}.js`),
92
+ templates.component.compile({ name: answers.name })
93
+ );
94
+
95
+ if (answers.options.tests) {
96
+ logger.start('Scaffolding out test files...');
97
+ await fs.ensureDir(path.join(directory, '__tests__'));
98
+ await fs.writeFile(
99
+ path.join(directory, '__tests__', `${answers.name}-test.js`),
100
+ templates.test.compile({ name: answers.name })
101
+ );
102
+ logger.stop();
103
+ }
104
+
105
+ if (answers.options.stories) {
106
+ logger.start('Scaffolding out story files...');
107
+ await fs.writeFile(
108
+ path.join(directory, `${answers.name}-story.js`),
109
+ templates.story.compile({
110
+ name: answers.name,
111
+ })
112
+ );
113
+ await fs.writeFile(
114
+ path.join(directory, `${answers.name}.mdx`),
115
+ templates.mdx.compile({
116
+ name: answers.name,
117
+ url: paramCase(answers.name),
118
+ })
119
+ );
120
+ logger.stop();
121
+ }
122
+
123
+ logger.stop();
124
+ }
125
+
126
+ module.exports = {
127
+ command: 'component',
128
+ desc: '[EXPERIMENTAL] Scaffold a component in React',
129
+ handler: component,
130
+ };