Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Add prompt when dirName isn't provided (#84)
Browse files Browse the repository at this point in the history
* simplify to requiring in theme commands

* dynamically pull in theme commands and move global commands out

* remove minimist

* move theme creation to command and other functions to utils

* group variables

* add comments to functions

* move out output slate theme check

* remove extra variable

* touch up output

* redo shrinkwrap

* improve error output

* add clean up after theme download

* add prompt when dirName isn't provided

* reword prompt message

* move babel-polyfill from devDep to dep

* update dirName regex

* remove &
  • Loading branch information
Ryan Macdonald authored and Thomas Kelly committed Jul 31, 2017
1 parent 4ade202 commit b178409
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/slate-cli/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
["shopify"]
],
"plugins": [
["transform-async-to-generator"],
["add-shopify-header", {
"files": ["src/index.js"]
}]
Expand Down
117 changes: 117 additions & 0 deletions packages/slate-cli/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/slate-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"license": "MIT",
"author": "Shopify Inc.",
"dependencies": {
"babel-polyfill": "6.16.0",
"chalk": "1.1.3",
"commander": "2.9.0",
"cross-spawn": "5.0.0",
"debug": "2.2.0",
"find-root": "1.0.0",
"inquirer": "1.2.2",
"rimraf": "2.5.4",
"unzip2": "0.2.5",
"update-notifier": "1.0.2"
Expand All @@ -26,6 +28,7 @@
"babel-cli": "^6.11.4",
"babel-core": "^6.13.2",
"babel-plugin-add-shopify-header": "^1.0.0",
"babel-plugin-transform-async-to-generator": "6.16.0",
"babel-preset-shopify": "^13.0.0",
"babel-register": "^6.11.6",
"eslint": "3.3.1",
Expand Down
32 changes: 28 additions & 4 deletions packages/slate-cli/src/commands/theme.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'babel-polyfill';
import {existsSync, mkdirSync} from 'fs'; // eslint-disable-line node/no-deprecated-api
import {join} from 'path';
import {prompt} from 'inquirer';
import rimraf from 'rimraf';
import {green, red} from 'chalk';
import {downloadFromUrl, unzip, startProcess, writePackageJsonSync} from '../utils';
Expand All @@ -9,10 +11,32 @@ export default function(program) {
.command('theme [name]')
.alias('th')
.description('Generate new theme')
.action((name = 'theme') => {
.action(async function(name) {
let dirName = name;

if (!dirName) {
const answers = await prompt({
type: 'input',
name: 'dirName',
message: 'What do you want to name the directory for your theme?',
default: 'theme',
validate: (value) => {
const validateName = value.match(/^[\w^'@{}[\],$=!#().%+~\- ]+$/);

if (validateName) {
return true;
}

return 'Please enter a directory name';
},
});

dirName = answers.dirName;
}

const workingDirectory = process.cwd();
const s3Url = 'https://sdks.shopifycdn.com/slate/latest/slate-src.zip';
const root = join(workingDirectory, name);
const root = join(workingDirectory, dirName);

if (existsSync(root)) {
console.log('');
Expand All @@ -36,15 +60,15 @@ export default function(program) {

const pkg = join(root, 'package.json');

writePackageJsonSync(pkg, name);
writePackageJsonSync(pkg, dirName);

return startProcess('npm', ['install', '@shopify/slate-tools', '-D'], {
cwd: root,
});
})
.then(() => {
console.log(` ${green('✓')} devDependencies installed`);
console.log(` ${green('✓')} ${name} theme is ready`);
console.log(` ${green('✓')} ${dirName} theme is ready`);
console.log('');

return;
Expand Down

0 comments on commit b178409

Please sign in to comment.