From 332541bac5d7eb0b7802f6195f928b264253b07b Mon Sep 17 00:00:00 2001 From: Nikhil Chelliah Date: Fri, 14 Oct 2022 17:37:52 -0400 Subject: [PATCH 1/3] refactor(new-design): Make some changes to lib/utils.js * Support `.mustache` template files in `packages/new-design/shared/`, just as in `packages/new-design/templates/*/`. * Only render files with an explicit `.mustache` suffix. * In `downloadLabFiles`: * Don't try to write response failures into the destination file. This was failing because it wasn't wrapping the error in `{data: ...}` to imitate a successful axios response. * Actually wait for `writeFile` to finish. Don't try to add to `promises` after they've already been collected with `Promise.all`. * General refactoring (really leaning into Promises here...) --- packages/new-design/lib/utils.mjs | 120 +++++++++++++++++------------- 1 file changed, 67 insertions(+), 53 deletions(-) diff --git a/packages/new-design/lib/utils.mjs b/packages/new-design/lib/utils.mjs index bb2caf372e2..99bc28c2ae6 100644 --- a/packages/new-design/lib/utils.mjs +++ b/packages/new-design/lib/utils.mjs @@ -1,6 +1,6 @@ import { config } from './config.mjs' import { mkdir, readFile, writeFile, copyFile } from 'node:fs/promises' -import { join, dirname } from 'path' +import { join, dirname, relative } from 'path' import mustache from 'mustache' import rdir from 'recursive-readdir' import chalk from 'chalk' @@ -11,12 +11,13 @@ import axios from 'axios' import { fileURLToPath } from 'url' // Current working directory -let cwd +let filename try { - cwd = __dirname + filename = __filename } catch { - cwd = dirname(fileURLToPath(import.meta.url)) + filename = fileURLToPath(import.meta.url) } +const newDesignDir = join(filename, '../..') const nl = '\n' const tab = ' ' @@ -114,41 +115,49 @@ export const getChoices = async () => { } // Keep track of directories that need to be created -const dirs = {} +const dirPromises = {} const ensureDir = async (file, suppress = false) => { const dir = suppress ? dirname(file.replace(suppress)) : dirname(file) - if (!dirs[dir]) { - await mkdir(dir, { recursive: true }) - dirs[dir] = true + if (!dirPromises[dir]) { + dirPromises[dir] = mkdir(dir, { recursive: true }) + } + await dirPromises[dir] +} + +// Helper method to copy template files +const copyFileOrTemplate = async (fromRoot, toRoot, relativeFile, templateVars) => { + const from = join(fromRoot, relativeFile) + const to = join( + toRoot, + relativeFile.endsWith('.mustache') ? relativeFile.slice(0, -9) : relativeFile + ) + + await ensureDir(to) + + if (relativeFile.endsWith('.mustache')) { + const template = await readFile(from, 'utf-8') + const rendered = mustache.render(template, templateVars) + await writeFile(to, rendered) + } else { + await copyFile(from, to) } } // Helper method to copy template files -const copyTemplate = async (config, choices) => { - // Copy files in parallel rather than using await - const promises = [] - +const copyAll = async (config, templateVars) => { // Copy shared files - for (const from of config.files.shared) { - // FIXME: Explain the -7 - const to = join(config.dest, from.slice(config.source.shared.length - 7)) - if (!dirs[to]) await ensureDir(to) - promises.push(copyFile(from, to)) - } + await Promise.all( + config.relativeFiles.shared.map((from) => { + copyFileOrTemplate(config.source.shared, config.dest, from, templateVars) + }) + ) // Template files - for (const from of config.files.template) { - let to = join(config.dest, from.slice(config.source.template.length - 7)) - if (to.slice(-9) === '.mustache') to = to.slice(0, -9) - if (!dirs[to]) await ensureDir(to) - // Template out file - const src = await readFile(from, 'utf-8') - promises.push(writeFile(to, mustache.render(src, { name: choices.name, tag: config.tag }))) - } - - await Promise.all(promises) - - return + await Promise.all( + config.relativeFiles.template.map((from) => { + copyFileOrTemplate(config.source.template, config.dest, from, templateVars) + }) + ) } // Helper method to run [yarn|npm] install @@ -162,25 +171,25 @@ const installDependencies = async (config, choices) => const downloadLabFiles = async (config) => { const promises = [] for (const dir in config.fetch) { - for (const file of config.fetch[dir]) { - const to = typeof file === 'string' ? join(config.dest, file) : join(config.dest, file.to) - if (!dirs[to]) await ensureDir(to) - promises.push( - axios - .get( + promises.push( + ...config.fetch[dir].map(async (file) => { + const to = typeof file === 'string' ? join(config.dest, file) : join(config.dest, file.to) + await ensureDir(to) + try { + const res = await axios.get( `${config.fileUri}/${config.repo}/${config.branch}/${dir}/${ typeof file === 'string' ? file : file.from }` ) - .catch((err) => console.log(err)) - .then((res) => promises.push(writeFile(to, res.data))) - ) - } + await writeFile(to, res.data) + } catch (err) { + console.log(err) + } + }) + ) } - await Promise.all(promises) - - return + return Promise.all(promises) } // Helper method to initialize a git repository @@ -253,21 +262,21 @@ const showTips = (config, choices) => { // Creates the environment based on the user's choices export const createEnvironment = async (choices) => { // Store directories for re-use - ;(config.cwd = cwd), - (config.source = { - root: cwd, - template: cwd + `/../templates/from-${choices.template}`, - shared: cwd + `/../shared`, - }) + config.source = { + template: `${newDesignDir}/templates/from-${choices.template}`, + shared: `${newDesignDir}/shared`, + } config.dest = join(process.cwd(), choices.name) // Create target directory await mkdir(config.dest, { recursive: true }) // Find files - config.files = { - template: await rdir(config.source.template), - shared: await rdir(config.source.shared), + config.relativeFiles = { + template: (await rdir(config.source.template)).map((file) => + relative(config.source.template, file) + ), + shared: (await rdir(config.source.shared)).map((file) => relative(config.source.shared, file)), } // Output a linebreak @@ -275,7 +284,12 @@ export const createEnvironment = async (choices) => { // Copy/Template files try { - await oraPromise(copyTemplate(config, choices), { + const templateVars = { + template: choices.template, + name: choices.name, + tag: config.tag, + } + await oraPromise(copyAll(config, templateVars), { text: chalk.white.bold('🟨⬜⬜⬜ Copying template files') + chalk.white.dim(' | Just a moment'), From 49e4496e4bf56a16f2e347a897ff924274d6ae3e Mon Sep 17 00:00:00 2001 From: Nikhil Chelliah Date: Fri, 14 Oct 2022 17:39:39 -0400 Subject: [PATCH 2/3] refactor(new-design): Coalesce the various package.json files --- packages/new-design/lib/utils.mjs | 14 ++- .../package.json.mustache | 3 + .../from-bella/package.json.mustache | 97 ------------------- .../templates/from-bent/package.json.mustache | 97 ------------------- .../from-breanna/package.json.mustache | 97 ------------------- .../from-brian/package.json.mustache | 96 ------------------ .../from-scratch/package.json.mustache | 97 ------------------- .../from-titan/package.json.mustache | 97 ------------------- 8 files changed, 15 insertions(+), 583 deletions(-) rename packages/new-design/{templates/from-tutorial => shared}/package.json.mustache (97%) delete mode 100644 packages/new-design/templates/from-bella/package.json.mustache delete mode 100644 packages/new-design/templates/from-bent/package.json.mustache delete mode 100644 packages/new-design/templates/from-breanna/package.json.mustache delete mode 100644 packages/new-design/templates/from-brian/package.json.mustache delete mode 100644 packages/new-design/templates/from-scratch/package.json.mustache delete mode 100644 packages/new-design/templates/from-titan/package.json.mustache diff --git a/packages/new-design/lib/utils.mjs b/packages/new-design/lib/utils.mjs index 99bc28c2ae6..56ccfeb6557 100644 --- a/packages/new-design/lib/utils.mjs +++ b/packages/new-design/lib/utils.mjs @@ -1,5 +1,5 @@ import { config } from './config.mjs' -import { mkdir, readFile, writeFile, copyFile } from 'node:fs/promises' +import { mkdir, readFile, writeFile, copyFile, stat } from 'node:fs/promises' import { join, dirname, relative } from 'path' import mustache from 'mustache' import rdir from 'recursive-readdir' @@ -18,6 +18,7 @@ try { filename = fileURLToPath(import.meta.url) } const newDesignDir = join(filename, '../..') +const monorepoDesignsDir = join(newDesignDir, '../../designs') const nl = '\n' const tab = ' ' @@ -285,10 +286,19 @@ export const createEnvironment = async (choices) => { // Copy/Template files try { const templateVars = { - template: choices.template, name: choices.name, tag: config.tag, } + + try { + await stat(join(monorepoDesignsDir, choices.template)) + if (choices.template !== 'tutorial') { + templateVars.block = choices.template + } + } catch (err) { + // fs.stat throws an error if no such file or directory exists + } + await oraPromise(copyAll(config, templateVars), { text: chalk.white.bold('🟨⬜⬜⬜ Copying template files') + diff --git a/packages/new-design/templates/from-tutorial/package.json.mustache b/packages/new-design/shared/package.json.mustache similarity index 97% rename from packages/new-design/templates/from-tutorial/package.json.mustache rename to packages/new-design/shared/package.json.mustache index 1259c67e9fb..b07bd109e6f 100644 --- a/packages/new-design/templates/from-tutorial/package.json.mustache +++ b/packages/new-design/shared/package.json.mustache @@ -35,6 +35,9 @@ "dependencies": { "@freesewing/core": "{{ tag }}", "@freesewing/plugin-bundle": "{{ tag }}" + {{# block }} + , "@freesewing/{{ block }}": "{{ tag }}" + {{/ block }} }, "devDependencies": { "@freesewing/plugin-svgattr": "{{ tag }}", diff --git a/packages/new-design/templates/from-bella/package.json.mustache b/packages/new-design/templates/from-bella/package.json.mustache deleted file mode 100644 index 89c5fba9bdc..00000000000 --- a/packages/new-design/templates/from-bella/package.json.mustache +++ /dev/null @@ -1,97 +0,0 @@ -{ - "name": "@freesewing/{{name}}", - "version": "0.0.1", - "description": "A new FreeSewing design", - "author": "Joost De Cock (https://github.com/joostdecock)", - "homepage": "https://freesewing.org/", - "repository": "github:freesewing/freesewing", - "license": "MIT", - "bugs": { - "url": "https://github.com/freesewing/freesewing/issues" - }, - "funding": { - "type": "individual", - "url": "https://freesewing.org/patrons/join" - }, - "keywords": [ - "freesewing", - "design", - "diy", - "fashion", - "parametric design", - "sewing", - "sewing pattern" - ], - "main": "dist/index.js", - "module": "dist/index.mjs", - "scripts": { - "dev": "node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", - "build": "node build.js", - "clean": "rimraf dist", - "mbuild": "NO_MINIFY=1 node build.js", - "test": "BABEL_ENV=production npx mocha tests/*.test.mjs --require @babel/register", - "vbuild": "VERBOSE=1 node build.js" - }, - "dependencies": { - "@freesewing/core": "{{ tag }}", - "@freesewing/bella": "{{ tag }}", - }, - "devDependencies": { - "@freesewing/plugin-svgattr": "{{ tag }}", - "@freesewing/plugin-theme": "{{ tag }}", - "@freesewing/plugin-i18n": "{{ tag }}", - "@freesewing/models": "{{ tag }}", - "@headlessui/react": "^1.6.5", - "js-yaml": "^4.1.0", - "file-saver": "^2.0.5", - "axios": "^0.27.2", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "react-sizeme": "^3.0.2", - "react-zoom-pan-pinch": "^2.1.3", - "react-markdown": "^8.0.3", - "roughjs": "^4.5.2", - "@tailwindcss/typography": "^0.5.2", - "d3-dispatch": "^3.0.1", - "d3-drag": "^3.0.0", - "d3-selection": "^3.0.0", - "daisyui": "^2.0.6", - "lodash.get": "^4.4.2", - "lodash.orderby": "^4.6.0", - "lodash.set": "^4.3.2", - "lodash.unset": "^4.5.2", - "lodash.clonedeep": "^4.5.0", - "next": "latest", - "next-i18next": "^11.0.0", - "react-copy-to-clipboard": "^5.0.4", - "react-hotkeys-hook": "^3.4.4", - "react-swipeable": "^6.2.0", - "react-timeago": "^6.2.1", - "mocha": "^9.1.1", - "chai": "^4.2.0", - "autoprefixer": "^10.4.0", - "eslint-config-next": "12.1.6", - "highlight.js": "^11.5.1", - "js-yaml": "^4.1.0", - "pdfkit": "^0.13.0", - "svg-to-pdfkit": "^0.1.8", - "postcss": "^8.4.14", - "postcss-for": "^2.1.1", - "tailwindcss": "^3.1.3", - "tailwindcss-open-variant": "^1.0.0", - "web-worker": "^1.2.0" - }, - "files": [ - "dist/*", - "README.md", - "package.json" - ], - "publishConfig": { - "access": "public", - "tag": "next" - }, - "engines": { - "node": ">=14.0.0", - "npm": ">=6" - } -} diff --git a/packages/new-design/templates/from-bent/package.json.mustache b/packages/new-design/templates/from-bent/package.json.mustache deleted file mode 100644 index e2a2d64b253..00000000000 --- a/packages/new-design/templates/from-bent/package.json.mustache +++ /dev/null @@ -1,97 +0,0 @@ -{ - "name": "@freesewing/{{name}}", - "version": "0.0.1", - "description": "A new FreeSewing design", - "author": "Joost De Cock (https://github.com/joostdecock)", - "homepage": "https://freesewing.org/", - "repository": "github:freesewing/freesewing", - "license": "MIT", - "bugs": { - "url": "https://github.com/freesewing/freesewing/issues" - }, - "funding": { - "type": "individual", - "url": "https://freesewing.org/patrons/join" - }, - "keywords": [ - "freesewing", - "design", - "diy", - "fashion", - "parametric design", - "sewing", - "sewing pattern" - ], - "main": "dist/index.js", - "module": "dist/index.mjs", - "scripts": { - "dev": "node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", - "build": "node build.js", - "clean": "rimraf dist", - "mbuild": "NO_MINIFY=1 node build.js", - "test": "BABEL_ENV=production npx mocha tests/*.test.mjs --require @babel/register", - "vbuild": "VERBOSE=1 node build.js" - }, - "dependencies": { - "@freesewing/core": "{{ tag }}", - "@freesewing/bent": "{{ tag }}" - }, - "devDependencies": { - "@freesewing/plugin-svgattr": "{{ tag }}", - "@freesewing/plugin-theme": "{{ tag }}", - "@freesewing/plugin-i18n": "{{ tag }}", - "@freesewing/models": "{{ tag }}", - "@headlessui/react": "^1.6.5", - "js-yaml": "^4.1.0", - "file-saver": "^2.0.5", - "axios": "^0.27.2", - "pdfkit": "^0.13.0", - "svg-to-pdfkit": "^0.1.8", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "react-sizeme": "^3.0.2", - "react-zoom-pan-pinch": "^2.1.3", - "react-markdown": "^8.0.3", - "roughjs": "^4.5.2", - "@tailwindcss/typography": "^0.5.2", - "d3-dispatch": "^3.0.1", - "d3-drag": "^3.0.0", - "d3-selection": "^3.0.0", - "daisyui": "^2.0.6", - "lodash.get": "^4.4.2", - "lodash.orderby": "^4.6.0", - "lodash.set": "^4.3.2", - "lodash.unset": "^4.5.2", - "lodash.clonedeep": "^4.5.0", - "next": "latest", - "next-i18next": "^11.0.0", - "react-copy-to-clipboard": "^5.0.4", - "react-hotkeys-hook": "^3.4.4", - "react-swipeable": "^6.2.0", - "react-timeago": "^6.2.1", - "mocha": "^9.1.1", - "chai": "^4.2.0", - "autoprefixer": "^10.4.0", - "eslint-config-next": "12.1.6", - "highlight.js": "^11.5.1", - "js-yaml": "^4.1.0", - "postcss": "^8.4.14", - "postcss-for": "^2.1.1", - "tailwindcss": "^3.1.3", - "tailwindcss-open-variant": "^1.0.0", - "web-worker": "^1.2.0" - }, - "files": [ - "dist/*", - "README.md", - "package.json" - ], - "publishConfig": { - "access": "public", - "tag": "next" - }, - "engines": { - "node": ">=14.0.0", - "npm": ">=6" - } -} diff --git a/packages/new-design/templates/from-breanna/package.json.mustache b/packages/new-design/templates/from-breanna/package.json.mustache deleted file mode 100644 index c59ca3f48bb..00000000000 --- a/packages/new-design/templates/from-breanna/package.json.mustache +++ /dev/null @@ -1,97 +0,0 @@ -{ - "name": "@freesewing/{{name}}", - "version": "0.0.1", - "description": "A new FreeSewing design", - "author": "Joost De Cock (https://github.com/joostdecock)", - "homepage": "https://freesewing.org/", - "repository": "github:freesewing/freesewing", - "license": "MIT", - "bugs": { - "url": "https://github.com/freesewing/freesewing/issues" - }, - "funding": { - "type": "individual", - "url": "https://freesewing.org/patrons/join" - }, - "keywords": [ - "freesewing", - "design", - "diy", - "fashion", - "parametric design", - "sewing", - "sewing pattern" - ], - "main": "dist/index.js", - "module": "dist/index.mjs", - "scripts": { - "dev": "node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", - "build": "node build.js", - "clean": "rimraf dist", - "mbuild": "NO_MINIFY=1 node build.js", - "test": "BABEL_ENV=production npx mocha tests/*.test.mjs --require @babel/register", - "vbuild": "VERBOSE=1 node build.js" - }, - "dependencies": { - "@freesewing/core": "{{ tag }}", - "@freesewing/breanna": "{{ tag }}" - }, - "devDependencies": { - "@freesewing/plugin-svgattr": "{{ tag }}", - "@freesewing/plugin-theme": "{{ tag }}", - "@freesewing/plugin-i18n": "{{ tag }}", - "@freesewing/models": "{{ tag }}", - "@headlessui/react": "^1.6.5", - "js-yaml": "^4.1.0", - "file-saver": "^2.0.5", - "axios": "^0.27.2", - "pdfkit": "^0.13.0", - "svg-to-pdfkit": "^0.1.8", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "react-sizeme": "^3.0.2", - "react-zoom-pan-pinch": "^2.1.3", - "react-markdown": "^8.0.3", - "roughjs": "^4.5.2", - "@tailwindcss/typography": "^0.5.2", - "d3-dispatch": "^3.0.1", - "d3-drag": "^3.0.0", - "d3-selection": "^3.0.0", - "daisyui": "^2.0.6", - "lodash.get": "^4.4.2", - "lodash.orderby": "^4.6.0", - "lodash.set": "^4.3.2", - "lodash.unset": "^4.5.2", - "lodash.clonedeep": "^4.5.0", - "next": "latest", - "next-i18next": "^11.0.0", - "react-copy-to-clipboard": "^5.0.4", - "react-hotkeys-hook": "^3.4.4", - "react-swipeable": "^6.2.0", - "react-timeago": "^6.2.1", - "mocha": "^9.1.1", - "chai": "^4.2.0", - "autoprefixer": "^10.4.0", - "eslint-config-next": "12.1.6", - "highlight.js": "^11.5.1", - "js-yaml": "^4.1.0", - "postcss": "^8.4.14", - "postcss-for": "^2.1.1", - "tailwindcss": "^3.1.3", - "tailwindcss-open-variant": "^1.0.0", - "web-worker": "^1.2.0" - }, - "files": [ - "dist/*", - "README.md", - "package.json" - ], - "publishConfig": { - "access": "public", - "tag": "next" - }, - "engines": { - "node": ">=14.0.0", - "npm": ">=6" - } -} diff --git a/packages/new-design/templates/from-brian/package.json.mustache b/packages/new-design/templates/from-brian/package.json.mustache deleted file mode 100644 index 24a355e7f7a..00000000000 --- a/packages/new-design/templates/from-brian/package.json.mustache +++ /dev/null @@ -1,96 +0,0 @@ -{ - "name": "@freesewing/{{name}}", - "version": "0.0.1", - "description": "A new FreeSewing design", - "author": "Joost De Cock (https://github.com/joostdecock)", - "homepage": "https://freesewing.org/", - "repository": "github:freesewing/freesewing", - "license": "MIT", - "bugs": { - "url": "https://github.com/freesewing/freesewing/issues" - }, - "funding": { - "type": "individual", - "url": "https://freesewing.org/patrons/join" - }, - "keywords": [ - "freesewing", - "design", - "diy", - "fashion", - "parametric design", - "sewing", - "sewing pattern" - ], - "main": "dist/index.js", - "module": "dist/index.mjs", - "scripts": { - "dev": "node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", - "build": "node build.js", - "clean": "rimraf dist", - "mbuild": "NO_MINIFY=1 node build.js", - "test": "BABEL_ENV=production npx mocha tests/*.test.mjs --require @babel/register", - "vbuild": "VERBOSE=1 node build.js" - }, - "dependencies": { - "@freesewing/core": "{{ tag }}", - "@freesewing/brian": "{{ tag }}" - }, - "devDependencies": { - "@freesewing/plugin-svgattr": "{{ tag }}", - "@freesewing/plugin-theme": "{{ tag }}", - "@freesewing/plugin-i18n": "{{ tag }}", - "@freesewing/models": "{{ tag }}", - "@headlessui/react": "^1.6.5", - "js-yaml": "^4.1.0", - "file-saver": "^2.0.5", - "axios": "^0.27.2", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "react-sizeme": "^3.0.2", - "react-zoom-pan-pinch": "^2.1.3", - "react-markdown": "^8.0.3", - "@tailwindcss/typography": "^0.5.2", - "d3-dispatch": "^3.0.1", - "d3-drag": "^3.0.0", - "d3-selection": "^3.0.0", - "daisyui": "^2.0.6", - "lodash.get": "^4.4.2", - "lodash.orderby": "^4.6.0", - "lodash.set": "^4.3.2", - "lodash.unset": "^4.5.2", - "lodash.clonedeep": "^4.5.0", - "next": "latest", - "next-i18next": "^11.0.0", - "react-copy-to-clipboard": "^5.0.4", - "react-hotkeys-hook": "^3.4.4", - "react-swipeable": "^6.2.0", - "react-timeago": "^6.2.1", - "mocha": "^9.1.1", - "chai": "^4.2.0", - "autoprefixer": "^10.4.0", - "eslint-config-next": "12.1.6", - "highlight.js": "^11.5.1", - "js-yaml": "^4.1.0", - "pdfkit": "^0.13.0", - "svg-to-pdfkit": "^0.1.8", - "postcss-for": "^2.1.1", - "postcss": "^8.4.14", - "tailwindcss": "^3.1.3", - "tailwindcss-open-variant": "^1.0.0", - "web-worker": "^1.2.0" - }, - "files": [ - "dist/*", - "README.md", - "package.json" - ], - "publishConfig": { - "access": "public", - "tag": "next" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=6" - } -} diff --git a/packages/new-design/templates/from-scratch/package.json.mustache b/packages/new-design/templates/from-scratch/package.json.mustache deleted file mode 100644 index 1259c67e9fb..00000000000 --- a/packages/new-design/templates/from-scratch/package.json.mustache +++ /dev/null @@ -1,97 +0,0 @@ -{ - "name": "@freesewing/{{name}}", - "version": "0.0.1", - "description": "A new FreeSewing design", - "author": "Joost De Cock (https://github.com/joostdecock)", - "homepage": "https://freesewing.org/", - "repository": "github:freesewing/freesewing", - "license": "MIT", - "bugs": { - "url": "https://github.com/freesewing/freesewing/issues" - }, - "funding": { - "type": "individual", - "url": "https://freesewing.org/patrons/join" - }, - "keywords": [ - "freesewing", - "design", - "diy", - "fashion", - "parametric design", - "sewing", - "sewing pattern" - ], - "main": "dist/index.js", - "module": "dist/index.mjs", - "scripts": { - "dev": "node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", - "build": "node build.js", - "clean": "rimraf dist", - "mbuild": "NO_MINIFY=1 node build.js", - "test": "BABEL_ENV=production npx mocha tests/*.test.mjs --require @babel/register", - "vbuild": "VERBOSE=1 node build.js" - }, - "dependencies": { - "@freesewing/core": "{{ tag }}", - "@freesewing/plugin-bundle": "{{ tag }}" - }, - "devDependencies": { - "@freesewing/plugin-svgattr": "{{ tag }}", - "@freesewing/plugin-theme": "{{ tag }}", - "@freesewing/plugin-i18n": "{{ tag }}", - "@freesewing/models": "{{ tag }}", - "@headlessui/react": "^1.6.5", - "js-yaml": "^4.1.0", - "file-saver": "^2.0.5", - "axios": "^0.27.2", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "react-sizeme": "^3.0.2", - "react-zoom-pan-pinch": "^2.1.3", - "react-markdown": "^8.0.3", - "roughjs": "^4.5.2", - "@tailwindcss/typography": "^0.5.2", - "d3-dispatch": "^3.0.1", - "d3-drag": "^3.0.0", - "d3-selection": "^3.0.0", - "daisyui": "^2.0.6", - "lodash.get": "^4.4.2", - "lodash.orderby": "^4.6.0", - "lodash.set": "^4.3.2", - "lodash.unset": "^4.5.2", - "lodash.clonedeep": "^4.5.0", - "next": "latest", - "next-i18next": "^11.0.0", - "pdfkit": "^0.13.0", - "react-copy-to-clipboard": "^5.0.4", - "react-hotkeys-hook": "^3.4.4", - "react-swipeable": "^6.2.0", - "react-timeago": "^6.2.1", - "mocha": "^9.1.1", - "chai": "^4.2.0", - "autoprefixer": "^10.4.0", - "eslint-config-next": "12.1.6", - "highlight.js": "^11.5.1", - "js-yaml": "^4.1.0", - "postcss": "^8.4.14", - "postcss-for": "^2.1.1", - "svg-to-pdfkit": "^0.1.8", - "tailwindcss": "^3.1.3", - "tailwindcss-open-variant": "^1.0.0", - "web-worker": "^1.2.0" - }, - "files": [ - "dist/*", - "README.md", - "package.json" - ], - "publishConfig": { - "access": "public", - "tag": "next" - }, - "engines": { - "node": ">=14.0.0", - "npm": ">=6" - } -} diff --git a/packages/new-design/templates/from-titan/package.json.mustache b/packages/new-design/templates/from-titan/package.json.mustache deleted file mode 100644 index 9733a347482..00000000000 --- a/packages/new-design/templates/from-titan/package.json.mustache +++ /dev/null @@ -1,97 +0,0 @@ -{ - "name": "@freesewing/{{name}}", - "version": "0.0.1", - "description": "A new FreeSewing design", - "author": "Joost De Cock (https://github.com/joostdecock)", - "homepage": "https://freesewing.org/", - "repository": "github:freesewing/freesewing", - "license": "MIT", - "bugs": { - "url": "https://github.com/freesewing/freesewing/issues" - }, - "funding": { - "type": "individual", - "url": "https://freesewing.org/patrons/join" - }, - "keywords": [ - "freesewing", - "design", - "diy", - "fashion", - "parametric design", - "sewing", - "sewing pattern" - ], - "main": "dist/index.js", - "module": "dist/index.mjs", - "scripts": { - "dev": "node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", - "build": "node build.js", - "clean": "rimraf dist", - "mbuild": "NO_MINIFY=1 node build.js", - "test": "BABEL_ENV=production npx mocha tests/*.test.mjs --require @babel/register", - "vbuild": "VERBOSE=1 node build.js" - }, - "dependencies": { - "@freesewing/core": "{{ tag }}", - "@freesewing/titan": "{{ tag }}" - }, - "devDependencies": { - "@freesewing/plugin-svgattr": "{{ tag }}", - "@freesewing/plugin-theme": "{{ tag }}", - "@freesewing/plugin-i18n": "{{ tag }}", - "@freesewing/models": "{{ tag }}", - "@headlessui/react": "^1.6.5", - "js-yaml": "^4.1.0", - "file-saver": "^2.0.5", - "axios": "^0.27.2", - "react": "^17.0.2", - "svg-to-pdfkit": "^0.1.8", - "react-dom": "^17.0.2", - "pdfkit": "^0.13.0", - "react-sizeme": "^3.0.2", - "react-zoom-pan-pinch": "^2.1.3", - "react-markdown": "^8.0.3", - "roughjs": "^4.5.2", - "@tailwindcss/typography": "^0.5.2", - "d3-dispatch": "^3.0.1", - "d3-drag": "^3.0.0", - "d3-selection": "^3.0.0", - "daisyui": "^2.0.6", - "lodash.get": "^4.4.2", - "lodash.orderby": "^4.6.0", - "lodash.set": "^4.3.2", - "lodash.unset": "^4.5.2", - "lodash.clonedeep": "^4.5.0", - "next": "latest", - "next-i18next": "^11.0.0", - "react-copy-to-clipboard": "^5.0.4", - "react-hotkeys-hook": "^3.4.4", - "react-swipeable": "^6.2.0", - "react-timeago": "^6.2.1", - "mocha": "^9.1.1", - "chai": "^4.2.0", - "autoprefixer": "^10.4.0", - "eslint-config-next": "12.1.6", - "highlight.js": "^11.5.1", - "js-yaml": "^4.1.0", - "postcss": "^8.4.14", - "postcss-for": "^2.1.1", - "tailwindcss": "^3.1.3", - "tailwindcss-open-variant": "^1.0.0", - "web-worker": "^1.2.0" - }, - "files": [ - "dist/*", - "README.md", - "package.json" - ], - "publishConfig": { - "access": "public", - "tag": "next" - }, - "engines": { - "node": ">=14.0.0", - "npm": ">=6" - } -} From f8b156d066b411fe3534b590cdc80ddfe7b30a4d Mon Sep 17 00:00:00 2001 From: Nikhil Chelliah Date: Fri, 14 Oct 2022 17:40:11 -0400 Subject: [PATCH 3/3] style(new-design): Export `$$Name$$` instead of `Pattern` --- packages/new-design/lib/utils.mjs | 2 ++ packages/new-design/package.json | 1 + .../pages/{design.mjs => design.mjs.mustache} | 10 ++++++++-- .../from-bella/design/src/index.mjs.mustache | 12 +++++++++--- .../from-bent/design/src/index.mjs.mustache | 12 +++++++++--- .../from-breanna/design/src/index.mjs.mustache | 12 +++++++++--- .../from-brian/design/src/index.mjs.mustache | 12 +++++++++--- .../from-scratch/design/src/index.mjs.mustache | 12 +++++++++--- .../from-titan/design/src/index.mjs.mustache | 12 +++++++++--- .../from-tutorial/design/src/bib.mjs.mustache | 3 +-- .../from-tutorial/design/src/index.mjs.mustache | 14 ++++++++++---- 11 files changed, 76 insertions(+), 26 deletions(-) rename packages/new-design/shared/pages/{design.mjs => design.mjs.mustache} (60%) diff --git a/packages/new-design/lib/utils.mjs b/packages/new-design/lib/utils.mjs index 56ccfeb6557..59b94514c6c 100644 --- a/packages/new-design/lib/utils.mjs +++ b/packages/new-design/lib/utils.mjs @@ -9,6 +9,7 @@ import { oraPromise } from 'ora' import { execa } from 'execa' import axios from 'axios' import { fileURLToPath } from 'url' +import { capitalize } from '@freesewing/core' // Current working directory let filename @@ -286,6 +287,7 @@ export const createEnvironment = async (choices) => { // Copy/Template files try { const templateVars = { + Name: capitalize(choices.name), name: choices.name, tag: config.tag, } diff --git a/packages/new-design/package.json b/packages/new-design/package.json index ede78e22ffd..82f9b1c977d 100644 --- a/packages/new-design/package.json +++ b/packages/new-design/package.json @@ -28,6 +28,7 @@ }, "peerDependencies": {}, "dependencies": { + "@freesewing/core": "^3.0.0-alpha.2", "axios": "^1.1.2", "chalk": "^5.0.1", "execa": "^6.1.0", diff --git a/packages/new-design/shared/pages/design.mjs b/packages/new-design/shared/pages/design.mjs.mustache similarity index 60% rename from packages/new-design/shared/pages/design.mjs rename to packages/new-design/shared/pages/design.mjs.mustache index efa2889a4f8..b9bc5a5f519 100644 --- a/packages/new-design/shared/pages/design.mjs +++ b/packages/new-design/shared/pages/design.mjs.mustache @@ -1,4 +1,10 @@ -import { Pattern } from 'design/src/index.mjs' +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + +import { $$Name$$ } from 'design/src/index.mjs' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import Page from 'site/components/wrappers/page.js' @@ -11,7 +17,7 @@ const WorkbenchPage = (props) => { return ( - + ) } diff --git a/packages/new-design/templates/from-bella/design/src/index.mjs.mustache b/packages/new-design/templates/from-bella/design/src/index.mjs.mustache index e628e6e7c1a..366a2f9db27 100644 --- a/packages/new-design/templates/from-bella/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-bella/design/src/index.mjs.mustache @@ -1,3 +1,9 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + // Import Design constructor import { Design } from '@freesewing/core' // Import parts @@ -5,7 +11,7 @@ import { back } from './back' import { front } from './front' // Create the new design -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { /* * If you like, you can add any data you want to your design. @@ -14,7 +20,7 @@ const Pattern = new Design({ * If you don't use this, * you can remove this data key enterely. */ - name: "{{ name }}", + name: "$$ name $$", }, // A list of parts is all that is required. parts: [ back, front ], @@ -26,5 +32,5 @@ const Pattern = new Design({ * We export the design itself as well as each part individually. * This allows us to re-use these parts in other designs. */ -export { back, front, Pattern } +export { back, front, $$Name$$ } diff --git a/packages/new-design/templates/from-bent/design/src/index.mjs.mustache b/packages/new-design/templates/from-bent/design/src/index.mjs.mustache index 59a30ada17f..0d877cda92c 100644 --- a/packages/new-design/templates/from-bent/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-bent/design/src/index.mjs.mustache @@ -1,3 +1,9 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + // Import Design constructor import { Design } from '@freesewing/core' // Import parts @@ -7,7 +13,7 @@ import { topSleeve } from './topsleeve.mjs' import { underSleeve } from './undersleeve.mjs' // Create the new design -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { /* * If you like, you can add any data you want to your design. @@ -16,7 +22,7 @@ const Pattern = new Design({ * If you don't use this, * you can remove this data key enterely. */ - name: "{{ name }}", + name: "$$ name $$", }, // A list of parts is all that is required. parts: [ back, front, topSleeve, underSleeve ], @@ -28,5 +34,5 @@ const Pattern = new Design({ * We export the design itself as well as each part individually. * This allows us to re-use these parts in other designs. */ -export { back, front, topSleeve, underSleeve, Pattern } +export { back, front, topSleeve, underSleeve, $$Name$$ } diff --git a/packages/new-design/templates/from-breanna/design/src/index.mjs.mustache b/packages/new-design/templates/from-breanna/design/src/index.mjs.mustache index 076a0a0a6d0..96319916723 100644 --- a/packages/new-design/templates/from-breanna/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-breanna/design/src/index.mjs.mustache @@ -1,3 +1,9 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + // Import Design constructor import { Design } from '@freesewing/core' // Import parts @@ -6,7 +12,7 @@ import { front } from './front' import { sleeve } from './sleeve' // Create the new design -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { /* * If you like, you can add any data you want to your design. @@ -15,7 +21,7 @@ const Pattern = new Design({ * If you don't use this, * you can remove this data key enterely. */ - name: "{{ name }}", + name: "$$ name $$", }, // A list of parts is all that is required. parts: [ back, front, sleeve ], @@ -27,5 +33,5 @@ const Pattern = new Design({ * We export the design itself as well as each part individually. * This allows us to re-use these parts in other designs. */ -export { back, front, sleeve, Pattern } +export { back, front, sleeve, $$Name$$ } diff --git a/packages/new-design/templates/from-brian/design/src/index.mjs.mustache b/packages/new-design/templates/from-brian/design/src/index.mjs.mustache index 076a0a0a6d0..96319916723 100644 --- a/packages/new-design/templates/from-brian/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-brian/design/src/index.mjs.mustache @@ -1,3 +1,9 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + // Import Design constructor import { Design } from '@freesewing/core' // Import parts @@ -6,7 +12,7 @@ import { front } from './front' import { sleeve } from './sleeve' // Create the new design -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { /* * If you like, you can add any data you want to your design. @@ -15,7 +21,7 @@ const Pattern = new Design({ * If you don't use this, * you can remove this data key enterely. */ - name: "{{ name }}", + name: "$$ name $$", }, // A list of parts is all that is required. parts: [ back, front, sleeve ], @@ -27,5 +33,5 @@ const Pattern = new Design({ * We export the design itself as well as each part individually. * This allows us to re-use these parts in other designs. */ -export { back, front, sleeve, Pattern } +export { back, front, sleeve, $$Name$$ } diff --git a/packages/new-design/templates/from-scratch/design/src/index.mjs.mustache b/packages/new-design/templates/from-scratch/design/src/index.mjs.mustache index 28d42e17195..528d7061d38 100644 --- a/packages/new-design/templates/from-scratch/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-scratch/design/src/index.mjs.mustache @@ -1,10 +1,16 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + // Import Design constructor import { Design } from '@freesewing/core' // Import parts import { box } from './box.mjs' // Create the new design -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { /* * If you like, you can add any data you want to your design. @@ -13,7 +19,7 @@ const Pattern = new Design({ * If you don't use this, * you can remove this data key enterely. */ - name: "{{ name }}", + name: "$$ name $$", }, // A list of parts is all that is required. parts: [ box ], @@ -25,5 +31,5 @@ const Pattern = new Design({ * We export the design itself as well as each part individually. * This allows us to re-use these parts in other designs. */ -export { box, Pattern } +export { box, $$Name$$ } diff --git a/packages/new-design/templates/from-titan/design/src/index.mjs.mustache b/packages/new-design/templates/from-titan/design/src/index.mjs.mustache index e628e6e7c1a..366a2f9db27 100644 --- a/packages/new-design/templates/from-titan/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-titan/design/src/index.mjs.mustache @@ -1,3 +1,9 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + // Import Design constructor import { Design } from '@freesewing/core' // Import parts @@ -5,7 +11,7 @@ import { back } from './back' import { front } from './front' // Create the new design -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { /* * If you like, you can add any data you want to your design. @@ -14,7 +20,7 @@ const Pattern = new Design({ * If you don't use this, * you can remove this data key enterely. */ - name: "{{ name }}", + name: "$$ name $$", }, // A list of parts is all that is required. parts: [ back, front ], @@ -26,5 +32,5 @@ const Pattern = new Design({ * We export the design itself as well as each part individually. * This allows us to re-use these parts in other designs. */ -export { back, front, Pattern } +export { back, front, $$Name$$ } diff --git a/packages/new-design/templates/from-tutorial/design/src/bib.mjs.mustache b/packages/new-design/templates/from-tutorial/design/src/bib.mjs.mustache index b2c74ab7488..2af04e1e5cc 100644 --- a/packages/new-design/templates/from-tutorial/design/src/bib.mjs.mustache +++ b/packages/new-design/templates/from-tutorial/design/src/bib.mjs.mustache @@ -1,9 +1,8 @@ function draftBib({ part }) { - return part } export const bib = { - name: 'tutorial.bib', + name: '{{ name }}.bib', draft: draftBib, } diff --git a/packages/new-design/templates/from-tutorial/design/src/index.mjs.mustache b/packages/new-design/templates/from-tutorial/design/src/index.mjs.mustache index 3bada6576fd..9ff7c96a38b 100644 --- a/packages/new-design/templates/from-tutorial/design/src/index.mjs.mustache +++ b/packages/new-design/templates/from-tutorial/design/src/index.mjs.mustache @@ -1,12 +1,18 @@ +//{{! +// Change the Mustache delimiter from double curly braces to double dollar signs. +// Dollar signs are allowed in EcmaScript identifier names, +// which is helpful when running unrendered Mustache templates through eslint. +//}}{{=$$ $$=}} + import { Design } from '@freesewing/core' import { bib } from './bib.mjs' -const Pattern = new Design({ +const $$Name$$ = new Design({ data: { - version: "0.0.1", - name: "Tutorial", + version: '0.0.1', + name: '$$ name $$', }, parts: [ bib ], }) -export { bib, Pattern } +export { bib, $$Name$$ }