2019-04-19 17:31:44 +02:00
|
|
|
/* eslint-disable no-console */
|
2020-05-31 17:53:04 +02:00
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs')
|
|
|
|
const fse = require('fs-extra')
|
|
|
|
const glob = require('glob')
|
|
|
|
const yaml = require('js-yaml')
|
|
|
|
const chalk = require('chalk')
|
|
|
|
const handlebars = require('handlebars')
|
|
|
|
const Mustache = require('mustache')
|
|
|
|
const { version } = require('../lerna.json')
|
|
|
|
const capitalize = require('@freesewing/utils/capitalize')
|
|
|
|
|
|
|
|
const repoPath = process.cwd()
|
2019-04-19 17:31:44 +02:00
|
|
|
const config = {
|
|
|
|
repoPath,
|
2020-05-31 17:53:04 +02:00
|
|
|
defaults: readConfigFile('defaults.yaml'),
|
|
|
|
descriptions: readConfigFile('descriptions.yaml'),
|
|
|
|
keywords: readConfigFile('keywords.yaml'),
|
|
|
|
badges: readConfigFile('badges.yaml'),
|
|
|
|
scripts: readConfigFile('scripts.yaml'),
|
|
|
|
changelog: readConfigFile('changelog.yaml'),
|
|
|
|
changetypes: ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'],
|
|
|
|
dependencies: readConfigFile('dependencies.yaml', { version }),
|
|
|
|
exceptions: readConfigFile('exceptions.yaml'),
|
2019-04-19 17:31:44 +02:00
|
|
|
templates: {
|
2020-05-31 17:53:04 +02:00
|
|
|
pkg: readTemplateFile('package.dflt.json'),
|
|
|
|
rollup: readTemplateFile('rollup.config.dflt.js'),
|
|
|
|
changelog: readTemplateFile('changelog.dflt.md'),
|
|
|
|
readme: readTemplateFile('readme.dflt.md')
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
}
|
2019-09-02 15:28:00 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
const packages = glob.sync('*', {
|
|
|
|
cwd: path.join(config.repoPath, 'packages')
|
|
|
|
})
|
2019-04-19 17:31:44 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
validate(packages, config)
|
|
|
|
reconfigure(packages, config)
|
2019-04-19 17:31:44 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
process.exit()
|
2019-04-19 17:31:44 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 08:04:02 +02:00
|
|
|
* Reads a template file
|
2019-04-19 17:31:44 +02:00
|
|
|
*/
|
2019-05-11 08:04:02 +02:00
|
|
|
function readTemplateFile(file) {
|
2020-05-31 17:53:04 +02:00
|
|
|
return fs.readFileSync(path.join(repoPath, 'config', 'templates', file), 'utf-8')
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 08:04:02 +02:00
|
|
|
/**
|
|
|
|
* Reads a pattern example file
|
|
|
|
*/
|
|
|
|
function readExampleFile(file, subdir = false) {
|
|
|
|
return fs.readFileSync(
|
|
|
|
subdir
|
|
|
|
? path.join(
|
|
|
|
repoPath,
|
2020-05-31 17:53:04 +02:00
|
|
|
'packages',
|
|
|
|
'create-freesewing-pattern',
|
|
|
|
'template',
|
|
|
|
'default',
|
|
|
|
'example',
|
2019-05-11 08:04:02 +02:00
|
|
|
file
|
|
|
|
)
|
|
|
|
: path.join(
|
|
|
|
repoPath,
|
2020-05-31 17:53:04 +02:00
|
|
|
'packages',
|
|
|
|
'create-freesewing-pattern',
|
|
|
|
'template',
|
|
|
|
'default',
|
|
|
|
'example',
|
2019-05-11 08:04:02 +02:00
|
|
|
subdir,
|
|
|
|
file
|
|
|
|
),
|
2020-05-31 17:53:04 +02:00
|
|
|
'utf-8'
|
|
|
|
)
|
2019-05-11 08:04:02 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 17:31:44 +02:00
|
|
|
/**
|
|
|
|
* Reads a YAML config file, with Mustache replacements if needed
|
|
|
|
*/
|
|
|
|
function readConfigFile(file, replace = false) {
|
|
|
|
if (replace)
|
2021-02-06 11:31:42 +01:00
|
|
|
return yaml.load(
|
2020-05-31 17:53:04 +02:00
|
|
|
Mustache.render(fs.readFileSync(path.join(repoPath, 'config', file), 'utf-8'), replace)
|
|
|
|
)
|
2021-02-06 11:31:42 +01:00
|
|
|
return yaml.load(fs.readFileSync(path.join(repoPath, 'config', file), 'utf-8'))
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 20:09:30 +02:00
|
|
|
/**
|
|
|
|
* Reads info.md from the package directory
|
|
|
|
* Returns its contents if it exists, or an empty string if not
|
|
|
|
*/
|
|
|
|
function readInfoFile(pkg) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let markup = ''
|
2019-04-19 20:09:30 +02:00
|
|
|
try {
|
2020-05-31 17:53:04 +02:00
|
|
|
markup = fs.readFileSync(path.join(repoPath, 'packages', pkg, 'info.md'), 'utf-8')
|
2019-09-06 09:43:37 +02:00
|
|
|
} catch (err) {
|
2020-05-31 17:53:04 +02:00
|
|
|
return ''
|
2019-04-19 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return markup
|
2019-04-19 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 17:31:44 +02:00
|
|
|
/**
|
|
|
|
* Figure out what sort of package this is.
|
|
|
|
* Returns a string, one of:
|
|
|
|
* - pattern
|
|
|
|
* - plugin
|
|
|
|
* - other
|
|
|
|
*/
|
|
|
|
function packageType(pkg, config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (pkg.substring(0, 7) === 'plugin-') return 'plugin'
|
|
|
|
if (config.descriptions[pkg].substring(0, 21) === 'A FreeSewing pattern ') return 'pattern'
|
|
|
|
return 'other'
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of keywords for a package
|
|
|
|
*/
|
|
|
|
function keywords(pkg, config, type) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (typeof config.keywords[pkg] !== 'undefined') return config.keywords[pkg]
|
|
|
|
if (typeof config.keywords[type] !== 'undefined') return config.keywords[type]
|
2019-04-19 17:31:44 +02:00
|
|
|
else {
|
|
|
|
console.log(
|
2020-05-31 17:53:04 +02:00
|
|
|
chalk.redBright.bold('Problem:'),
|
2019-04-19 17:31:44 +02:00
|
|
|
chalk.redBright(`No keywords for package ${pkg} which is of type ${type}`)
|
2020-05-31 17:53:04 +02:00
|
|
|
)
|
|
|
|
process.exit()
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an plain object of scripts for a package
|
|
|
|
*/
|
|
|
|
function scripts(pkg, config, type) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let runScripts = {}
|
2019-04-20 15:36:31 +02:00
|
|
|
for (let key of Object.keys(config.scripts._)) {
|
|
|
|
runScripts[key] = Mustache.render(config.scripts._[key], {
|
|
|
|
name: pkg
|
2020-05-31 17:53:04 +02:00
|
|
|
})
|
2019-04-20 15:36:31 +02:00
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
if (typeof config.scripts._types[type] !== 'undefined') {
|
2019-04-19 17:31:44 +02:00
|
|
|
for (let key of Object.keys(config.scripts._types[type])) {
|
|
|
|
runScripts[key] = Mustache.render(config.scripts._types[type][key], {
|
|
|
|
name: pkg
|
2020-05-31 17:53:04 +02:00
|
|
|
})
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
if (typeof config.scripts[pkg] !== 'undefined') {
|
2019-04-19 17:31:44 +02:00
|
|
|
for (let key of Object.keys(config.scripts[pkg])) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (config.scripts[pkg][key] === '!') delete runScripts[key]
|
2019-05-02 21:17:18 +02:00
|
|
|
else
|
|
|
|
runScripts[key] = Mustache.render(config.scripts[pkg][key], {
|
|
|
|
name: pkg
|
2020-05-31 17:53:04 +02:00
|
|
|
})
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return runScripts
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an plain object with the of dependencies for a package
|
2019-05-11 08:04:02 +02:00
|
|
|
* section is the key in the dependencies.yaml fine, one of:
|
2019-04-19 17:31:44 +02:00
|
|
|
*
|
|
|
|
* - _ (for dependencies)
|
|
|
|
* - dev (for devDependencies)
|
|
|
|
* - peer (for peerDependencies)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function deps(section, pkg, config, type) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let dependencies = {}
|
2019-04-19 17:31:44 +02:00
|
|
|
if (
|
2020-05-31 17:53:04 +02:00
|
|
|
typeof config.dependencies._types[type] !== 'undefined' &&
|
|
|
|
typeof config.dependencies._types[type][section] !== 'undefined'
|
2019-04-19 17:31:44 +02:00
|
|
|
)
|
2020-05-31 17:53:04 +02:00
|
|
|
dependencies = config.dependencies._types[type][section]
|
|
|
|
if (typeof config.dependencies[pkg] === 'undefined') return dependencies
|
|
|
|
if (typeof config.dependencies[pkg][section] !== 'undefined')
|
|
|
|
return { ...dependencies, ...config.dependencies[pkg][section] }
|
2019-05-11 08:04:02 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return dependencies
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These merely call deps() for the relevant dependency section
|
|
|
|
*/
|
|
|
|
function dependencies(pkg, config, type) {
|
2020-05-31 17:53:04 +02:00
|
|
|
return deps('_', pkg, config, type)
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
function devDependencies(pkg, config, type) {
|
2020-05-31 17:53:04 +02:00
|
|
|
return deps('dev', pkg, config, type)
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
function peerDependencies(pkg, config, type) {
|
2020-05-31 17:53:04 +02:00
|
|
|
return deps('peer', pkg, config, type)
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a package.json file for a package
|
|
|
|
*/
|
|
|
|
function packageConfig(pkg, config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let type = packageType(pkg, config)
|
|
|
|
let pkgConf = {}
|
2019-04-20 19:23:22 +02:00
|
|
|
// Let's keep these at the top
|
2020-05-31 17:53:04 +02:00
|
|
|
pkgConf.name = fullName(pkg, config)
|
|
|
|
pkgConf.version = version
|
|
|
|
pkgConf.description = config.descriptions[pkg]
|
2019-05-11 08:04:02 +02:00
|
|
|
pkgConf = {
|
|
|
|
...pkgConf,
|
|
|
|
...JSON.parse(Mustache.render(config.templates.pkg, { name: pkg }))
|
2020-05-31 17:53:04 +02:00
|
|
|
}
|
|
|
|
pkgConf.keywords = pkgConf.keywords.concat(keywords(pkg, config, type))
|
|
|
|
pkgConf.scripts = scripts(pkg, config, type)
|
|
|
|
pkgConf.dependencies = dependencies(pkg, config, type)
|
|
|
|
pkgConf.devDependencies = devDependencies(pkg, config, type)
|
|
|
|
pkgConf.peerDependencies = peerDependencies(pkg, config, type)
|
|
|
|
if (typeof config.exceptions.packageJson[pkg] !== 'undefined') {
|
2019-04-20 19:23:22 +02:00
|
|
|
pkgConf = {
|
|
|
|
...pkgConf,
|
|
|
|
...config.exceptions.packageJson[pkg]
|
2020-05-31 17:53:04 +02:00
|
|
|
}
|
2019-05-02 21:17:18 +02:00
|
|
|
for (let key of Object.keys(config.exceptions.packageJson[pkg])) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (config.exceptions.packageJson[pkg][key] === '!') delete pkgConf[key]
|
2019-05-02 21:17:18 +02:00
|
|
|
}
|
2019-04-20 19:23:22 +02:00
|
|
|
}
|
2020-08-08 17:20:08 +02:00
|
|
|
if (config.exceptions.namedExports.indexOf(pkg) !== -1) {
|
|
|
|
pkgConf.rollup.exports = 'named'
|
|
|
|
}
|
2019-04-19 17:31:44 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return pkgConf
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 20:09:30 +02:00
|
|
|
/**
|
|
|
|
* Returns an string with the markup for badges in the readme file
|
|
|
|
*/
|
|
|
|
function badges(pkg, config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let markup = ''
|
|
|
|
for (let group of ['_all', '_social']) {
|
|
|
|
markup += "<p align='center'>"
|
2019-04-19 20:48:29 +02:00
|
|
|
for (let key of Object.keys(config.badges[group])) {
|
2020-05-31 17:53:04 +02:00
|
|
|
markup += formatBadge(config.badges[group][key], pkg, fullName(pkg, config))
|
2019-04-19 20:48:29 +02:00
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
markup += '</p>'
|
2019-04-19 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return markup
|
2019-04-19 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 20:48:29 +02:00
|
|
|
/**
|
|
|
|
* Formats a badge for a readme file
|
|
|
|
*/
|
2019-04-21 12:57:12 +02:00
|
|
|
function formatBadge(badge, name, fullname) {
|
2019-04-19 20:48:29 +02:00
|
|
|
return `<a
|
2019-04-21 12:57:12 +02:00
|
|
|
href="${Mustache.render(badge.link, { name, fullname })}"
|
|
|
|
title="${Mustache.render(badge.alt, { name, fullname })}"
|
|
|
|
><img src="${Mustache.render(badge.img, { name, fullname })}"
|
|
|
|
alt="${Mustache.render(badge.alt, { name, fullname })}"/>
|
2020-05-31 17:53:04 +02:00
|
|
|
</a>`
|
2019-04-19 20:48:29 +02:00
|
|
|
}
|
2019-04-19 20:09:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the full (namespaced) name of a package
|
|
|
|
*/
|
|
|
|
function fullName(pkg, config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (config.exceptions.noNamespace.indexOf(pkg) !== -1) return pkg
|
|
|
|
else return `@freesewing/${pkg}`
|
2019-04-19 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a README.md file for a package
|
|
|
|
*/
|
|
|
|
function readme(pkg, config) {
|
|
|
|
let markup = Mustache.render(config.templates.readme, {
|
|
|
|
fullname: fullName(pkg, config),
|
|
|
|
description: config.descriptions[pkg],
|
|
|
|
badges: badges(pkg, config),
|
|
|
|
info: readInfoFile(pkg)
|
2020-05-31 17:53:04 +02:00
|
|
|
})
|
2019-04-19 20:09:30 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return markup
|
2019-04-19 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
2019-09-02 15:28:00 +02:00
|
|
|
/**
|
|
|
|
* Creates a CHANGELOG.md file for a package
|
|
|
|
*/
|
|
|
|
function changelog(pkg, config) {
|
|
|
|
let markup = Mustache.render(config.templates.changelog, {
|
2020-05-31 17:53:04 +02:00
|
|
|
fullname: pkg === 'global' ? 'FreeSewing (global)' : fullName(pkg, config),
|
|
|
|
changelog: pkg === 'global' ? globalChangelog(config) : packageChangelog(pkg, config)
|
|
|
|
})
|
2019-09-02 15:28:00 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return markup
|
2019-09-02 19:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the global changelog data
|
|
|
|
*/
|
|
|
|
function globalChangelog(config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let markup = ''
|
2019-09-02 19:51:56 +02:00
|
|
|
for (let v in config.changelog) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let changes = config.changelog[v]
|
|
|
|
markup += '\n## ' + v
|
|
|
|
if (v !== 'Unreleased') markup += ' (' + formatDate(changes.date) + ')'
|
|
|
|
markup += '\n\n'
|
2019-09-02 19:51:56 +02:00
|
|
|
for (let pkg of packages) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let changed = false
|
2019-09-02 19:51:56 +02:00
|
|
|
for (let type of config.changetypes) {
|
|
|
|
if (
|
2020-05-31 17:53:04 +02:00
|
|
|
typeof changes[type] !== 'undefined' &&
|
2019-09-02 19:51:56 +02:00
|
|
|
changes[type] !== null &&
|
2020-05-31 17:53:04 +02:00
|
|
|
typeof changes[type][pkg] !== 'undefined' &&
|
2019-09-02 19:51:56 +02:00
|
|
|
changes[type][pkg] !== null
|
|
|
|
) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (!changed) changed = ''
|
|
|
|
changed += '\n#### ' + type + '\n\n'
|
|
|
|
for (let change of changes[type][pkg]) changed += ' - ' + change + '\n'
|
2019-09-02 19:51:56 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
if (changed) markup += '### ' + pkg + '\n' + changed + '\n'
|
2019-09-02 19:51:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return markup
|
2019-09-02 15:28:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the changelog data for a package
|
|
|
|
*/
|
|
|
|
function packageChangelog(pkg, config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let log = {}
|
|
|
|
let version
|
|
|
|
let markup = ''
|
2019-09-02 19:51:56 +02:00
|
|
|
for (let v in config.changelog) {
|
2020-05-31 17:53:04 +02:00
|
|
|
version = v
|
|
|
|
let changes = config.changelog[v]
|
|
|
|
let changed = false
|
2019-09-02 19:51:56 +02:00
|
|
|
for (let type of config.changetypes) {
|
|
|
|
if (
|
2020-05-31 17:53:04 +02:00
|
|
|
typeof changes[type] !== 'undefined' &&
|
2019-09-02 19:51:56 +02:00
|
|
|
changes[type] !== null &&
|
2020-05-31 17:53:04 +02:00
|
|
|
typeof changes[type][pkg] !== 'undefined' &&
|
2019-09-02 19:51:56 +02:00
|
|
|
changes[type][pkg] !== null
|
|
|
|
) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (!changed) changed = ''
|
|
|
|
changed += '\n### ' + type + '\n\n'
|
|
|
|
for (let change of changes[type][pkg]) changed += ' - ' + change + '\n'
|
2019-09-02 19:51:56 +02:00
|
|
|
}
|
2019-09-02 15:28:00 +02:00
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
if (v !== 'Unreleased' && changed) {
|
|
|
|
markup += '\n## ' + v
|
|
|
|
markup += ' (' + formatDate(changes.date) + ')'
|
|
|
|
markup += '\n'
|
|
|
|
markup += changed
|
|
|
|
}
|
2019-09-02 15:28:00 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
markup += '\n\nThis is the **initial release**, and the start of this change log.\n'
|
|
|
|
if (version === '2.0.0')
|
|
|
|
markup += `
|
|
|
|
> Prior to version 2, FreeSewing was not a JavaScript project.
|
|
|
|
> As such, that history is out of scope for this change log.
|
|
|
|
`
|
|
|
|
|
|
|
|
return markup
|
2019-09-02 19:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatDate(date) {
|
|
|
|
let d = new Date(date),
|
2020-05-31 17:53:04 +02:00
|
|
|
month = '' + (d.getMonth() + 1),
|
|
|
|
day = '' + d.getDate(),
|
|
|
|
year = d.getFullYear()
|
2019-09-02 19:51:56 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
if (month.length < 2) month = '0' + month
|
|
|
|
if (day.length < 2) day = '0' + day
|
2019-09-02 19:51:56 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return [year, month, day].join('-')
|
2019-09-02 15:28:00 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 17:31:44 +02:00
|
|
|
/**
|
|
|
|
* Make sure we have (at least) a description for each package
|
|
|
|
*/
|
|
|
|
function validate(pkgs, config) {
|
2020-05-31 17:53:04 +02:00
|
|
|
console.log(chalk.blueBright('Validating package descriptions'))
|
2019-04-19 17:31:44 +02:00
|
|
|
for (let pkg of pkgs) {
|
2020-05-31 17:53:04 +02:00
|
|
|
if (typeof config.descriptions[pkg] !== 'string') {
|
2019-04-19 17:31:44 +02:00
|
|
|
console.log(
|
2020-05-31 17:53:04 +02:00
|
|
|
chalk.redBright.bold('Problem:'),
|
2019-04-19 17:31:44 +02:00
|
|
|
chalk.redBright(`No description for package ${pkg}`)
|
2020-05-31 17:53:04 +02:00
|
|
|
)
|
|
|
|
process.exit()
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
console.log(chalk.yellowBright.bold('Looks good'))
|
2019-04-19 17:31:44 +02:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
return true
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 08:04:02 +02:00
|
|
|
/**
|
|
|
|
* Creates and 'example' directory for patterns,
|
|
|
|
* same result as what gets done by create-freesewing-pattern.
|
|
|
|
*/
|
|
|
|
function configurePatternExample(pkg, config) {
|
|
|
|
// Create example dir structure
|
|
|
|
let source = path.join(
|
|
|
|
config.repoPath,
|
2020-05-31 17:53:04 +02:00
|
|
|
'packages',
|
|
|
|
'create-freesewing-pattern',
|
|
|
|
'template',
|
2021-05-22 18:00:41 +02:00
|
|
|
'freesewing',
|
2020-05-31 17:53:04 +02:00
|
|
|
'example'
|
|
|
|
)
|
|
|
|
let dest = path.join(config.repoPath, 'packages', pkg, 'example')
|
|
|
|
fse.ensureDirSync(path.join(dest, 'src'))
|
|
|
|
fse.ensureDirSync(path.join(dest, 'public'))
|
2019-05-11 08:04:02 +02:00
|
|
|
// Copy files
|
2020-05-31 17:53:04 +02:00
|
|
|
for (let file of ['.babelrc', '.env'])
|
|
|
|
fs.copyFileSync(path.join(source, file), path.join(dest, file))
|
2021-04-17 13:02:16 +02:00
|
|
|
for (let file of ['index.js', 'serviceWorker.js', 'layout.css'])
|
2020-05-31 17:53:04 +02:00
|
|
|
fs.copyFileSync(path.join(source, 'src', file), path.join(dest, 'src', file))
|
2019-05-11 08:04:02 +02:00
|
|
|
fs.copyFileSync(
|
2020-05-31 17:53:04 +02:00
|
|
|
path.join(source, 'public', 'favicon.ico'),
|
|
|
|
path.join(dest, 'public', 'favicon.ico')
|
|
|
|
)
|
2019-05-11 08:04:02 +02:00
|
|
|
// Write templates
|
|
|
|
let replace = {
|
|
|
|
name: pkg,
|
2020-10-25 13:48:17 +01:00
|
|
|
version,
|
2020-05-31 17:53:04 +02:00
|
|
|
author: 'freesewing',
|
2019-05-11 08:04:02 +02:00
|
|
|
yarn: true,
|
2020-05-31 17:53:04 +02:00
|
|
|
language: 'en'
|
2019-05-11 08:04:02 +02:00
|
|
|
}
|
2020-10-25 14:05:27 +01:00
|
|
|
for (let file of ['package.json', 'README.md', 'netlify.toml']) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let template = handlebars.compile(fs.readFileSync(path.join(source, file), 'utf-8'))
|
|
|
|
fs.writeFileSync(path.join(dest, file), template(replace))
|
2019-05-11 08:04:02 +02:00
|
|
|
}
|
2021-01-11 19:47:10 +01:00
|
|
|
for (let file of ['index.html', 'manifest.json', 'layout.css']) {
|
2020-05-31 17:53:04 +02:00
|
|
|
let template = handlebars.compile(fs.readFileSync(path.join(source, 'public', file), 'utf-8'))
|
|
|
|
fs.writeFileSync(path.join(dest, 'public', file), 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))
|
2019-05-11 08:04:02 +02:00
|
|
|
}
|
|
|
|
|
2020-03-14 15:04:45 +01:00
|
|
|
/**
|
|
|
|
* Adds unit tests for patterns
|
|
|
|
*/
|
|
|
|
function configurePatternUnitTests(pkg, config) {
|
|
|
|
// Create tests directory
|
2020-05-31 17:53:04 +02:00
|
|
|
let dest = path.join(config.repoPath, 'packages', pkg, 'tests')
|
2020-03-14 15:04:45 +01:00
|
|
|
fse.ensureDirSync(dest)
|
2020-05-31 17:53:04 +02:00
|
|
|
let source = path.join(config.repoPath, 'config', 'templates', 'tests', 'patterns')
|
2020-03-14 15:04:45 +01:00
|
|
|
// Write templates
|
2020-07-12 15:58:07 +02:00
|
|
|
let peerdeps = peerDependencies(pkg, config, 'pattern')
|
2020-03-14 15:04:45 +01:00
|
|
|
let replace = {
|
2020-07-12 15:58:07 +02:00
|
|
|
version,
|
2020-03-14 15:04:45 +01:00
|
|
|
pattern: pkg,
|
2020-03-14 17:09:14 +01:00
|
|
|
Pattern: capitalize(pkg),
|
2020-08-08 17:20:08 +02:00
|
|
|
peerdeps: Object.keys(peerdeps)
|
|
|
|
.map((dep) => dep + '@' + peerdeps[dep])
|
|
|
|
.join(' ')
|
2020-05-31 17:53:04 +02:00
|
|
|
}
|
2020-03-14 17:09:14 +01:00
|
|
|
|
2020-05-31 17:53:04 +02:00
|
|
|
for (let file of ['shared.test.js']) {
|
2020-03-14 15:37:36 +01:00
|
|
|
fs.writeFileSync(
|
|
|
|
path.join(dest, file),
|
2020-05-31 17:53:04 +02:00
|
|
|
Mustache.render(fs.readFileSync(path.join(source, file + '.template'), 'utf-8'), replace)
|
|
|
|
)
|
2020-03-14 15:04:45 +01:00
|
|
|
}
|
|
|
|
// Add workflow file for Github actions
|
2020-03-14 15:37:36 +01:00
|
|
|
fs.writeFileSync(
|
2020-05-31 17:53:04 +02:00
|
|
|
path.join(config.repoPath, '.github', 'workflows', `tests.${pkg}.yml`),
|
2020-03-14 15:37:36 +01:00
|
|
|
Mustache.render(
|
2020-05-31 17:53:04 +02:00
|
|
|
fs.readFileSync(
|
|
|
|
path.join(config.repoPath, 'config', 'templates', 'workflows', 'tests.pattern.yml'),
|
|
|
|
'utf-8'
|
|
|
|
),
|
2020-03-14 15:37:36 +01:00
|
|
|
replace
|
|
|
|
)
|
2020-05-31 17:53:04 +02:00
|
|
|
)
|
2020-03-14 15:04:45 +01:00
|
|
|
}
|
|
|
|
|
2019-04-19 17:31:44 +02:00
|
|
|
/**
|
2019-09-02 15:28:00 +02:00
|
|
|
* Puts a package.json, rollup.config.js, README.md, and CHANGELOG.md
|
2019-04-19 17:31:44 +02:00
|
|
|
* into every subdirectory under the packages directory.
|
2019-09-02 15:28:00 +02:00
|
|
|
* Also creates an example dir for pattern packages, and writes
|
|
|
|
* the global CHANGELOG.md.
|
2020-03-14 15:04:45 +01:00
|
|
|
* New: Adds unit tests for patterns
|
2019-04-19 17:31:44 +02:00
|
|
|
*/
|
|
|
|
function reconfigure(pkgs, config) {
|
|
|
|
for (let pkg of pkgs) {
|
2020-05-31 17:53:04 +02:00
|
|
|
console.log(chalk.blueBright(`Reconfiguring ${pkg}`))
|
|
|
|
let pkgConfig = packageConfig(pkg, config)
|
2019-05-11 08:04:02 +02:00
|
|
|
fs.writeFileSync(
|
2020-05-31 17:53:04 +02:00
|
|
|
path.join(config.repoPath, 'packages', pkg, 'package.json'),
|
|
|
|
JSON.stringify(pkgConfig, null, 2) + '\n'
|
|
|
|
)
|
2019-04-20 19:23:22 +02:00
|
|
|
if (config.exceptions.customRollup.indexOf(pkg) === -1) {
|
2019-05-11 08:04:02 +02:00
|
|
|
fs.writeFileSync(
|
2020-05-31 17:53:04 +02:00
|
|
|
path.join(config.repoPath, 'packages', pkg, 'rollup.config.js'),
|
2019-04-19 17:31:44 +02:00
|
|
|
config.templates.rollup
|
2020-05-31 17:53:04 +02:00
|
|
|
)
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
fs.writeFileSync(path.join(config.repoPath, 'packages', pkg, 'README.md'), readme(pkg, config))
|
2019-05-11 08:04:02 +02:00
|
|
|
fs.writeFileSync(
|
2020-05-31 17:53:04 +02:00
|
|
|
path.join(config.repoPath, 'packages', pkg, 'CHANGELOG.md'),
|
2019-09-02 15:28:00 +02:00
|
|
|
changelog(pkg, config)
|
2020-05-31 17:53:04 +02:00
|
|
|
)
|
|
|
|
if (packageType(pkg, config) === 'pattern') {
|
|
|
|
configurePatternExample(pkg, config)
|
|
|
|
configurePatternUnitTests(pkg, config)
|
2020-03-14 15:04:45 +01:00
|
|
|
}
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|
2020-05-31 17:53:04 +02:00
|
|
|
fs.writeFileSync(path.join(config.repoPath, 'CHANGELOG.md'), changelog('global', config))
|
|
|
|
console.log(chalk.yellowBright.bold('All done.'))
|
2019-04-19 17:31:44 +02:00
|
|
|
}
|