1
0
Fork 0

chore(yarn-new-design): Port to v3.

This commit is contained in:
Benjamin F 2022-10-02 13:11:29 -07:00
parent f847010561
commit 820004f3dd
3 changed files with 98 additions and 67 deletions

View file

@ -6,7 +6,7 @@
"homepage": "https://freesewing.org/", "homepage": "https://freesewing.org/",
"repository": "github:freesewing/freesewing", "repository": "github:freesewing/freesewing",
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.mjs",
"module": "dist/index.mjs", "module": "dist/index.mjs",
"scripts": { } "scripts": {}
} }

View file

@ -1,7 +1,19 @@
export default function (part) { import { pluginBundle } from '@freesewing/plugin-bundle'
const { options, Point, Path, points, paths, Snippet, snippets, complete, sa, paperless, macro } =
part.shorthand()
function draftBox({
options,
Point,
Path,
points,
paths,
Snippet,
snippets,
complete,
sa,
paperless,
macro,
part,
}) {
const w = 500 * options.size const w = 500 * options.size
points.topLeft = new Point(0, 0) points.topLeft = new Point(0, 0)
points.topRight = new Point(w, 0) points.topRight = new Point(w, 0)
@ -47,3 +59,12 @@ export default function (part) {
return part return part
} }
export const box = {
name: 'box',
options: {
size: { pct: 50, min: 10, max: 100, menu: 'fit' },
},
plugins: [pluginBundle],
draft: draftBox,
}

View file

@ -22,9 +22,8 @@ else if (type === 'plugin') {
console.clear() console.clear()
console.log(banner) console.log(banner)
addPlugin() addPlugin()
} } else
console.log(`
else console.log(`
Usage: Usage:
${chalk.bold.blue('yarn new design')} 👉 Adds a new design ${chalk.bold.blue('yarn new design')} 👉 Adds a new design
@ -32,7 +31,6 @@ else console.log(`
${chalk.bold.blue('yarn new')} ${chalk.yellow('[anything else]')} 👉 Shows this help ${chalk.bold.blue('yarn new')} ${chalk.yellow('[anything else]')} 👉 Shows this help
`) `)
async function addDesign() { async function addDesign() {
console.log(` console.log(`
@ -47,10 +45,22 @@ async function addDesign() {
name: 'type', name: 'type',
message: 'In what category should we add the design?', message: 'In what category should we add the design?',
choices: [ choices: [
{ title: 'Accessories', value: 'accessories', description: 'Hats, bags, plushies, and so on' }, {
title: 'Accessories',
value: 'accessories',
description: 'Hats, bags, plushies, and so on',
},
{ title: 'Blocks', value: 'blocks', description: 'Blocks/Slopers to base other designs on' }, { title: 'Blocks', value: 'blocks', description: 'Blocks/Slopers to base other designs on' },
{ title: 'Garments', value: 'garments', description: 'For clothes. The most common category' }, {
{ title: 'Utilities', value: 'utilities', description: 'For utility designs such as our rendertest or legend' }, title: 'Garments',
value: 'garments',
description: 'For clothes. The most common category',
},
{
title: 'Utilities',
value: 'utilities',
description: 'For utility designs such as our rendertest or legend',
},
], ],
initial: 2, initial: 2,
}) })
@ -61,8 +71,12 @@ async function addDesign() {
We'd appreciate if you pick: We'd appreciate if you pick:
- a firstname like ${chalk.green('alex')}, ${chalk.green('jordan')}, ${chalk.green('ezra')}, or ${chalk.green('logan')} - a firstname like ${chalk.green('alex')}, ${chalk.green('jordan')}, ${chalk.green(
- that is an aliteration with the kind of design, like ${chalk.green('wahid')} for a ${chalk.green('w')}aistcoat 'ezra'
)}, or ${chalk.green('logan')}
- that is an aliteration with the kind of design, like ${chalk.green(
'wahid'
)} for a ${chalk.green('w')}aistcoat
Bonus points for picking a name that embraces diversity 🌈 Bonus points for picking a name that embraces diversity 🌈
`) `)
@ -75,9 +89,9 @@ async function addDesign() {
}) })
if (name && type) { if (name && type) {
console.log("\n"+` Alright, let's add ${chalk.green(name)} under ${chalk.green(type)} 🪄`) console.log('\n' + ` Alright, let's add ${chalk.green(name)} under ${chalk.green(type)} 🪄`)
createDesign(name, type) createDesign(name, type)
execSync("npm run reconfigure") execSync('npm run reconfigure')
console.log(` All done 🎉`) console.log(` All done 🎉`)
try { try {
@ -86,9 +100,9 @@ async function addDesign() {
${chalk.bold.yellow('✨ Summary')} ${chalk.bold.yellow('✨ Summary')}
${chalk.gray('≡≡≡≡≡≡≡≡≡≡')} ${chalk.gray('≡≡≡≡≡≡≡≡≡≡')}
👉 We've created your design skeleton at ${chalk.green('designs/'+name)} 👉 We've created your design skeleton at ${chalk.green('designs/' + name)}
👉 We've configured the packages via the ${chalk.green('pacakge.json')} file 👉 We've configured the packages via the ${chalk.green('pacakge.json')} file
👉 We've added ${chalk.green('designs/'+name)} to the lab 👉 We've added ${chalk.green('designs/' + name)} to the lab
${chalk.bold.yellow('✏️ Make it your own')} ${chalk.bold.yellow('✏️ Make it your own')}
@ -96,9 +110,17 @@ async function addDesign() {
Hhere's a few other things you can configure: Hhere's a few other things you can configure:
👉 ${chalk.yellow('Author')}: Credit where credit is due; Add yourself as author in ${chalk.green('config/exceptions.yaml')} 👉 ${chalk.yellow('Author')}: Credit where credit is due; Add yourself as author in ${chalk.green(
👉 ${chalk.yellow('Description')}: We used a placeholder description; Update it in ${chalk.green('config/software/designs.json')} 'config/exceptions.yaml'
👉 ${chalk.yellow('Dependencies')}: If you need additional plugins or patterns to extend, update ${chalk.green('config/dependecies.yaml')} )}
👉 ${chalk.yellow('Description')}: We used a placeholder description; Update it in ${chalk.green(
'config/software/designs.json'
)}
👉 ${chalk.yellow(
'Dependencies'
)}: If you need additional plugins or patterns to extend, update ${chalk.green(
'config/dependecies.yaml'
)}
If you change any of these, run ${chalk.blue('yarn reconfigure')} to update the package(s). If you change any of these, run ${chalk.blue('yarn reconfigure')} to update the package(s).
@ -111,7 +133,7 @@ async function addDesign() {
🤓 Happy hacking 🤓 Happy hacking
`) `)
} catch(err) { } catch (err) {
console.log(err) console.log(err)
} }
} }
@ -130,14 +152,16 @@ async function addPlugin() {
`) `)
} }
function validateName(name) { function validateName(name) {
if ([ if (
...Object.keys(designs.accessories), [
...Object.keys(designs.blocks), ...Object.keys(designs.accessories),
...Object.keys(designs.garments), ...Object.keys(designs.blocks),
...Object.keys(designs.utilities) ...Object.keys(designs.garments),
].indexOf(name) !== -1) return `Sorry but ${name} is already taken so you'll need to pick something else` ...Object.keys(designs.utilities),
].indexOf(name) !== -1
)
return `Sorry but ${name} is already taken so you'll need to pick something else`
if (/^([a-z]+)$/.test(name)) return true if (/^([a-z]+)$/.test(name)) return true
else return ' 🙈 Please use only [a-z], no spaces, no capitals, no nothing 🤷' else return ' 🙈 Please use only [a-z], no spaces, no capitals, no nothing 🤷'
@ -146,41 +170,36 @@ function validateName(name) {
function createDesign(name, type) { function createDesign(name, type) {
const template = ['config', 'templates', 'design'] const template = ['config', 'templates', 'design']
const design = ['designs', name] const design = ['designs', name]
const description = 'FIXME: A FreeSewing pattern that needs a description' const description = 'A FreeSewing pattern that needs a description'
const capitalized_name = name.charAt(0).toUpperCase() + name.slice(1)
// Add to designs config file // Add to designs config file
designs[type][name] = description designs[type][name] = {
write( description: description,
['config', 'software', 'designs.json'], code: 'Coder name',
JSON.stringify(orderDesigns(designs), null, 2) design: 'Designer name',
) difficulty: 1,
tags: ['tagname'],
}
write(['config', 'software', 'designs.json'], JSON.stringify(orderDesigns(designs), null, 2))
// Create folders // Create folders
mkdir([...design, 'src']) mkdir([...design, 'src'])
mkdir([...design, 'tests']) mkdir([...design, 'tests'])
// Create package.json // Create package.json
templateOut( templateOut([...template, 'package.json'], [...design, 'package.json'], { name, description })
[...template, 'package.json'],
[...design, 'package.json'],
{ name, description }
)
// Create config file // Create index.mjs
templateOut( templateOut([...template, 'src', 'index.mjs'], [...design, 'src', 'index.mjs'], {
['config', 'templates', 'design', 'config.js'], capitalized_name,
['designs', name, 'config.js'], })
{ name, description }
)
// Create tests file // Create tests file
cp( cp([...template, 'tests', 'shared.test.mjs'], [...design, 'tests', 'shared.test.mjs'])
[...template, 'tests', 'shared.test.mjs'],
[...design, 'tests', 'shared.test.mjs']
)
// Copy source // Copy source
for (const file of ['index.js', 'box.js']) { for (const file of ['box.mjs']) {
cp([...template, 'src', file], [...design, 'src', file]) cp([...template, 'src', file], [...design, 'src', file])
} }
} }
@ -189,12 +208,9 @@ function templateOut(from, to, data) {
try { try {
fs.writeFileSync( fs.writeFileSync(
path.join(process.cwd(), ...to), path.join(process.cwd(), ...to),
mustache.render( mustache.render(fs.readFileSync(path.join(process.cwd(), ...from), 'utf-8'), data)
fs.readFileSync(path.join(process.cwd(), ...from), 'utf-8'),
data
)
) )
} catch(err) { } catch (err) {
console.log(err) console.log(err)
} }
@ -204,7 +220,7 @@ function templateOut(from, to, data) {
function write(to, data) { function write(to, data) {
try { try {
fs.writeFileSync(path.join(process.cwd(), ...to), data) fs.writeFileSync(path.join(process.cwd(), ...to), data)
} catch(err) { } catch (err) {
console.log(err) console.log(err)
} }
@ -213,11 +229,8 @@ function write(to, data) {
function mkdir(dir) { function mkdir(dir) {
try { try {
fs.mkdirSync( fs.mkdirSync(path.join(process.cwd(), ...dir), { recursive: true })
path.join(process.cwd(), ...dir), } catch (err) {
{ recursive: true }
)
} catch(err) {
console.log(err) console.log(err)
} }
@ -226,11 +239,8 @@ function mkdir(dir) {
function cp(from, to) { function cp(from, to) {
try { try {
fs.copyFileSync( fs.copyFileSync(path.join(process.cwd(), ...from), path.join(process.cwd(), ...to))
path.join(process.cwd(), ...from), } catch (err) {
path.join(process.cwd(), ...to)
)
} catch(err) {
console.log(err) console.log(err)
} }