diff --git a/bin/generate.js b/bin/generate.js index 8d290531..33b23de1 100755 --- a/bin/generate.js +++ b/bin/generate.js @@ -24,21 +24,6 @@ const path = require('path'); const paths = require('../util/paths'); const log = require('../util/log'); -const getVersionData = async () => { - const latestVersion = require('latest-version'); - let versions = {}; - - versions['designTokens'] = await latestVersion('@alaskaairux/orion-design-tokens'); - versions['wcss'] = await latestVersion('@alaskaairux/orion-web-core-style-sheets'); - versions['icons'] = await latestVersion('@alaskaairux/orion-icons'); - versions['focusVisible'] = await latestVersion('focus-visible'); - versions['webcomponentsjs'] = await latestVersion('@webcomponents/webcomponentsjs'); - versions['litElement'] = await latestVersion('lit-element'); - versions['bableCore'] = await latestVersion('@babel/core'); - - return versions; -} - const lowerKebabCase = str => str.toLowerCase().replace(' ', '-'); const upperCamelCase = str => lowerKebabCase(str) @@ -99,7 +84,104 @@ const makeFolder = async dir => { } }; +const getVersionData = async () => { + const latestVersion = require('latest-version'); + let versions = {}; + + versions['designTokens'] = await latestVersion('@alaskaairux/orion-design-tokens'); + versions['wcss'] = await latestVersion('@alaskaairux/orion-web-core-style-sheets'); + versions['icons'] = await latestVersion('@alaskaairux/orion-icons'); + versions['focusVisible'] = await latestVersion('focus-visible'); + versions['webcomponentsjs'] = await latestVersion('@webcomponents/webcomponentsjs'); + versions['litElement'] = await latestVersion('lit-element'); + versions['bableCore'] = await latestVersion('@babel/core'); + versions['bableTransRuntime'] = await latestVersion('@babel/plugin-transform-runtime'); + versions['bablePreset'] = await latestVersion('@babel/preset-env'); + versions['bableRuntime'] = await latestVersion('@babel/runtime'); + versions['commitlintCli'] = await latestVersion('@commitlint/cli'); + versions['commitlintConfig'] = await latestVersion('@commitlint/config-conventional'); + versions['openwcTesting'] = await latestVersion('@open-wc/testing'); + versions['openwcKarma'] = await latestVersion('@open-wc/testing-karma'); + versions['srChangelog'] = await latestVersion('@semantic-release/changelog'); + versions['srGit'] = await latestVersion('@semantic-release/git'); + versions['srNpm'] = await latestVersion('@semantic-release/npm'); + versions['autoprefixer'] = await latestVersion('autoprefixer'); + versions['concat'] = await latestVersion('concat'); + versions['copyfiles'] = await latestVersion('copyfiles'); + versions['coreJs'] = await latestVersion('core-js'); + versions['eslint'] = await latestVersion('eslint'); + versions['eslintLit'] = await latestVersion('eslint-plugin-lit'); + versions['husky'] = await latestVersion('husky'); + versions['lodash'] = await latestVersion('lodash'); + versions['marked'] = await latestVersion('marked'); + versions['nodemon'] = await latestVersion('nodemon'); + versions['npmRunAll'] = await latestVersion('npm-run-all'); + versions['parcelBundler'] = await latestVersion('parcel-bundler'); + versions['parcelCompress'] = await latestVersion('parcel-plugin-compress'); + versions['postcss'] = await latestVersion('postcss'); + versions['postcssCustomProperties'] = await latestVersion('postcss-custom-properties'); + versions['postcssDiscardComments'] = await latestVersion('postcss-discard-comments'); + versions['postcssRemoveRules'] = await latestVersion('postcss-remove-rules'); + versions['postcssSelectorReplace'] = await latestVersion('postcss-selector-replace'); + versions['rollup'] = await latestVersion('rollup'); + versions['sr'] = await latestVersion('semantic-release'); + versions['sinon'] = await latestVersion('sinon'); + versions['stylelint'] = await latestVersion('stylelint'); + versions['stylelintConfig'] = await latestVersion('stylelint-config-standard'); + versions['wcSassRender'] = await latestVersion('wc-sass-render'); + versions['webpackMerge'] = await latestVersion('webpack-merge'); + versions['yamlLint'] = await latestVersion('yaml-lint'); + + return versions; +} + const formatTemplateFileContents = (data, content, { name, namespace, npm }) => { + const pkgReplacements = [ + { regex: /\[designTokens\]/g, value: data.designTokens }, + { regex: /\[wcss\]/g, value: data.wcss }, + { regex: /\[icons\]/g, value: data.icons }, + { regex: /\[focusVisible\]/g, value: data.focusVisible }, + { regex: /\[webcomponentsjs\]/g, value: data.webcomponentsjs }, + { regex: /\[litElement\]/g, value: data.litElement }, + { regex: /\[bableCore\]/g, value: data.bableCore }, + { regex: /\[bableTransRuntime\]/g, value: data.bableTransRuntime }, + { regex: /\[bablePreset\]/g, value: data.bablePreset }, + { regex: /\[bableRuntime\]/g, value: data.bableRuntime }, + { regex: /\[commitlintCli\]/g, value: data.commitlintCli }, + { regex: /\[commitlintConfig\]/g, value: data.commitlintConfig }, + { regex: /\[openwcTesting\]/g, value: data.openwcTesting }, + { regex: /\[openwcKarma\]/g, value: data.openwcKarma }, + { regex: /\[srChangelog\]/g, value: data.srChangelog }, + { regex: /\[srGit\]/g, value: data.srGit }, + { regex: /\[srNpm\]/g, value: data.srNpm }, + { regex: /\[autoprefixer\]/g, value: data.autoprefixer }, + { regex: /\[concat\]/g, value: data.concat }, + { regex: /\[copyfiles\]/g, value: data.copyfiles }, + { regex: /\[coreJs\]/g, value: data.coreJs }, + { regex: /\[eslint\]/g, value: data.eslint }, + { regex: /\[eslintLit\]/g, value: data.eslintLit }, + { regex: /\[husky\]/g, value: data.husky }, + { regex: /\[lodash\]/g, value: data.lodash }, + { regex: /\[marked\]/g, value: data.marked }, + { regex: /\[nodemon\]/g, value: data.nodemon }, + { regex: /\[npmRunAll\]/g, value: data.npmRunAll }, + { regex: /\[parcelBundler\]/g, value: data.parcelBundler }, + { regex: /\[parcelCompress\]/g, value: data.parcelCompress }, + { regex: /\[postcss\]/g, value: data.postcss }, + { regex: /\[postcssCustomProperties\]/g, value: data.postcssCustomProperties }, + { regex: /\[postcssDiscardComments\]/g, value: data.postcssDiscardComments }, + { regex: /\[postcssRemoveRules\]/g, value: data.postcssRemoveRules }, + { regex: /\[postcssSelectorReplace\]/g, value: data.postcssSelectorReplace }, + { regex: /\[rollup\]/g, value: data.rollup }, + { regex: /\[sr\]/g, value: data.sr }, + { regex: /\[sinon\]/g, value: data.sinon }, + { regex: /\[stylelint\]/g, value: data.stylelint }, + { regex: /\[stylelintConfig\]/g, value: data.stylelintConfig }, + { regex: /\[wcSassRender\]/g, value: data.wcSassRender }, + { regex: /\[webpackMerge\]/g, value: data.webpackMerge }, + { regex: /\[yamlLint\]/g, value: data.yamlLint } + ]; + // name to lower-kebab-case (e.g. Text Input -> text-input) const lowerKebabCaseName = lowerKebabCase(name); // namespace to lower-kebab-case (e.g. Text Input -> text-input) @@ -115,24 +197,19 @@ const formatTemplateFileContents = (data, content, { name, namespace, npm }) => // generate new year for copyright stamp const newYear = new Date().getFullYear(); - const replacements = [ + const nameReplacements = [ { regex: /\[author\]/g, value: userName }, { regex: /\[author-email\]/g, value: userEmail }, - { regex: /\[designTokens\]/g, value: data.designTokens }, - { regex: /\[focusVisible\]/g, value: data.focusVisible }, - { regex: /\[icons\]/g, value: data.icons }, - { regex: /\[litElement\]/g, value: data.litElement }, - { regex: /\[bableCore\]/g, value: data.bableCore }, { regex: /\[name\]/g, value: lowerKebabCaseName }, { regex: /\[namespace\]/g, value: lowerKebabCaseNameSpace }, { regex: /\[Namespace\]/g, value: upperCamelCaseNameSpace }, { regex: /\[Name\]/g, value: upperCamelCaseName }, { regex: /\[npm\]/g, value: npm }, - { regex: /\[webcomponentsjs\]/g, value: data.webcomponentsjs }, - { regex: /\[wcss\]/g, value: data.wcss }, { regex: /\[year\]/g, value: newYear }, ]; + const replacements = nameReplacements.concat(pkgReplacements); + // replace all instances of [name], [Name], [namespace] and [Namespace] accordingly let result = content; for (let i = 0; i < replacements.length; i++) { diff --git a/template/package.temp b/template/package.temp index 7663b2c4..a26b58a5 100644 --- a/template/package.temp +++ b/template/package.temp @@ -37,46 +37,46 @@ "@alaskaairux/orion-icons": "^[icons]", "@alaskaairux/orion-web-core-style-sheets": "^[wcss]", "@babel/core": "^[bableCore]", - "@babel/plugin-transform-runtime": "^7.9.0", - "@babel/preset-env": "^7.9.5", - "@babel/runtime": "^7.9.2", - "@commitlint/cli": "^8.3.5", - "@commitlint/config-conventional": "^8.3.4", - "@open-wc/testing": "^2.3.9", - "@open-wc/testing-karma": "^3.2.43", + "@babel/plugin-transform-runtime": "^[bableTransRuntime]", + "@babel/preset-env": "^[bablePreset]", + "@babel/runtime": "^[bableRuntime]", + "@commitlint/cli": "^[commitlintCli]", + "@commitlint/config-conventional": "^[commitlintConfig]", + "@open-wc/testing": "^[openwcTesting]", + "@open-wc/testing-karma": "^[openwcKarma]", "@polymer/iron-demo-helpers": "^3.1.0", "@polymer/iron-icons": "^3.0.1", "@polymer/polymer": "^3.2.0", - "@semantic-release/changelog": "^5.0.0", - "@semantic-release/git": "^9.0.0", - "@semantic-release/npm": "^7.0.3", + "@semantic-release/changelog": "^[srChangelog]", + "@semantic-release/git": "^[srGit]", + "@semantic-release/npm": "^[srNpm]", "@webcomponents/webcomponentsjs": "^[webcomponentsjs]", - "autoprefixer": "^9.6.0", - "concat": "^1.0.3", - "copyfiles": "^2.1.0", - "core-js": "^3.6.5", - "eslint": "^6.7.1", - "eslint-plugin-lit": "^1.2.0", + "autoprefixer": "^[autoprefixer]", + "concat": "^[concat]", + "copyfiles": "^[copyfiles]", + "core-js": "^[coreJs]", + "eslint": "^[eslint]", + "eslint-plugin-lit": "^[eslintLit]", "focus-visible": "^[focusVisible]", - "husky": "^4.2.3", - "lodash": "^4.17.11", - "marked": "^0.8.0", - "nodemon": "^2.0.2", - "npm-run-all": "^4.1.5", - "parcel-bundler": "^1.12.4", - "parcel-plugin-compress": "^1.1.0", - "postcss": "^7.0.17", - "postcss-custom-properties": "^9.1.1", - "postcss-discard-comments": "^4.0.2", - "postcss-remove-rules": "^1.0.0", - "postcss-selector-replace": "^1.0.2", - "rollup": "^1.31.1", - "semantic-release": "^17.0.4", - "sinon": "^9.0.0", - "stylelint": "^13.2.0", - "stylelint-config-standard": "^20.0.0", - "wc-sass-render": "^1.2.1", - "webpack-merge": "^4.2.2", + "husky": "^[husky]", + "lodash": "^[lodash]", + "marked": "^[marked]", + "nodemon": "^[nodemon]", + "npm-run-all": "^[npmRunAll]", + "parcel-bundler": "^[parcelBundler]", + "parcel-plugin-compress": "^[parcelCompress]", + "postcss": "^[postcss]", + "postcss-custom-properties": "^[postcssCustomProperties]", + "postcss-discard-comments": "^[postcssDiscardComments]", + "postcss-remove-rules": "^[postcssRemoveRules]", + "postcss-selector-replace": "^[postcssSelectorReplace]", + "rollup": "^[rollup]", + "semantic-release": "^[sr]", + "sinon": "^[sinon]", + "stylelint": "^[stylelint]", + "stylelint-config-standard": "^[stylelintConfig]", + "wc-sass-render": "^[wcSassRender]", + "webpack-merge": "^[webpackMerge]", "yaml-lint": "^1.2.4" }, "browserslist": [