diff --git a/package.json b/package.json index c83b527c..7bcf3344 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "groom": "pnpm install && pnpm run format && pnpm run lint && pnpm run build:packages", "preinstall": "npx only-allow pnpm", "lint": "turbo run lint", - "new:package": "plop --plopfile scripts/plopfile.mjs", + "new:package": "plop --plopfile scripts/plopfile.mjs && pnpm run groom", "test": "pnpm run validate && pnpm run test:unit run", "test:unit": "vitest", "validate": "run-s check:*" @@ -48,7 +48,6 @@ "@testing-library/user-event": "^14.4.3", "@types/eslint": "^8.4.6", "@vitejs/plugin-react": "^2.1.0", - "chalk": "^5.1.0", "eslint": "^8.25.0", "eslint-config-luke-ui": "workspace:*", "jsdom": "^20.0.1", diff --git a/packages/button/index.js b/packages/button/index.js index 7bd4b6c7..bc44aa0c 100644 --- a/packages/button/index.js +++ b/packages/button/index.js @@ -1,7 +1,6 @@ 'use strict'; -if (process.env.NODE_ENV === 'production') { - module.exports = require('./dist/index.cjs.prod'); -} else { - module.exports = require('./dist/index.cjs.dev'); -} +module.exports = + process.env.NODE_ENV === 'production' + ? require('./dist/index.cjs.prod') + : require('./dist/index.cjs.dev'); diff --git a/plop-templates/component/LICENSE.hbs b/plop-templates/component/LICENSE similarity index 100% rename from plop-templates/component/LICENSE.hbs rename to plop-templates/component/LICENSE diff --git a/plop-templates/component/index.js b/plop-templates/component/index.js new file mode 100644 index 00000000..bc44aa0c --- /dev/null +++ b/plop-templates/component/index.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = + process.env.NODE_ENV === 'production' + ? require('./dist/index.cjs.prod') + : require('./dist/index.cjs.dev'); diff --git a/plop-templates/component/index.js.hbs b/plop-templates/component/index.js.hbs deleted file mode 100644 index 7bd4b6c7..00000000 --- a/plop-templates/component/index.js.hbs +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./dist/index.cjs.prod'); -} else { - module.exports = require('./dist/index.cjs.dev'); -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e0ba2cc..962a897b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,7 +12,6 @@ importers: '@testing-library/user-event': ^14.4.3 '@types/eslint': ^8.4.6 '@vitejs/plugin-react': ^2.1.0 - chalk: ^5.1.0 eslint: ^8.25.0 eslint-config-luke-ui: workspace:* jsdom: ^20.0.1 @@ -41,7 +40,6 @@ importers: '@testing-library/user-event': 14.4.3_znccgeejomvff3jrsk3ljovfpu '@types/eslint': 8.4.6 '@vitejs/plugin-react': 2.1.0_vite@3.1.6 - chalk: 5.1.0 eslint: 8.25.0 eslint-config-luke-ui: link:internal/eslint-config-luke-ui jsdom: 20.0.1 diff --git a/scripts/plopfile.mjs b/scripts/plopfile.mjs index eac077f0..17de8568 100644 --- a/scripts/plopfile.mjs +++ b/scripts/plopfile.mjs @@ -1,5 +1,3 @@ -import chalk from 'chalk'; - export default function newPackage( /** @type {import('plop').NodePlopAPI} */ plop @@ -34,54 +32,40 @@ export default function newPackage( actions: (answers) => { const actions = []; - if (!answers) return actions; + if (!answers) { + return actions; + } const { componentName, packageName } = answers; - actions.push({ - type: 'addMany', - templateFiles: '../plop-templates/component/**', - base: '../plop-templates/component/', - destination: `../packages/${packageName}`, - data: { componentName, packageName }, - }); - - actions.push({ - type: 'modify', - path: '../playroom/src/components.ts', - pattern: /\n/, - template: "\nexport * from '{{ packageScope }}/{{ packageName }}';\n", - }); - - actions.push({ - type: 'modify', - path: '../playroom/package.json', - pattern: /"dependencies": {/, - template: - '"dependencies": {\n"{{ packageScope }}/{{ packageName }}": "workspace:*",\n', - }); - - actions.push({ - type: 'modify', - path: '../docs/package.json', - pattern: /"dependencies": {/, - template: - '"dependencies": {\n"{{ packageScope }}/{{ packageName }}": "workspace:*",\n', - }); - - actions.push( - chalk.yellowBright.bold( - 'Please run the following to rename your license file:\n' - ) + - chalk( - `mv packages/${packageName}/LICENSE.hbs packages/${packageName}/LICENSE` - ) - ); - actions.push( - chalk.greenBright.bold( - 'Please run the following script to set up the new package:\n' - ) + chalk('pnpm run groom') + { + type: 'addMany', + templateFiles: '../plop-templates/component/**', + base: '../plop-templates/component/', + destination: `../packages/${packageName}`, + data: { componentName, packageName }, + }, + { + type: 'modify', + path: '../playroom/src/components.ts', + pattern: /\n/, + template: "\nexport * from '{{ packageScope }}/{{ packageName }}';\n", + }, + { + type: 'modify', + path: '../playroom/package.json', + pattern: /"dependencies": {/, + template: + '"dependencies": {\n"{{ packageScope }}/{{ packageName }}": "workspace:*",\n', + }, + { + type: 'modify', + path: '../docs/package.json', + pattern: /"dependencies": {/, + template: + '"dependencies": {\n"{{ packageScope }}/{{ packageName }}": "workspace:*",\n', + } ); return actions;