forked from carbon-design-system/carbon
-
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.
feat(cli): add @carbon/cli package (carbon-design-system#2982)
* 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
Showing
36 changed files
with
524 additions
and
65 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/__mocks__/** | ||
**/__tests__/** | ||
**/examples/** | ||
**/tasks/** |
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,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); | ||
}); |
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,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" | ||
} | ||
} |
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,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; |
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 |
---|---|---|
@@ -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, | ||
}; |
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,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, | ||
}; |
Oops, something went wrong.