🚧 Bumping alpha pre-release
This commit is contained in:
parent
6b6f6fd7cd
commit
bca5deedb3
62 changed files with 477 additions and 358 deletions
|
@ -1,32 +1,45 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
"use strict";
|
||||
|
||||
const path = require('path')
|
||||
const chalk = require('chalk')
|
||||
const program = require('commander')
|
||||
const { version } = require('../package')
|
||||
const path = require("path");
|
||||
const chalk = require("chalk");
|
||||
const program = require("commander");
|
||||
const { version } = require("../package");
|
||||
|
||||
const getDefaultLibraryParams = require('./get-default-library-params')
|
||||
const createLibrary = require('./create-library')
|
||||
const promptLibraryParams = require('./prompt-library-params')
|
||||
const getDefaultLibraryParams = require("./get-default-library-params");
|
||||
const createLibrary = require("./create-library");
|
||||
const promptLibraryParams = require("./prompt-library-params");
|
||||
|
||||
module.exports = async () => {
|
||||
const defaults = await getDefaultLibraryParams()
|
||||
const defaults = await getDefaultLibraryParams();
|
||||
|
||||
program
|
||||
.name('create-freesewing-pattern')
|
||||
.name("create-freesewing-pattern")
|
||||
.version(version)
|
||||
.usage('[options] [package-name]')
|
||||
.option('-d, --desc <string>', 'package description')
|
||||
.option('-a, --author <string>', 'author\'s github handle', defaults.author)
|
||||
.option('-l, --license <string>', 'package license', defaults.license)
|
||||
.option('-r, --repo <string>', 'package repo path')
|
||||
.option('-g, --no-git', 'generate without git init')
|
||||
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
|
||||
.option('-t, --template <default|custom>', 'package template to use', /^(default|custom)$/, defaults.template)
|
||||
.option('-p, --template-path <string>', 'custom package template path')
|
||||
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
|
||||
.parse(process.argv)
|
||||
.usage("[options] [package-name]")
|
||||
.option("-d, --desc <string>", "package description")
|
||||
.option("-a, --author <string>", "author's github handle", defaults.author)
|
||||
.option("-l, --license <string>", "package license", defaults.license)
|
||||
.option("-r, --repo <string>", "package repo path")
|
||||
.option("-g, --no-git", "generate without git init")
|
||||
.option(
|
||||
"-m, --manager <npm|yarn>",
|
||||
"package manager to use",
|
||||
/^(npm|yarn)$/,
|
||||
defaults.manager
|
||||
)
|
||||
.option(
|
||||
"-t, --template <default|custom>",
|
||||
"package template to use",
|
||||
/^(default|custom)$/,
|
||||
defaults.template
|
||||
)
|
||||
.option("-p, --template-path <string>", "custom package template path")
|
||||
.option(
|
||||
"-s, --skip-prompts",
|
||||
"skip all prompts (must provide package-name via cli)"
|
||||
)
|
||||
.parse(process.argv);
|
||||
|
||||
const opts = {
|
||||
description: program.desc,
|
||||
|
@ -38,24 +51,24 @@ module.exports = async () => {
|
|||
templatePath: program.templatePath,
|
||||
skipPrompts: program.skipPrompts,
|
||||
git: program.git
|
||||
}
|
||||
};
|
||||
|
||||
Object.keys(opts).forEach((key) => {
|
||||
Object.keys(opts).forEach(key => {
|
||||
if (!opts[key] && defaults[key]) {
|
||||
opts[key] = defaults[key]
|
||||
opts[key] = defaults[key];
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (program.args.length === 1) {
|
||||
opts.name = program.args[0]
|
||||
opts.name = program.args[0];
|
||||
} else if (program.args.length > 1) {
|
||||
console.error('invalid arguments')
|
||||
program.help()
|
||||
process.exit(1)
|
||||
console.error("invalid arguments");
|
||||
program.help();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const params = await promptLibraryParams(opts)
|
||||
const dest = await createLibrary(params)
|
||||
const params = await promptLibraryParams(opts);
|
||||
const dest = await createLibrary(params);
|
||||
|
||||
console.log(`
|
||||
|
||||
|
@ -67,14 +80,15 @@ In one terminal, start the rollup bundler in watch mode:
|
|||
$ ${chalk.cyan(`cd ${params.shortName} && ${params.manager} start`)}
|
||||
|
||||
And in another terminal, run the dev server:
|
||||
$ ${chalk.cyan(`cd ${path.join(params.shortName, 'example')} && ${params.manager} start`)}
|
||||
`)
|
||||
$ ${chalk.cyan(
|
||||
`cd ${path.join(params.shortName, "example")} && ${params.manager} start`
|
||||
)}
|
||||
`);
|
||||
|
||||
return dest
|
||||
}
|
||||
return dest;
|
||||
};
|
||||
|
||||
module.exports()
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
module.exports().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
'use strict'
|
||||
"use strict";
|
||||
|
||||
const getGitConfigPath = require('git-config-path')
|
||||
const githubUsername = require('github-username')
|
||||
const parseGitConfig = require('parse-git-config')
|
||||
const which = require('which')
|
||||
const getGitConfigPath = require("git-config-path");
|
||||
const githubUsername = require("github-username");
|
||||
const parseGitConfig = require("parse-git-config");
|
||||
const which = require("which");
|
||||
|
||||
const config = require('./config')
|
||||
const config = require("./config");
|
||||
|
||||
module.exports = async () => {
|
||||
const defaults = {
|
||||
name: '',
|
||||
description: '',
|
||||
author: config.get('author'),
|
||||
repo: (info) => `${info.author}/${info.name}`,
|
||||
license: config.get('license', 'MIT'),
|
||||
manager: config.get('manager', 'npm'),
|
||||
template: config.get('template', 'default')
|
||||
}
|
||||
name: "",
|
||||
description: "",
|
||||
author: config.get("author"),
|
||||
repo: info => `${info.author}/${info.name}`,
|
||||
license: config.get("license", "MIT"),
|
||||
manager: config.get("manager", "npm"),
|
||||
template: config.get("template", "default")
|
||||
};
|
||||
|
||||
try {
|
||||
if (!config.get('author')) {
|
||||
const gitConfigPath = getGitConfigPath('global')
|
||||
if (!config.get("author")) {
|
||||
const gitConfigPath = getGitConfigPath("global");
|
||||
|
||||
if (gitConfigPath) {
|
||||
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
|
||||
const gitConfig = parseGitConfig.sync({ path: gitConfigPath });
|
||||
|
||||
if (gitConfig.github && gitConfig.github.user) {
|
||||
defaults.author = gitConfig.github.user
|
||||
defaults.author = gitConfig.github.user;
|
||||
} else if (gitConfig.user && gitConfig.user.email) {
|
||||
defaults.author = await githubUsername(gitConfig.user.email)
|
||||
defaults.author = await githubUsername(gitConfig.user.email);
|
||||
}
|
||||
}
|
||||
|
||||
if (defaults.author) {
|
||||
config.set('author', defaults.author)
|
||||
config.set("author", defaults.author);
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.get('manager')) {
|
||||
if (which.sync('yarn', { nothrow: true })) {
|
||||
defaults.manager = 'yarn'
|
||||
if (!config.get("manager")) {
|
||||
if (which.sync("yarn", { nothrow: true })) {
|
||||
defaults.manager = "yarn";
|
||||
}
|
||||
|
||||
config.set('manager', defaults.manager)
|
||||
config.set("manager", defaults.manager);
|
||||
}
|
||||
|
||||
if (!config.get('template')) {
|
||||
config.set('template', defaults.template)
|
||||
if (!config.get("template")) {
|
||||
config.set("template", defaults.template);
|
||||
}
|
||||
} catch (err) { }
|
||||
} catch (err) {}
|
||||
|
||||
return defaults
|
||||
}
|
||||
return defaults;
|
||||
};
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
'use strict'
|
||||
"use strict";
|
||||
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const inquirer = require('inquirer')
|
||||
const validateNpmName = require('validate-npm-package-name')
|
||||
const languages = require('@freesewing/i18n').languages;
|
||||
const strings = require('@freesewing/i18n').strings;
|
||||
const config = require('./config')
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const inquirer = require("inquirer");
|
||||
const validateNpmName = require("validate-npm-package-name");
|
||||
const languages = require("@freesewing/i18n").languages;
|
||||
const strings = require("@freesewing/i18n").strings;
|
||||
const config = require("./config");
|
||||
|
||||
let languageChoices = []
|
||||
let languageChoices = [];
|
||||
for (let l of Object.keys(languages)) {
|
||||
languageChoices.push({
|
||||
name: languages[l],
|
||||
|
@ -17,99 +17,113 @@ for (let l of Object.keys(languages)) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = async (opts) => {
|
||||
module.exports = async opts => {
|
||||
if (opts.name && !validateNpmName(opts.name).validForNewPackages) {
|
||||
throw new Error(`invalid package name "${opts.name}"`)
|
||||
throw new Error(`invalid package name "${opts.name}"`);
|
||||
}
|
||||
|
||||
if (opts.skipPrompts) {
|
||||
if (!opts.name) {
|
||||
throw new Error('invalid input; you must pass a package name with --skip-prompts')
|
||||
throw new Error(
|
||||
"invalid input; you must pass a package name with --skip-prompts"
|
||||
);
|
||||
}
|
||||
|
||||
Object.keys(opts).forEach((key) => {
|
||||
const value = opts[key]
|
||||
if (typeof value === 'function') {
|
||||
opts[key] = value(opts)
|
||||
Object.keys(opts).forEach(key => {
|
||||
const value = opts[key];
|
||||
if (typeof value === "function") {
|
||||
opts[key] = value(opts);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return opts
|
||||
return opts;
|
||||
} else {
|
||||
const info = await inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'language',
|
||||
message: 'Language',
|
||||
type: "list",
|
||||
name: "language",
|
||||
message: "Language",
|
||||
choices: languageChoices,
|
||||
default: 'en'
|
||||
default: "en"
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: info => strings[info.language]['cfp.patternName'],
|
||||
type: "input",
|
||||
name: "name",
|
||||
message: info => strings[info.language]["cfp.patternName"],
|
||||
validate: name => {
|
||||
return name && validateNpmName(name).validForNewPackages
|
||||
return name && validateNpmName(name).validForNewPackages;
|
||||
},
|
||||
default: opts.name
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'description',
|
||||
message: info => strings[info.language]['cfp.patternDescription'],
|
||||
type: "input",
|
||||
name: "description",
|
||||
message: info => strings[info.language]["cfp.patternDescription"],
|
||||
default: opts.description
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'type',
|
||||
message: info => strings[info.language]['cfp.patternType'],
|
||||
type: "list",
|
||||
name: "type",
|
||||
message: info => strings[info.language]["cfp.patternType"],
|
||||
choices: info => [
|
||||
{ name: strings[info.language]['filter.type.pattern'], value: 'pattern'},
|
||||
{ name: strings[info.language]['filter.type.block'], value: 'block'},
|
||||
{
|
||||
name: strings[info.language]["filter.type.pattern"],
|
||||
value: "pattern"
|
||||
},
|
||||
{ name: strings[info.language]["filter.type.block"], value: "block" }
|
||||
],
|
||||
default: 'pattern',
|
||||
default: "pattern"
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'department',
|
||||
message: info => strings[info.language]['filter.department.title'],
|
||||
type: "list",
|
||||
name: "department",
|
||||
message: info => strings[info.language]["filter.department.title"],
|
||||
choices: info => [
|
||||
{ name: strings[info.language]['filter.department.menswear'], value: 'menswear'},
|
||||
{ name: strings[info.language]['filter.department.womenswear'], value: 'womenswear'},
|
||||
{ name: strings[info.language]['filter.department.accessories'], value: 'accessories'},
|
||||
{
|
||||
name: strings[info.language]["filter.department.menswear"],
|
||||
value: "menswear"
|
||||
},
|
||||
{
|
||||
name: strings[info.language]["filter.department.womenswear"],
|
||||
value: "womenswear"
|
||||
},
|
||||
{
|
||||
name: strings[info.language]["filter.department.accessories"],
|
||||
value: "accessories"
|
||||
}
|
||||
],
|
||||
default: 'womenswear',
|
||||
default: "womenswear"
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'author',
|
||||
message: info => strings[info.language]['cfp.author'],
|
||||
type: "input",
|
||||
name: "author",
|
||||
message: info => strings[info.language]["cfp.author"],
|
||||
default: opts.author
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'repo',
|
||||
message: info => strings[info.language]['cfp.githubRepo'],
|
||||
type: "input",
|
||||
name: "repo",
|
||||
message: info => strings[info.language]["cfp.githubRepo"],
|
||||
default: opts.repo
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'manager',
|
||||
message: info => strings[info.language]['cfp.packageManager'],
|
||||
choices: [ 'npm', 'yarn' ],
|
||||
type: "list",
|
||||
name: "manager",
|
||||
message: info => strings[info.language]["cfp.packageManager"],
|
||||
choices: ["npm", "yarn"],
|
||||
default: opts.manager
|
||||
},
|
||||
])
|
||||
}
|
||||
]);
|
||||
|
||||
config.set('author', info.author)
|
||||
config.set('manager', info.manager)
|
||||
config.set('template', 'default')
|
||||
config.set('license', 'MIT')
|
||||
info.template = 'default';
|
||||
config.set("author", info.author);
|
||||
config.set("manager", info.manager);
|
||||
config.set("template", "default");
|
||||
config.set("license", "MIT");
|
||||
info.template = "default";
|
||||
|
||||
return {
|
||||
...info,
|
||||
git: opts.git
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue