diff --git a/config/templates/design/package.json b/config/templates/design/package.json index 06867ede26f..22e3a375618 100644 --- a/config/templates/design/package.json +++ b/config/templates/design/package.json @@ -6,7 +6,7 @@ "homepage": "https://freesewing.org/", "repository": "github:freesewing/freesewing", "license": "MIT", - "main": "dist/index.js", + "main": "dist/index.mjs", "module": "dist/index.mjs", - "scripts": { } + "scripts": {} } diff --git a/config/templates/design/src/box.mjs b/config/templates/design/src/box.mjs index 18b3ab1e23b..b06ac5a6c20 100644 --- a/config/templates/design/src/box.mjs +++ b/config/templates/design/src/box.mjs @@ -1,7 +1,19 @@ -export default function (part) { - const { options, Point, Path, points, paths, Snippet, snippets, complete, sa, paperless, macro } = - part.shorthand() +import { pluginBundle } from '@freesewing/plugin-bundle' +function draftBox({ + options, + Point, + Path, + points, + paths, + Snippet, + snippets, + complete, + sa, + paperless, + macro, + part, +}) { const w = 500 * options.size points.topLeft = new Point(0, 0) points.topRight = new Point(w, 0) @@ -47,3 +59,12 @@ export default function (part) { return part } + +export const box = { + name: 'box', + options: { + size: { pct: 50, min: 10, max: 100, menu: 'fit' }, + }, + plugins: [pluginBundle], + draft: draftBox, +} diff --git a/scripts/add-software.mjs b/scripts/add-software.mjs index 5c506c58730..07f4730784c 100644 --- a/scripts/add-software.mjs +++ b/scripts/add-software.mjs @@ -22,9 +22,8 @@ else if (type === 'plugin') { console.clear() console.log(banner) addPlugin() -} - -else console.log(` +} else + console.log(` Usage: ${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 `) - async function addDesign() { console.log(` @@ -47,10 +45,22 @@ async function addDesign() { name: 'type', message: 'In what category should we add the design?', 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: '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, }) @@ -61,8 +71,12 @@ async function addDesign() { We'd appreciate if you pick: - - a firstname like ${chalk.green('alex')}, ${chalk.green('jordan')}, ${chalk.green('ezra')}, or ${chalk.green('logan')} - - that is an aliteration with the kind of design, like ${chalk.green('wahid')} for a ${chalk.green('w')}aistcoat + - a firstname like ${chalk.green('alex')}, ${chalk.green('jordan')}, ${chalk.green( + '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 ๐ŸŒˆ โœŠ `) @@ -75,9 +89,9 @@ async function addDesign() { }) 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) - execSync("npm run reconfigure") + execSync('npm run reconfigure') console.log(` All done ๐ŸŽ‰`) try { @@ -86,9 +100,9 @@ async function addDesign() { ${chalk.bold.yellow('โœจ Summary')} ${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 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')} @@ -96,9 +110,17 @@ async function addDesign() { 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('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')} + ๐Ÿ‘‰ ${chalk.yellow('Author')}: Credit where credit is due; Add yourself as author in ${chalk.green( + 'config/exceptions.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). @@ -111,7 +133,7 @@ async function addDesign() { ๐Ÿค“ Happy hacking `) - } catch(err) { + } catch (err) { console.log(err) } } @@ -130,14 +152,16 @@ async function addPlugin() { `) } - function validateName(name) { - if ([ - ...Object.keys(designs.accessories), - ...Object.keys(designs.blocks), - ...Object.keys(designs.garments), - ...Object.keys(designs.utilities) - ].indexOf(name) !== -1) return `Sorry but ${name} is already taken so you'll need to pick something else` + if ( + [ + ...Object.keys(designs.accessories), + ...Object.keys(designs.blocks), + ...Object.keys(designs.garments), + ...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 else return ' ๐Ÿ™ˆ Please use only [a-z], no spaces, no capitals, no nothing ๐Ÿคท' @@ -146,41 +170,36 @@ function validateName(name) { function createDesign(name, type) { const template = ['config', 'templates', 'design'] 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 - designs[type][name] = description - write( - ['config', 'software', 'designs.json'], - JSON.stringify(orderDesigns(designs), null, 2) - ) + designs[type][name] = { + description: description, + code: 'Coder name', + design: 'Designer name', + difficulty: 1, + tags: ['tagname'], + } + write(['config', 'software', 'designs.json'], JSON.stringify(orderDesigns(designs), null, 2)) // Create folders mkdir([...design, 'src']) mkdir([...design, 'tests']) // Create package.json - templateOut( - [...template, 'package.json'], - [...design, 'package.json'], - { name, description } - ) + templateOut([...template, 'package.json'], [...design, 'package.json'], { name, description }) - // Create config file - templateOut( - ['config', 'templates', 'design', 'config.js'], - ['designs', name, 'config.js'], - { name, description } - ) + // Create index.mjs + templateOut([...template, 'src', 'index.mjs'], [...design, 'src', 'index.mjs'], { + capitalized_name, + }) // Create tests file - cp( - [...template, 'tests', 'shared.test.mjs'], - [...design, 'tests', 'shared.test.mjs'] - ) + cp([...template, 'tests', 'shared.test.mjs'], [...design, 'tests', 'shared.test.mjs']) // Copy source - for (const file of ['index.js', 'box.js']) { + for (const file of ['box.mjs']) { cp([...template, 'src', file], [...design, 'src', file]) } } @@ -189,12 +208,9 @@ function templateOut(from, to, data) { try { fs.writeFileSync( path.join(process.cwd(), ...to), - mustache.render( - fs.readFileSync(path.join(process.cwd(), ...from), 'utf-8'), - data - ) + mustache.render(fs.readFileSync(path.join(process.cwd(), ...from), 'utf-8'), data) ) - } catch(err) { + } catch (err) { console.log(err) } @@ -204,7 +220,7 @@ function templateOut(from, to, data) { function write(to, data) { try { fs.writeFileSync(path.join(process.cwd(), ...to), data) - } catch(err) { + } catch (err) { console.log(err) } @@ -213,11 +229,8 @@ function write(to, data) { function mkdir(dir) { try { - fs.mkdirSync( - path.join(process.cwd(), ...dir), - { recursive: true } - ) - } catch(err) { + fs.mkdirSync(path.join(process.cwd(), ...dir), { recursive: true }) + } catch (err) { console.log(err) } @@ -226,11 +239,8 @@ function mkdir(dir) { function cp(from, to) { try { - fs.copyFileSync( - path.join(process.cwd(), ...from), - path.join(process.cwd(), ...to) - ) - } catch(err) { + fs.copyFileSync(path.join(process.cwd(), ...from), path.join(process.cwd(), ...to)) + } catch (err) { console.log(err) }