Skip to content

Commit

Permalink
use argv.name within pkg & manifest (Closes #326)
Browse files Browse the repository at this point in the history
- declare `log-symbols` as a dependency
  - it is already a direct dependency of `ora`
  • Loading branch information
lukeed committed Aug 20, 2017
1 parent 8ab7688 commit 6b878d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"less": "^2.7.2",
"less-loader": "^4.0.3",
"loader-utils": "^1.1.0",
"log-symbols": "^2.0.0",
"minimatch": "^3.0.3",
"mkdirp": "^0.5.1",
"offline-plugin": "^4.6.2",
Expand Down
24 changes: 20 additions & 4 deletions src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import asyncCommand from '../lib/async-command';
import fs from 'fs.promised';
import copy from 'recursive-copy';
import mkdirp from 'mkdirp';
import glob from 'glob';
import ora from 'ora';
import chalk from 'chalk';
import inquirer from 'inquirer';
import logSymbols from 'log-symbols';
import promisify from 'es6-promisify';
import path from 'path';
import { install, initialize, pkgScripts, initGit, trimLeft } from './../lib/setup';
Expand All @@ -23,7 +25,7 @@ export default asyncCommand({

builder: {
name: {
description: 'directory and package name for the new app'
description: 'The application\'s name'
},
force: {
description: 'Force option to create the directory for the new app',
Expand Down Expand Up @@ -54,13 +56,12 @@ export default asyncCommand({
throw Error(`Unknown app template "${argv.type}".`);
}

let target = path.resolve(process.cwd(), argv.dest || argv.name);
let target = path.resolve(process.cwd(), argv.dest);

let exists = false;
try {
exists = (await fs.stat(target)).isDirectory();
}
catch (err) {}
} catch (err) {}

if (exists && argv.force) {
const question = {
Expand Down Expand Up @@ -110,6 +111,21 @@ export default asyncCommand({

pkgData.scripts = await pkgScripts(isYarn, pkgData);

if (argv.name) {
pkgData.name = argv.name;
// Find a `manifest.json`; use the first match, if any
let files = await promisify(glob)(target + '/**/manifest.json');
let manifest = files[0] && JSON.parse(await fs.readFile(files[0]));
if (manifest) {
manifest.name = manifest.short_name = argv.name;
await fs.writeFile(files[0], JSON.stringify(manifest, null, 2));
if (argv.name.length > 12) {
// @see https://developer.chrome.com/extensions/manifest/name#short_name
process.stdout.write(`\n${logSymbols.warning} Your \`short_name\` should be fewer than 12 characters.\n`);
}
}
}

try {
await fs.stat(path.resolve(target, 'src'));
} catch (_) {
Expand Down

0 comments on commit 6b878d4

Please sign in to comment.