🐛 Fixed catch block in reconfigure script
This commit is contained in:
parent
b720b6490d
commit
3eb913dcb5
1 changed files with 231 additions and 187 deletions
|
@ -1,48 +1,58 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
const path = require('path')
|
const path = require("path");
|
||||||
const fs = require('fs')
|
const fs = require("fs");
|
||||||
const fse = require('fs-extra')
|
const fse = require("fs-extra");
|
||||||
const glob = require('glob')
|
const glob = require("glob");
|
||||||
const yaml = require('js-yaml')
|
const yaml = require("js-yaml");
|
||||||
const chalk = require('chalk')
|
const chalk = require("chalk");
|
||||||
const handlebars = require('handlebars')
|
const handlebars = require("handlebars");
|
||||||
const Mustache = require('mustache')
|
const Mustache = require("mustache");
|
||||||
const { version } = require('../lerna.json')
|
const { version } = require("../lerna.json");
|
||||||
|
|
||||||
const repoPath = process.cwd()
|
const repoPath = process.cwd();
|
||||||
const config = {
|
const config = {
|
||||||
repoPath,
|
repoPath,
|
||||||
defaults: readConfigFile('defaults.yaml'),
|
defaults: readConfigFile("defaults.yaml"),
|
||||||
descriptions: readConfigFile('descriptions.yaml'),
|
descriptions: readConfigFile("descriptions.yaml"),
|
||||||
keywords: readConfigFile('keywords.yaml'),
|
keywords: readConfigFile("keywords.yaml"),
|
||||||
badges: readConfigFile('badges.yaml'),
|
badges: readConfigFile("badges.yaml"),
|
||||||
scripts: readConfigFile('scripts.yaml'),
|
scripts: readConfigFile("scripts.yaml"),
|
||||||
changelog: readConfigFile('changelog.yaml'),
|
changelog: readConfigFile("changelog.yaml"),
|
||||||
changetypes: ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'],
|
changetypes: [
|
||||||
dependencies: readConfigFile('dependencies.yaml', { version }),
|
"Added",
|
||||||
exceptions: readConfigFile('exceptions.yaml'),
|
"Changed",
|
||||||
|
"Deprecated",
|
||||||
|
"Removed",
|
||||||
|
"Fixed",
|
||||||
|
"Security"
|
||||||
|
],
|
||||||
|
dependencies: readConfigFile("dependencies.yaml", { version }),
|
||||||
|
exceptions: readConfigFile("exceptions.yaml"),
|
||||||
templates: {
|
templates: {
|
||||||
pkg: readTemplateFile('package.dflt.json'),
|
pkg: readTemplateFile("package.dflt.json"),
|
||||||
rollup: readTemplateFile('rollup.config.dflt.js'),
|
rollup: readTemplateFile("rollup.config.dflt.js"),
|
||||||
changelog: readTemplateFile('changelog.dflt.md'),
|
changelog: readTemplateFile("changelog.dflt.md"),
|
||||||
readme: readTemplateFile('readme.dflt.md')
|
readme: readTemplateFile("readme.dflt.md")
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const packages = glob.sync('*', {
|
const packages = glob.sync("*", {
|
||||||
cwd: path.join(config.repoPath, 'packages')
|
cwd: path.join(config.repoPath, "packages")
|
||||||
})
|
});
|
||||||
|
|
||||||
validate(packages, config)
|
validate(packages, config);
|
||||||
reconfigure(packages, config)
|
reconfigure(packages, config);
|
||||||
|
|
||||||
process.exit()
|
process.exit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a template file
|
* Reads a template file
|
||||||
*/
|
*/
|
||||||
function readTemplateFile(file) {
|
function readTemplateFile(file) {
|
||||||
return fs.readFileSync(path.join(repoPath, 'config', 'templates', file), 'utf-8')
|
return fs.readFileSync(
|
||||||
|
path.join(repoPath, "config", "templates", file),
|
||||||
|
"utf-8"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,25 +63,25 @@ function readExampleFile(file, subdir = false) {
|
||||||
subdir
|
subdir
|
||||||
? path.join(
|
? path.join(
|
||||||
repoPath,
|
repoPath,
|
||||||
'packages',
|
"packages",
|
||||||
'create-freesewing-pattern',
|
"create-freesewing-pattern",
|
||||||
'template',
|
"template",
|
||||||
'default',
|
"default",
|
||||||
'example',
|
"example",
|
||||||
file
|
file
|
||||||
)
|
)
|
||||||
: path.join(
|
: path.join(
|
||||||
repoPath,
|
repoPath,
|
||||||
'packages',
|
"packages",
|
||||||
'create-freesewing-pattern',
|
"create-freesewing-pattern",
|
||||||
'template',
|
"template",
|
||||||
'default',
|
"default",
|
||||||
'example',
|
"example",
|
||||||
subdir,
|
subdir,
|
||||||
file
|
file
|
||||||
),
|
),
|
||||||
'utf-8'
|
"utf-8"
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,9 +90,14 @@ function readExampleFile(file, subdir = false) {
|
||||||
function readConfigFile(file, replace = false) {
|
function readConfigFile(file, replace = false) {
|
||||||
if (replace)
|
if (replace)
|
||||||
return yaml.safeLoad(
|
return yaml.safeLoad(
|
||||||
Mustache.render(fs.readFileSync(path.join(repoPath, 'config', file), 'utf-8'), replace)
|
Mustache.render(
|
||||||
)
|
fs.readFileSync(path.join(repoPath, "config", file), "utf-8"),
|
||||||
return yaml.safeLoad(fs.readFileSync(path.join(repoPath, 'config', file), 'utf-8'))
|
replace
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return yaml.safeLoad(
|
||||||
|
fs.readFileSync(path.join(repoPath, "config", file), "utf-8")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,14 +105,17 @@ function readConfigFile(file, replace = false) {
|
||||||
* Returns its contents if it exists, or an empty string if not
|
* Returns its contents if it exists, or an empty string if not
|
||||||
*/
|
*/
|
||||||
function readInfoFile(pkg) {
|
function readInfoFile(pkg) {
|
||||||
let markup = ''
|
let markup = "";
|
||||||
try {
|
try {
|
||||||
markup = fs.readFileSync(path.join(repoPath, 'packages', pkg, 'info.md'), 'utf-8')
|
markup = fs.readFileSync(
|
||||||
} catch {
|
path.join(repoPath, "packages", pkg, "info.md"),
|
||||||
return ''
|
"utf-8"
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return markup
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,23 +126,25 @@ function readInfoFile(pkg) {
|
||||||
* - other
|
* - other
|
||||||
*/
|
*/
|
||||||
function packageType(pkg, config) {
|
function packageType(pkg, config) {
|
||||||
if (pkg.substring(0, 7) === 'plugin-') return 'plugin'
|
if (pkg.substring(0, 7) === "plugin-") return "plugin";
|
||||||
if (config.descriptions[pkg].substring(0, 21) === 'A FreeSewing pattern ') return 'pattern'
|
if (config.descriptions[pkg].substring(0, 21) === "A FreeSewing pattern ")
|
||||||
return 'other'
|
return "pattern";
|
||||||
|
return "other";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of keywords for a package
|
* Returns an array of keywords for a package
|
||||||
*/
|
*/
|
||||||
function keywords(pkg, config, type) {
|
function keywords(pkg, config, type) {
|
||||||
if (typeof config.keywords[pkg] !== 'undefined') return config.keywords[pkg]
|
if (typeof config.keywords[pkg] !== "undefined") return config.keywords[pkg];
|
||||||
if (typeof config.keywords[type] !== 'undefined') return config.keywords[type]
|
if (typeof config.keywords[type] !== "undefined")
|
||||||
|
return config.keywords[type];
|
||||||
else {
|
else {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.redBright.bold('Problem:'),
|
chalk.redBright.bold("Problem:"),
|
||||||
chalk.redBright(`No keywords for package ${pkg} which is of type ${type}`)
|
chalk.redBright(`No keywords for package ${pkg} which is of type ${type}`)
|
||||||
)
|
);
|
||||||
process.exit()
|
process.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,30 +152,30 @@ function keywords(pkg, config, type) {
|
||||||
* Returns an plain object of scripts for a package
|
* Returns an plain object of scripts for a package
|
||||||
*/
|
*/
|
||||||
function scripts(pkg, config, type) {
|
function scripts(pkg, config, type) {
|
||||||
let runScripts = {}
|
let runScripts = {};
|
||||||
for (let key of Object.keys(config.scripts._)) {
|
for (let key of Object.keys(config.scripts._)) {
|
||||||
runScripts[key] = Mustache.render(config.scripts._[key], {
|
runScripts[key] = Mustache.render(config.scripts._[key], {
|
||||||
name: pkg
|
name: pkg
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (typeof config.scripts._types[type] !== 'undefined') {
|
if (typeof config.scripts._types[type] !== "undefined") {
|
||||||
for (let key of Object.keys(config.scripts._types[type])) {
|
for (let key of Object.keys(config.scripts._types[type])) {
|
||||||
runScripts[key] = Mustache.render(config.scripts._types[type][key], {
|
runScripts[key] = Mustache.render(config.scripts._types[type][key], {
|
||||||
name: pkg
|
name: pkg
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof config.scripts[pkg] !== 'undefined') {
|
if (typeof config.scripts[pkg] !== "undefined") {
|
||||||
for (let key of Object.keys(config.scripts[pkg])) {
|
for (let key of Object.keys(config.scripts[pkg])) {
|
||||||
if (config.scripts[pkg][key] === '!') delete runScripts[key]
|
if (config.scripts[pkg][key] === "!") delete runScripts[key];
|
||||||
else
|
else
|
||||||
runScripts[key] = Mustache.render(config.scripts[pkg][key], {
|
runScripts[key] = Mustache.render(config.scripts[pkg][key], {
|
||||||
name: pkg
|
name: pkg
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return runScripts
|
return runScripts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,78 +188,82 @@ function scripts(pkg, config, type) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function deps(section, pkg, config, type) {
|
function deps(section, pkg, config, type) {
|
||||||
let dependencies = {}
|
let dependencies = {};
|
||||||
if (
|
if (
|
||||||
typeof config.dependencies._types[type] !== 'undefined' &&
|
typeof config.dependencies._types[type] !== "undefined" &&
|
||||||
typeof config.dependencies._types[type][section] !== 'undefined'
|
typeof config.dependencies._types[type][section] !== "undefined"
|
||||||
)
|
)
|
||||||
dependencies = config.dependencies._types[type][section]
|
dependencies = config.dependencies._types[type][section];
|
||||||
if (typeof config.dependencies[pkg] === 'undefined') return dependencies
|
if (typeof config.dependencies[pkg] === "undefined") return dependencies;
|
||||||
if (typeof config.dependencies[pkg][section] !== 'undefined')
|
if (typeof config.dependencies[pkg][section] !== "undefined")
|
||||||
return { ...dependencies, ...config.dependencies[pkg][section] }
|
return { ...dependencies, ...config.dependencies[pkg][section] };
|
||||||
|
|
||||||
return dependencies
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These merely call deps() for the relevant dependency section
|
* These merely call deps() for the relevant dependency section
|
||||||
*/
|
*/
|
||||||
function dependencies(pkg, config, type) {
|
function dependencies(pkg, config, type) {
|
||||||
return deps('_', pkg, config, type)
|
return deps("_", pkg, config, type);
|
||||||
}
|
}
|
||||||
function devDependencies(pkg, config, type) {
|
function devDependencies(pkg, config, type) {
|
||||||
return deps('dev', pkg, config, type)
|
return deps("dev", pkg, config, type);
|
||||||
}
|
}
|
||||||
function peerDependencies(pkg, config, type) {
|
function peerDependencies(pkg, config, type) {
|
||||||
return deps('peer', pkg, config, type)
|
return deps("peer", pkg, config, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a package.json file for a package
|
* Creates a package.json file for a package
|
||||||
*/
|
*/
|
||||||
function packageConfig(pkg, config) {
|
function packageConfig(pkg, config) {
|
||||||
let type = packageType(pkg, config)
|
let type = packageType(pkg, config);
|
||||||
let pkgConf = {}
|
let pkgConf = {};
|
||||||
// Let's keep these at the top
|
// Let's keep these at the top
|
||||||
pkgConf.name = fullName(pkg, config)
|
pkgConf.name = fullName(pkg, config);
|
||||||
pkgConf.version = version
|
pkgConf.version = version;
|
||||||
pkgConf.description = config.descriptions[pkg]
|
pkgConf.description = config.descriptions[pkg];
|
||||||
pkgConf = {
|
pkgConf = {
|
||||||
...pkgConf,
|
...pkgConf,
|
||||||
...JSON.parse(Mustache.render(config.templates.pkg, { name: pkg }))
|
...JSON.parse(Mustache.render(config.templates.pkg, { name: pkg }))
|
||||||
}
|
};
|
||||||
pkgConf.keywords = pkgConf.keywords.concat(keywords(pkg, config, type))
|
pkgConf.keywords = pkgConf.keywords.concat(keywords(pkg, config, type));
|
||||||
pkgConf.scripts = scripts(pkg, config, type)
|
pkgConf.scripts = scripts(pkg, config, type);
|
||||||
pkgConf.dependencies = dependencies(pkg, config, type)
|
pkgConf.dependencies = dependencies(pkg, config, type);
|
||||||
pkgConf.devDependencies = devDependencies(pkg, config, type)
|
pkgConf.devDependencies = devDependencies(pkg, config, type);
|
||||||
pkgConf.peerDependencies = peerDependencies(pkg, config, type)
|
pkgConf.peerDependencies = peerDependencies(pkg, config, type);
|
||||||
if (typeof config.exceptions.packageJson[pkg] !== 'undefined') {
|
if (typeof config.exceptions.packageJson[pkg] !== "undefined") {
|
||||||
pkgConf = {
|
pkgConf = {
|
||||||
...pkgConf,
|
...pkgConf,
|
||||||
...config.exceptions.packageJson[pkg]
|
...config.exceptions.packageJson[pkg]
|
||||||
}
|
};
|
||||||
for (let key of Object.keys(config.exceptions.packageJson[pkg])) {
|
for (let key of Object.keys(config.exceptions.packageJson[pkg])) {
|
||||||
if (config.exceptions.packageJson[pkg][key] === '!') delete pkgConf[key]
|
if (config.exceptions.packageJson[pkg][key] === "!") delete pkgConf[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pkgConf
|
return pkgConf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an string with the markup for badges in the readme file
|
* Returns an string with the markup for badges in the readme file
|
||||||
*/
|
*/
|
||||||
function badges(pkg, config) {
|
function badges(pkg, config) {
|
||||||
let markup = ''
|
let markup = "";
|
||||||
for (let group of ['_all', '_social']) {
|
for (let group of ["_all", "_social"]) {
|
||||||
markup += "<p align='center'>"
|
markup += "<p align='center'>";
|
||||||
for (let key of Object.keys(config.badges[group])) {
|
for (let key of Object.keys(config.badges[group])) {
|
||||||
markup += formatBadge(config.badges[group][key], pkg, fullName(pkg, config))
|
markup += formatBadge(
|
||||||
|
config.badges[group][key],
|
||||||
|
pkg,
|
||||||
|
fullName(pkg, config)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
markup += '</p>'
|
markup += "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return markup
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,14 +275,14 @@ function formatBadge(badge, name, fullname) {
|
||||||
title="${Mustache.render(badge.alt, { name, fullname })}"
|
title="${Mustache.render(badge.alt, { name, fullname })}"
|
||||||
><img src="${Mustache.render(badge.img, { name, fullname })}"
|
><img src="${Mustache.render(badge.img, { name, fullname })}"
|
||||||
alt="${Mustache.render(badge.alt, { name, fullname })}"/>
|
alt="${Mustache.render(badge.alt, { name, fullname })}"/>
|
||||||
</a>`
|
</a>`;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the full (namespaced) name of a package
|
* Returns the full (namespaced) name of a package
|
||||||
*/
|
*/
|
||||||
function fullName(pkg, config) {
|
function fullName(pkg, config) {
|
||||||
if (config.exceptions.noNamespace.indexOf(pkg) !== -1) return pkg
|
if (config.exceptions.noNamespace.indexOf(pkg) !== -1) return pkg;
|
||||||
else return `@freesewing/${pkg}`
|
else return `@freesewing/${pkg}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -270,9 +294,9 @@ function readme(pkg, config) {
|
||||||
description: config.descriptions[pkg],
|
description: config.descriptions[pkg],
|
||||||
badges: badges(pkg, config),
|
badges: badges(pkg, config),
|
||||||
info: readInfoFile(pkg)
|
info: readInfoFile(pkg)
|
||||||
})
|
});
|
||||||
|
|
||||||
return markup
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -280,102 +304,106 @@ function readme(pkg, config) {
|
||||||
*/
|
*/
|
||||||
function changelog(pkg, config) {
|
function changelog(pkg, config) {
|
||||||
let markup = Mustache.render(config.templates.changelog, {
|
let markup = Mustache.render(config.templates.changelog, {
|
||||||
fullname: pkg === 'global' ? 'FreeSewing (global)' : fullName(pkg, config),
|
fullname: pkg === "global" ? "FreeSewing (global)" : fullName(pkg, config),
|
||||||
changelog: pkg === 'global' ? globalChangelog(config) : packageChangelog(pkg, config)
|
changelog:
|
||||||
})
|
pkg === "global" ? globalChangelog(config) : packageChangelog(pkg, config)
|
||||||
|
});
|
||||||
|
|
||||||
return markup
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the global changelog data
|
* Generates the global changelog data
|
||||||
*/
|
*/
|
||||||
function globalChangelog(config) {
|
function globalChangelog(config) {
|
||||||
let markup = ''
|
let markup = "";
|
||||||
for (let v in config.changelog) {
|
for (let v in config.changelog) {
|
||||||
let changes = config.changelog[v]
|
let changes = config.changelog[v];
|
||||||
markup += '\n## ' + v
|
markup += "\n## " + v;
|
||||||
if (v !== 'Unreleased') markup += ' (' + formatDate(changes.date) + ')'
|
if (v !== "Unreleased") markup += " (" + formatDate(changes.date) + ")";
|
||||||
markup += '\n\n'
|
markup += "\n\n";
|
||||||
for (let pkg of packages) {
|
for (let pkg of packages) {
|
||||||
let changed = false
|
let changed = false;
|
||||||
for (let type of config.changetypes) {
|
for (let type of config.changetypes) {
|
||||||
if (
|
if (
|
||||||
typeof changes[type] !== 'undefined' &&
|
typeof changes[type] !== "undefined" &&
|
||||||
changes[type] !== null &&
|
changes[type] !== null &&
|
||||||
typeof changes[type][pkg] !== 'undefined' &&
|
typeof changes[type][pkg] !== "undefined" &&
|
||||||
changes[type][pkg] !== null
|
changes[type][pkg] !== null
|
||||||
) {
|
) {
|
||||||
if (!changed) changed = ''
|
if (!changed) changed = "";
|
||||||
changed += '\n#### ' + type + '\n\n'
|
changed += "\n#### " + type + "\n\n";
|
||||||
for (let change of changes[type][pkg]) changed += ' - ' + change + '\n'
|
for (let change of changes[type][pkg])
|
||||||
|
changed += " - " + change + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed) markup += '### ' + pkg + '\n' + changed + '\n'
|
if (changed) markup += "### " + pkg + "\n" + changed + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return markup
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the changelog data for a package
|
* Generates the changelog data for a package
|
||||||
*/
|
*/
|
||||||
function packageChangelog(pkg, config) {
|
function packageChangelog(pkg, config) {
|
||||||
let markup = ''
|
let markup = "";
|
||||||
for (let v in config.changelog) {
|
for (let v in config.changelog) {
|
||||||
let changes = config.changelog[v]
|
let changes = config.changelog[v];
|
||||||
let changed = false
|
let changed = false;
|
||||||
for (let type of config.changetypes) {
|
for (let type of config.changetypes) {
|
||||||
if (
|
if (
|
||||||
typeof changes[type] !== 'undefined' &&
|
typeof changes[type] !== "undefined" &&
|
||||||
changes[type] !== null &&
|
changes[type] !== null &&
|
||||||
typeof changes[type][pkg] !== 'undefined' &&
|
typeof changes[type][pkg] !== "undefined" &&
|
||||||
changes[type][pkg] !== null
|
changes[type][pkg] !== null
|
||||||
) {
|
) {
|
||||||
if (!changed) changed = ''
|
if (!changed) changed = "";
|
||||||
changed += '\n### ' + type + '\n\n'
|
changed += "\n### " + type + "\n\n";
|
||||||
for (let change of changes[type][pkg]) changed += ' - ' + change + '\n'
|
for (let change of changes[type][pkg]) changed += " - " + change + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
markup += '## ' + v
|
markup += "## " + v;
|
||||||
if (v !== 'Unreleased') markup += ' (' + formatDate(changes.date) + ')'
|
if (v !== "Unreleased") markup += " (" + formatDate(changes.date) + ")";
|
||||||
markup += '\n'
|
markup += "\n";
|
||||||
markup += changed ? changed : `\n**Note:** Version bump only for package ${pkg}\n\n\n`
|
markup += changed
|
||||||
|
? changed
|
||||||
|
: `\n**Note:** Version bump only for package ${pkg}\n\n\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return markup
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
let d = new Date(date),
|
let d = new Date(date),
|
||||||
month = '' + (d.getMonth() + 1),
|
month = "" + (d.getMonth() + 1),
|
||||||
day = '' + d.getDate(),
|
day = "" + d.getDate(),
|
||||||
year = d.getFullYear()
|
year = d.getFullYear();
|
||||||
|
|
||||||
if (month.length < 2) month = '0' + month
|
if (month.length < 2) month = "0" + month;
|
||||||
if (day.length < 2) day = '0' + day
|
if (day.length < 2) day = "0" + day;
|
||||||
|
|
||||||
return [year, month, day].join('-')
|
return [year, month, day].join("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure we have (at least) a description for each package
|
* Make sure we have (at least) a description for each package
|
||||||
*/
|
*/
|
||||||
function validate(pkgs, config) {
|
function validate(pkgs, config) {
|
||||||
console.log(chalk.blueBright('Validating package descriptions'))
|
console.log(chalk.blueBright("Validating package descriptions"));
|
||||||
for (let pkg of pkgs) {
|
for (let pkg of pkgs) {
|
||||||
if (typeof config.descriptions[pkg] !== 'string') {
|
if (typeof config.descriptions[pkg] !== "string") {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.redBright.bold('Problem:'),
|
chalk.redBright.bold("Problem:"),
|
||||||
chalk.redBright(`No description for package ${pkg}`)
|
chalk.redBright(`No description for package ${pkg}`)
|
||||||
)
|
);
|
||||||
process.exit()
|
process.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(chalk.yellowBright.bold('Looks good'))
|
console.log(chalk.yellowBright.bold("Looks good"));
|
||||||
|
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -386,41 +414,50 @@ function configurePatternExample(pkg, config) {
|
||||||
// Create example dir structure
|
// Create example dir structure
|
||||||
let source = path.join(
|
let source = path.join(
|
||||||
config.repoPath,
|
config.repoPath,
|
||||||
'packages',
|
"packages",
|
||||||
'create-freesewing-pattern',
|
"create-freesewing-pattern",
|
||||||
'template',
|
"template",
|
||||||
'default',
|
"default",
|
||||||
'example'
|
"example"
|
||||||
)
|
);
|
||||||
let dest = path.join(config.repoPath, 'packages', pkg, 'example')
|
let dest = path.join(config.repoPath, "packages", pkg, "example");
|
||||||
fse.ensureDirSync(path.join(dest, 'src'))
|
fse.ensureDirSync(path.join(dest, "src"));
|
||||||
fse.ensureDirSync(path.join(dest, 'public'))
|
fse.ensureDirSync(path.join(dest, "public"));
|
||||||
// Copy files
|
// Copy files
|
||||||
for (let file of ['.babelrc', '.env'])
|
for (let file of [".babelrc", ".env"])
|
||||||
fs.copyFileSync(path.join(source, file), path.join(dest, file))
|
fs.copyFileSync(path.join(source, file), path.join(dest, file));
|
||||||
for (let file of ['index.js', 'serviceWorker.js'])
|
for (let file of ["index.js", "serviceWorker.js"])
|
||||||
fs.copyFileSync(path.join(source, 'src', file), path.join(dest, 'src', file))
|
fs.copyFileSync(
|
||||||
|
path.join(source, "src", file),
|
||||||
|
path.join(dest, "src", file)
|
||||||
|
);
|
||||||
fs.copyFileSync(
|
fs.copyFileSync(
|
||||||
path.join(source, 'public', 'favicon.ico'),
|
path.join(source, "public", "favicon.ico"),
|
||||||
path.join(dest, 'public', 'favicon.ico')
|
path.join(dest, "public", "favicon.ico")
|
||||||
)
|
);
|
||||||
// Write templates
|
// Write templates
|
||||||
let replace = {
|
let replace = {
|
||||||
name: pkg,
|
name: pkg,
|
||||||
author: 'freesewing',
|
author: "freesewing",
|
||||||
yarn: true,
|
yarn: true,
|
||||||
language: 'en'
|
language: "en"
|
||||||
|
};
|
||||||
|
for (let file of ["package.json", "README.md"]) {
|
||||||
|
let template = handlebars.compile(
|
||||||
|
fs.readFileSync(path.join(source, file), "utf-8")
|
||||||
|
);
|
||||||
|
fs.writeFileSync(path.join(dest, file), template(replace));
|
||||||
}
|
}
|
||||||
for (let file of ['package.json', 'README.md']) {
|
for (let file of ["index.html", "manifest.json"]) {
|
||||||
let template = handlebars.compile(fs.readFileSync(path.join(source, file), 'utf-8'))
|
let template = handlebars.compile(
|
||||||
fs.writeFileSync(path.join(dest, file), template(replace))
|
fs.readFileSync(path.join(source, "public", file), "utf-8")
|
||||||
|
);
|
||||||
|
fs.writeFileSync(path.join(dest, "public", file), template(replace));
|
||||||
}
|
}
|
||||||
for (let file of ['index.html', 'manifest.json']) {
|
let template = handlebars.compile(
|
||||||
let template = handlebars.compile(fs.readFileSync(path.join(source, 'public', file), 'utf-8'))
|
fs.readFileSync(path.join(source, "src", "App.js"), "utf-8")
|
||||||
fs.writeFileSync(path.join(dest, 'public', file), template(replace))
|
);
|
||||||
}
|
fs.writeFileSync(path.join(dest, "src", "App.js"), template(replace));
|
||||||
let template = handlebars.compile(fs.readFileSync(path.join(source, 'src', 'App.js'), 'utf-8'))
|
|
||||||
fs.writeFileSync(path.join(dest, 'src', 'App.js'), template(replace))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -431,25 +468,32 @@ function configurePatternExample(pkg, config) {
|
||||||
*/
|
*/
|
||||||
function reconfigure(pkgs, config) {
|
function reconfigure(pkgs, config) {
|
||||||
for (let pkg of pkgs) {
|
for (let pkg of pkgs) {
|
||||||
console.log(chalk.blueBright(`Reconfiguring ${pkg}`))
|
console.log(chalk.blueBright(`Reconfiguring ${pkg}`));
|
||||||
let pkgConfig = packageConfig(pkg, config)
|
let pkgConfig = packageConfig(pkg, config);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(config.repoPath, 'packages', pkg, 'package.json'),
|
path.join(config.repoPath, "packages", pkg, "package.json"),
|
||||||
JSON.stringify(pkgConfig, null, 2) + '\n'
|
JSON.stringify(pkgConfig, null, 2) + "\n"
|
||||||
)
|
);
|
||||||
if (config.exceptions.customRollup.indexOf(pkg) === -1) {
|
if (config.exceptions.customRollup.indexOf(pkg) === -1) {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(config.repoPath, 'packages', pkg, 'rollup.config.js'),
|
path.join(config.repoPath, "packages", pkg, "rollup.config.js"),
|
||||||
config.templates.rollup
|
config.templates.rollup
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
fs.writeFileSync(path.join(config.repoPath, 'packages', pkg, 'README.md'), readme(pkg, config))
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(config.repoPath, 'packages', pkg, 'CHANGELOG.md'),
|
path.join(config.repoPath, "packages", pkg, "README.md"),
|
||||||
|
readme(pkg, config)
|
||||||
|
);
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(config.repoPath, "packages", pkg, "CHANGELOG.md"),
|
||||||
changelog(pkg, config)
|
changelog(pkg, config)
|
||||||
)
|
);
|
||||||
if (packageType(pkg, config) === 'pattern') configurePatternExample(pkg, config)
|
if (packageType(pkg, config) === "pattern")
|
||||||
|
configurePatternExample(pkg, config);
|
||||||
}
|
}
|
||||||
fs.writeFileSync(path.join(config.repoPath, 'CHANGELOG.md'), changelog('global', config))
|
fs.writeFileSync(
|
||||||
console.log(chalk.yellowBright.bold('All done.'))
|
path.join(config.repoPath, "CHANGELOG.md"),
|
||||||
|
changelog("global", config)
|
||||||
|
);
|
||||||
|
console.log(chalk.yellowBright.bold("All done."));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue