Skip to content

Commit

Permalink
feat(start): Prompt for monorepo project on sku start (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Apr 11, 2017
1 parent b6cacae commit 696ade1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ module.exports = [
]
```

You can then start the relevant project by name at development time:
You will then be prompted to select the project you'd like to work on when starting your development server:

```bash
$ npm start
```

Alternatively, you can start the relevant project directly:

```bash
$ npm start hello
Expand Down
24 changes: 19 additions & 5 deletions config/builds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const cwd = process.cwd();
const path = require('path');
const fs = require('fs');
const inquirer = require('inquirer');
const deasyncPromise = require('deasync-promise');
const skuConfigPath = path.join(cwd, 'sku.config.js');
const args = require('./args');

Expand All @@ -9,14 +11,26 @@ const buildConfigs = fs.existsSync(skuConfigPath)
? makeArray(require(skuConfigPath))
: [{}];

if (args.script === 'start' && buildConfigs.length > 1 && !args.buildName) {
console.log('ERROR: Build name must be provded, e.g. sku start hello');
process.exit(1);
let buildName = args.buildName;

if (!buildName && args.script === 'start' && buildConfigs.length > 1) {
const answers = deasyncPromise(
inquirer.prompt([
{
type: 'list',
name: 'buildName',
message: 'You appear to be running a monorepo. Which project would you like to work on?',
choices: buildConfigs.map(x => x.name).filter(Boolean)
}
])
);

buildName = answers.buildName;
}

const builds = buildConfigs
.filter(buildConfig => {
return args.script === 'start' ? buildConfig.name === args.buildName : true;
return args.script === 'start' ? buildConfig.name === buildName : true;
})
.map(buildConfig => {
const name = buildConfig.name || '';
Expand All @@ -39,7 +53,7 @@ const builds = buildConfigs
});

if (args.script === 'start' && builds.length === 0) {
console.log(`ERROR: Build with the name "${args.buildName}" wasn't found`);
console.log(`ERROR: Build with the name "${buildName}" wasn't found`);
process.exit(1);
}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
"classnames": "^2.2.5",
"cross-spawn": "^5.0.1",
"css-loader": "^0.26.1",
"deasync-promise": "^1.0.1",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"fs-extra": "^2.0.0",
"identity-obj-proxy": "^3.0.0",
"inquirer": "^3.0.6",
"jest": "^18.1.0",
"less": "^2.7.2",
"less-loader": "^4.0.2",
Expand Down

0 comments on commit 696ade1

Please sign in to comment.