Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD a CLI for bootstrapping #1216

Merged
merged 28 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
369ac55
ADD a CLI for bootstrapping
ndelangen Jun 8, 2017
5726f13
Merge branch 'master' into improve-bootstrap-command
ndelangen Jun 9, 2017
27edf5e
Merge branch 'master' into improve-bootstrap-command
ndelangen Jul 23, 2017
4f4b9e4
set as default bootstrap command && add core as default
ndelangen Jul 23, 2017
9fafeab
CHANGE hoist-internals script to be less verbose
ndelangen Jul 23, 2017
86c25d6
Merge branch 'master' into improve-bootstrap-command
ndelangen Jul 23, 2017
6aad7a1
use `-- --flag` in docs & circleci
ndelangen Jul 24, 2017
8146294
Merge branch 'master' into improve-bootstrap-command
ndelangen Jul 24, 2017
31f83aa
Merge branch 'master' into improve-bootstrap-command
ndelangen Jul 26, 2017
1327e2d
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 19, 2017
02e0950
ADD build-packs
ndelangen Aug 19, 2017
540ec9a
DISABLE concurrency on lint-staged (I got problems with git lock files)
ndelangen Aug 19, 2017
c85776a
WIP
ndelangen Aug 20, 2017
de7777e
SWITCH to normal node for bootstrap script && CHANGE circleCI to use …
ndelangen Aug 20, 2017
ed0e61e
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 20, 2017
b215110
FIX circleCI.yml
ndelangen Aug 21, 2017
7940e62
REVERT incorrect changes on docs/pages
ndelangen Aug 21, 2017
879928d
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 23, 2017
1843196
ADD crna-kitchen-sink bootstrap command
ndelangen Aug 23, 2017
43b8753
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 23, 2017
9f30bbf
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 23, 2017
f84623d
ADD .vscode and .idea to gitignore, but whitelist them from being rem…
ndelangen Aug 23, 2017
6dd4ae7
Merge branch 'improve-bootstrap-command' of github.com:storybooks/sto…
ndelangen Aug 23, 2017
0723401
ADD -- --core to CONTRIBUTING.md
ndelangen Aug 23, 2017
7fd661c
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 23, 2017
30e7c37
ADD a confirmation step when doing the reset task, it will NOT ask wh…
ndelangen Aug 23, 2017
faec65e
Merge branch 'master' into improve-bootstrap-command
ndelangen Aug 23, 2017
55a2b9a
IMPROVE confirm message
ndelangen Aug 23, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"url": "https://github.com/storybooks/storybook.git"
},
"scripts": {
"bootstrap": "lerna bootstrap",
"bootstrap": "./scripts/bootstrap.js",
"bootstrap:libs": "lerna bootstrap",
"bootstrap:docs": "cd docs && npm i",
"bootstrap:test-cra": "lerna exec --scope test-cra -- npm i",
"bootstrap:react-native-vanilla": "lerna exec --scope react-native-vanilla -- npm i",
Expand Down Expand Up @@ -36,6 +37,7 @@
"babel-preset-stage-0": "^6.24.1",
"chalk": "^1.1.3",
"codecov": "^2.2.0",
"commander": "^2.9.0",
"enzyme": "^2.8.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
Expand All @@ -49,14 +51,15 @@
"gh-pages": "^1.0.0",
"github-release-from-changelog": "^1.2.1",
"husky": "^0.13.4",
"inquirer": "^3.1.0",
"jest": "^20.0.4",
"jest-enzyme": "^3.2.0",
"lerna": "2.0.0-rc.5",
"lint-staged": "^3.5.1",
"markdown-it-anchor": "^4.0.0",
"markdownlint-cli": "^0.3.1",
"nodemon": "^1.11.0",
"prettier": "^1.3.1",
"prettier": "^1.4.4",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
Expand Down
83 changes: 83 additions & 0 deletions scripts/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env babel-node

import inquirer from 'inquirer';
import program from 'commander';
import childProcess from 'child_process';

const spawn = childProcess.spawnSync;

program
.version('1.0.0')
.option('--all', 'Run all without asking')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should --all be the default and instead a --interactive or --pick flag would launch the interactive picker?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming developers want to type LESS ?

I think interactive mode is a sane default for a developer tool ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree ... just raised the consideration of keeping the normal bootstrap behaviour default with the interactive bootstrapping be a power mode. But this is more discoverable!

.option('--docs', 'Bootstrap docs')
.option('--libs', 'Bootstrap libs')
.option('--test-cra', 'Bootstrap test-cra')
.option('--react-native-vanilla', 'Bootstrap react-native-vanilla')
.parse(process.argv);

const todo = {
docs: false,
libs: false,
'test-cra': false,
'react-native-vanilla': false,
};

if (program.all) {
Object.assign(todo, {
docs: true,
libs: true,
'test-cra': true,
'react-native-vanilla': true,
});
}

if (program.docs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like this to replace all of these if statements:

Object.keys(todo).forEach(key => {
  todo[key] = program[key] || program.all
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do this, thanks!

Object.assign(todo, {
docs: true,
});
}
if (program.libs) {
Object.assign(todo, {
libs: true,
});
}
if (program['test-cra']) {
Object.assign(todo, {
'test-cra': true,
});
}
if (program['react-native-vanilla']) {
Object.assign(todo, {
'react-native-vanilla': true,
});
}

let selection;
if (!Object.keys(todo).map(key => todo[key]).filter(Boolean).length) {
selection = inquirer
.prompt([
{
type: 'checkbox',
message: 'Select which packages to bootstrap',
name: 'todo',
choices: Object.keys(todo).map(key => ({ name: key })),
},
])
.then(answers => answers.todo);
} else {
selection = Promise.resolve(Object.keys(todo).filter(key => todo[key] === true));
}

selection.then(list => {
if (list.length === 0) {
console.log('Nothing to bootstrap');
} else {
console.log(`Bootstrapping: ${list.join(', ')}`);
list.forEach(key => {
spawn('npm', [`run bootstrap:${key}`], {
shell: true,
stdio: 'inherit',
});
});
}
});