From 379e351adb7757f4c7120518a0aa412428457a80 Mon Sep 17 00:00:00 2001 From: meshare <845545348@qq.com> Date: Fri, 12 Jul 2024 23:58:01 +0800 Subject: [PATCH] Format the generated code using prettier --- .browserslistrc | 4 ++ babel.config.js | 21 ++++--- bin/index.js | 8 +-- eslint.config.js | 6 +- package-lock.json | 135 ++++++++++++++++++++++++++++++++++-------- package.json | 7 ++- rollup.config.js | 64 ++------------------ src/cli/generate.ts | 22 +++---- src/cli/index.ts | 11 ++-- src/cli/parse.ts | 2 + test/command.spec.ts | 14 +---- test/generate.spec.ts | 34 ++++------- 12 files changed, 182 insertions(+), 146 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 1002e60..a909def 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -1,5 +1,9 @@ +[browser] > 0.5% last 2 versions Firefox ESR not ie < 11 not dead + +[node] +node >= 18.0 diff --git a/babel.config.js b/babel.config.js index 75967c9..0493bef 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,29 +1,34 @@ import pkg from './package.json' assert { type: 'json' }; export default { + browserslistEnv: 'browser', presets: [ - ['@babel/preset-env', { + [ '@babel/preset-env', { // debug: true, bugfixes: true, useBuiltIns: false }], - ['@babel/preset-typescript', { + [ '@babel/preset-typescript', { allowDeclareFields: true, optimizeConstEnums: true, onlyRemoveTypeImports: true }] ], plugins: [ - ['@babel/plugin-transform-runtime', { + [ '@babel/plugin-transform-runtime', { corejs: false, - version: pkg.devDependencies['@babel/runtime'] + version: pkg.dependencies['@babel/runtime'] }], - ['babel-plugin-polyfill-corejs3', { + [ 'babel-plugin-polyfill-corejs3', { // debug: true, - exclude: [ 'es.array.push', 'es.array.unshift' ], + // exclude: [ 'es.array.push', 'es.array.unshift' ], method: 'usage-pure', - version: pkg.devDependencies['core-js-pure'], + version: pkg.dependencies['core-js-pure'], proposals: true }] - ] + ], + overrides: [{ + test: 'src/cli/**/*', + browserslistEnv: 'node' + }] }; diff --git a/bin/index.js b/bin/index.js index 29d44b5..a6328a0 100644 --- a/bin/index.js +++ b/bin/index.js @@ -1,13 +1,13 @@ #!/usr/bin/env node -const { exit } = require('node:process') - , chalk = require('chalk') - , command = require('../dist/cli/command'); +import process from 'node:process'; +import chalk from 'chalk'; +import command from '../dist/cli/command.js'; (async () => { try { await command(process.argv); } catch (e) { console.log(chalk.red.bold(`j-icon-cli: ${e}`)); - exit(1); + process.exit(1); } })(); diff --git a/eslint.config.js b/eslint.config.js index ce3349b..fcbf16e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,7 @@ import jslint from '@eslint/js'; import tslint from 'typescript-eslint'; import stylistic from '@stylistic/eslint-plugin'; +import globals from 'globals'; export default [ jslint.configs.recommended, @@ -19,7 +20,10 @@ export default [ 'node_modules/**', 'dist/**', 'test/template/**' - ] + ], + languageOptions: { + globals: { ...globals.browser, ...globals.nodeBuiltin } + } }, { rules: { diff --git a/package-lock.json b/package-lock.json index 6c23d67..ad40815 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,21 @@ { "name": "@tomoeed/j-icon", - "version": "4.0.2", + "version": "4.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tomoeed/j-icon", - "version": "4.0.2", + "version": "4.0.3", "license": "Apache-2.0", "dependencies": { + "@babel/runtime": "^7.24.7", "camelcase": "^8.0.0", "chalk": "^5.3.0", "commander": "^12.1.0", + "core-js-pure": "^3.37.1", "happy-dom": "^14.12.3", - "js-beautify": "^1.15.1", + "prettier": "^3.3.2", "svgo": "^3.3.2", "type-fest": "^4.20.1" }, @@ -25,7 +27,6 @@ "@babel/plugin-transform-runtime": "^7.24.7", "@babel/preset-env": "^7.24.7", "@babel/preset-typescript": "^7.24.7", - "@babel/runtime": "^7.24.7", "@eslint/js": "^8.57.0", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^26.0.1", @@ -39,8 +40,8 @@ "@vitest/coverage-v8": "^1.6.0", "@vue/test-utils": "^2.4.6", "babel-plugin-polyfill-corejs3": "^0.10.4", - "core-js-pure": "^3.37.1", "eslint": "^8.57.0", + "globals": "^15.8.0", "jsdom": "^24.1.0", "rimraf": "^5.0.7", "rollup": "^4.18.0", @@ -1023,6 +1024,15 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-classes/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/plugin-transform-computed-properties": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.24.7.tgz", @@ -1835,7 +1845,6 @@ "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.7.tgz", "integrity": "sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw==", - "dev": true, "dependencies": { "regenerator-runtime": "^0.14.0" }, @@ -1878,6 +1887,15 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/types": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.7.tgz", @@ -2473,6 +2491,7 @@ "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", @@ -2489,6 +2508,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { "node": ">=12" }, @@ -2500,6 +2520,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -2627,12 +2648,14 @@ "node_modules/@one-ini/wasm": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@one-ini/wasm/-/wasm-0.1.1.tgz", - "integrity": "sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==" + "integrity": "sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==", + "dev": true }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, "optional": true, "engines": { "node": ">=14" @@ -3624,6 +3647,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz", "integrity": "sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ==", + "dev": true, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } @@ -3693,6 +3717,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { "node": ">=8" } @@ -3781,7 +3806,8 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "node_modules/boolbase": { "version": "1.0.0", @@ -3792,6 +3818,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, "dependencies": { "balanced-match": "^1.0.0" } @@ -4005,6 +4032,7 @@ "version": "1.1.13", "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", "integrity": "sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==", + "dev": true, "dependencies": { "ini": "^1.3.4", "proto-list": "~1.2.1" @@ -4033,7 +4061,6 @@ "version": "3.37.1", "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.37.1.tgz", "integrity": "sha512-J/r5JTHSmzTxbiYYrzXg9w1VpqrYt+gexenBE9pugeyhwPZTAEJddyiReJWsLO6uNQ8xJZFbod6XC7KKwatCiA==", - "dev": true, "hasInstallScript": true, "funding": { "type": "opencollective", @@ -4044,6 +4071,7 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -4313,12 +4341,14 @@ "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", - "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true }, "node_modules/editorconfig": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-1.0.4.tgz", "integrity": "sha512-L9Qe08KWTlqYMVvMcTIvMAdl1cDUubzRNYL+WfA4bLDMHe4nemKkpmYzkznE1FwLKu0EEmy6obgQKzMJrg4x9Q==", + "dev": true, "dependencies": { "@one-ini/wasm": "0.1.1", "commander": "^10.0.0", @@ -4336,6 +4366,7 @@ "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", + "dev": true, "engines": { "node": ">=14" } @@ -4344,6 +4375,7 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.1.tgz", "integrity": "sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==", + "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, @@ -4358,6 +4390,7 @@ "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "dev": true, "bin": { "semver": "bin/semver.js" }, @@ -4374,7 +4407,8 @@ "node_modules/emoji-regex": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", - "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==" + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true }, "node_modules/entities": { "version": "4.5.0", @@ -4922,6 +4956,7 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.2.1.tgz", "integrity": "sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA==", + "dev": true, "dependencies": { "cross-spawn": "^7.0.0", "signal-exit": "^4.0.1" @@ -5010,6 +5045,7 @@ "version": "10.4.2", "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.2.tgz", "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "dev": true, "dependencies": { "foreground-child": "^3.1.0", "jackspeak": "^3.1.2", @@ -5041,12 +5077,15 @@ } }, "node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "version": "15.8.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.8.0.tgz", + "integrity": "sha512-VZAJ4cewHTExBWDHR6yptdIBlx9YSSZuwojj9Nt5mBRXQzrKakDsVKQ1J63sklLvzAJm0X5+RpO4i3Y2hcOnFw==", "dev": true, "engines": { - "node": ">=4" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/globby": { @@ -5228,7 +5267,8 @@ "node_modules/ini": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "dev": true }, "node_modules/is-builtin-module": { "version": "3.2.1", @@ -5273,6 +5313,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, "engines": { "node": ">=8" } @@ -5343,7 +5384,8 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true }, "node_modules/istanbul-lib-coverage": { "version": "3.2.2", @@ -5399,6 +5441,7 @@ "version": "3.4.0", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.0.tgz", "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", + "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -5416,6 +5459,7 @@ "version": "1.15.1", "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.15.1.tgz", "integrity": "sha512-ESjNzSlt/sWE8sciZH8kBF8BPlwXPwhR6pWKAw8bw4Bwj+iZcnKW6ONWUutJ7eObuBZQpiIb8S7OYspWrKt7rA==", + "dev": true, "dependencies": { "config-chain": "^1.1.13", "editorconfig": "^1.0.4", @@ -5436,6 +5480,7 @@ "version": "3.0.5", "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "dev": true, "engines": { "node": ">=14" } @@ -5749,6 +5794,7 @@ "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, @@ -5763,6 +5809,7 @@ "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dev": true, "engines": { "node": ">=16 || 14 >=14.17" } @@ -5819,6 +5866,7 @@ "version": "7.2.1", "resolved": "https://registry.npmjs.org/nopt/-/nopt-7.2.1.tgz", "integrity": "sha512-taM24ViiimT/XntxbPyJQzCG+p4EKOpgD3mxFwW38mGjVUrfERQOeY4EDHjdnptttfHuHQXFx+lTP08Q+mLa/w==", + "dev": true, "dependencies": { "abbrev": "^2.0.0" }, @@ -5947,7 +5995,8 @@ "node_modules/package-json-from-dist": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz", - "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==" + "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==", + "dev": true }, "node_modules/parent-module": { "version": "1.0.1", @@ -5995,6 +6044,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, "engines": { "node": ">=8" } @@ -6009,6 +6059,7 @@ "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" @@ -6024,6 +6075,7 @@ "version": "10.2.2", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", + "dev": true, "engines": { "node": "14 || >=16.14" } @@ -6117,6 +6169,20 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz", + "integrity": "sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -6134,7 +6200,8 @@ "node_modules/proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", - "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==" + "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==", + "dev": true }, "node_modules/psl": { "version": "1.9.0", @@ -6213,8 +6280,7 @@ "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", - "dev": true + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==" }, "node_modules/regenerator-transform": { "version": "0.15.2", @@ -6447,6 +6513,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, @@ -6458,6 +6525,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, "engines": { "node": ">=8" } @@ -6472,6 +6540,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, "engines": { "node": ">=14" }, @@ -6537,6 +6606,7 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", @@ -6554,6 +6624,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -6566,12 +6637,14 @@ "node_modules/string-width-cjs/node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true }, "node_modules/string-width/node_modules/ansi-regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { "node": ">=12" }, @@ -6583,6 +6656,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -6597,6 +6671,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -6609,6 +6684,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -7304,6 +7380,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "dependencies": { "isexe": "^2.0.0" }, @@ -7343,6 +7420,7 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, "dependencies": { "ansi-styles": "^6.1.0", "string-width": "^5.0.1", @@ -7360,6 +7438,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -7376,6 +7455,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -7390,6 +7470,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -7400,17 +7481,20 @@ "node_modules/wrap-ansi-cjs/node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "node_modules/wrap-ansi-cjs/node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true }, "node_modules/wrap-ansi-cjs/node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -7424,6 +7508,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { "node": ">=12" }, @@ -7435,6 +7520,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, "engines": { "node": ">=12" }, @@ -7446,6 +7532,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, diff --git a/package.json b/package.json index 92041ea..705323d 100644 --- a/package.json +++ b/package.json @@ -58,11 +58,13 @@ "vue": "3.x" }, "dependencies": { + "@babel/runtime": "^7.24.7", "camelcase": "^8.0.0", "chalk": "^5.3.0", "commander": "^12.1.0", + "core-js-pure": "^3.37.1", "happy-dom": "^14.12.3", - "js-beautify": "^1.15.1", + "prettier": "^3.3.2", "svgo": "^3.3.2", "type-fest": "^4.20.1" }, @@ -71,7 +73,6 @@ "@babel/plugin-transform-runtime": "^7.24.7", "@babel/preset-env": "^7.24.7", "@babel/preset-typescript": "^7.24.7", - "@babel/runtime": "^7.24.7", "@eslint/js": "^8.57.0", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^26.0.1", @@ -85,8 +86,8 @@ "@vitest/coverage-v8": "^1.6.0", "@vue/test-utils": "^2.4.6", "babel-plugin-polyfill-corejs3": "^0.10.4", - "core-js-pure": "^3.37.1", "eslint": "^8.57.0", + "globals": "^15.8.0", "jsdom": "^24.1.0", "rimraf": "^5.0.7", "rollup": "^4.18.0", diff --git a/rollup.config.js b/rollup.config.js index d12f049..d756881 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,24 +9,10 @@ export default defineConfig([ { input: 'src/component/index.ts', output: [ - { - file: 'dist/component/index.esm.js', - format: 'module', - sourcemap: true - }, { file: 'dist/component/index.esm.min.js', format: 'module', - sourcemap: true, - plugins: [ terser() ] - }, - { - name: 'JIcon', - file: 'dist/component/index.umd.js', - exports: 'named', - format: 'umd', - sourcemap: true, - globals: { vue: 'Vue' } + sourcemap: true }, { name: 'JIcon', @@ -34,8 +20,7 @@ export default defineConfig([ exports: 'named', format: 'umd', sourcemap: true, - globals: { vue: 'Vue' }, - plugins: [ terser() ] + globals: { vue: 'Vue' } } ], external: [ 'vue' ], @@ -43,41 +28,6 @@ export default defineConfig([ nodeResolve(), commonjs(), typescript({ noForceEmit: true, tsconfig: 'src/component/tsconfig.json' }), - babel({ - exclude: 'node_modules/**', - babelHelpers: 'runtime', - extensions: [ '.js', '.ts', '.cjs', '.mjs' ] - }) - ] - }, - { - input: 'src/cli/parse.ts', - output: [ - { - file: 'dist/cli/parse.js', - format: 'commonjs', - sourcemap: true, - exports: 'auto' - }, - { - file: 'dist/cli/parse.esm.js', - format: 'esm', - sourcemap: true - } - ], - external: [ - 'node:fs', - 'node:path', - 'camelcase', - 'happy-dom', - 'svgo', - 'js-beautify', - 'chalk' - ], - plugins: [ - nodeResolve(), - commonjs(), - typescript({ noForceEmit: true, tsconfig: 'src/cli/tsconfig.json' }), babel({ exclude: 'node_modules/**', babelHelpers: 'runtime', @@ -90,18 +40,16 @@ export default defineConfig([ input: 'src/cli/index.ts', output: { file: 'dist/cli/command.js', - format: 'commonjs', + format: 'module', sourcemap: true }, external: [ - 'node:fs', - 'node:path', - 'node:url', - 'node:process', + /node:/, + /core-js-pure/, 'camelcase', 'happy-dom', 'svgo', - 'js-beautify', + 'prettier', 'chalk', 'commander' ], diff --git a/src/cli/generate.ts b/src/cli/generate.ts index 60deed4..37f5bd3 100644 --- a/src/cli/generate.ts +++ b/src/cli/generate.ts @@ -1,4 +1,5 @@ -import { js_beautify } from 'js-beautify'; +import { format as prettierFormat } from 'prettier'; +import type { Options } from 'prettier'; import camelcase from 'camelcase'; import type { SVGElement } from './parse'; @@ -152,9 +153,9 @@ export { `; } -function generate(elements: Map, format: Format): string { +function generate(elements: Map, format: Format): Promise { if (format === Format.DECLARE) { - return generateDeclare(elements); + return Promise.resolve(generateDeclare(elements)); } let code: string; @@ -164,13 +165,14 @@ function generate(elements: Map, format: Format): string { code = generateEcmaModule(elements, format); } - return js_beautify(code, { - indent_char: ' ', - indent_size: 4, - indent_with_tabs: false, - eol: '\n', - end_with_newline: true - }); + const option: Options = { + tabWidth: 4, + singleQuote: true, + trailingComma: 'none', + parser: format === Format.TYPESCRIPT ? 'typescript' : 'babel' + }; + + return prettierFormat(code, option); } export default generate; diff --git a/src/cli/index.ts b/src/cli/index.ts index 9687776..cbefc30 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,4 +1,3 @@ -// import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import FS from 'node:fs'; import { fileURLToPath } from 'node:url'; import { resolve, dirname } from 'node:path'; @@ -19,7 +18,7 @@ type OptionValue = { const pkg = JSON.parse(FS.readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json'), 'utf8')) , formatOptionalValues = [ 'esm', 'umd', 'ts', 'type' ]; -function commandAction(options: OptionValue, command: Command): Promise { +async function commandAction(options: OptionValue, command: Command): Promise { const formats = options.format .filter((value, index, self) => self.indexOf(value) === index) .filter(value => formatOptionalValues.includes(value)); @@ -39,16 +38,16 @@ function commandAction(options: OptionValue, command: Command): Promise { for (const format of formats) { switch (format) { case 'umd': - codes.set(`${options.name}.umd.js`, generate(elements, Format.UNIVERSAL_MODULE)); + codes.set(`${options.name}.umd.js`, await generate(elements, Format.UNIVERSAL_MODULE)); break; case 'esm': - codes.set(`${options.name}.esm.js`, generate(elements, Format.ECMA_SCRIPT_MODULE)); + codes.set(`${options.name}.esm.js`, await generate(elements, Format.ECMA_SCRIPT_MODULE)); break; case 'ts': - codes.set(`${options.name}.ts`, generate(elements, Format.TYPESCRIPT)); + codes.set(`${options.name}.ts`, await generate(elements, Format.TYPESCRIPT)); break; case 'type': - codes.set(`${options.name}.d.ts`, generate(elements, Format.DECLARE)); + codes.set(`${options.name}.d.ts`, await generate(elements, Format.DECLARE)); break; } } diff --git a/src/cli/parse.ts b/src/cli/parse.ts index bebd12f..c8231f2 100644 --- a/src/cli/parse.ts +++ b/src/cli/parse.ts @@ -34,6 +34,8 @@ function loadFile(path: string): string[] { function fun(path: string): void { const status = lstatSync(path); if (status.isFile()) { + const { ext } = pathParse(path); + if (ext !== '.svg') return; files.push(path); } diff --git a/test/command.spec.ts b/test/command.spec.ts index bfd59cc..1aed34f 100644 --- a/test/command.spec.ts +++ b/test/command.spec.ts @@ -4,8 +4,7 @@ import { cwd } from 'node:process'; import { fileURLToPath } from 'node:url'; import { describe, it, vitest, expect } from 'vitest'; import command from '../src/cli/index'; -import { js_beautify } from 'js-beautify'; -import type { JSBeautifyOptions } from 'js-beautify'; +import { format as prettierFormat } from 'prettier'; vitest.mock('svgo', async importOriginal => { return { @@ -17,14 +16,7 @@ vitest.mock('svgo', async importOriginal => { }; }); -const __dirname = dirname(fileURLToPath(import.meta.url)) - , jsBeautifyOption: JSBeautifyOptions = { - indent_char: ' ', - indent_size: 4, - indent_with_tabs: false, - eol: '\n', - end_with_newline: true - }; +const __dirname = dirname(fileURLToPath(import.meta.url)); describe('j-icon cli command', () => { it.each([ @@ -158,6 +150,6 @@ describe('j-icon cli command', () => { expect(mkdirSync).toHaveBeenCalled(); expect(writeFileSync).toHaveBeenCalledTimes(1); expect(paths).toEqual(expect.arrayContaining([ resolve(cwd(), 'test/generated/index.esm.js') ])); - expect(codes).toEqual(expect.arrayContaining([ js_beautify(template, jsBeautifyOption) ])); + expect(codes).toEqual(expect.arrayContaining([ await prettierFormat(template, { tabWidth: 4, singleQuote: true, trailingComma: 'none', parser: 'babel' }) ])); }); }); diff --git a/test/generate.spec.ts b/test/generate.spec.ts index 50fe07e..c53e281 100644 --- a/test/generate.spec.ts +++ b/test/generate.spec.ts @@ -4,8 +4,7 @@ import { fileURLToPath } from 'node:url'; import { describe, expect, it, vitest } from 'vitest'; import parse from '../src/cli/parse'; import generate, { Format } from '../src/cli/generate'; -import type { JSBeautifyOptions } from 'js-beautify'; -import { js_beautify } from 'js-beautify'; +import { format as prettierFormat } from 'prettier'; vitest.mock('svgo', async importOriginal => { return { @@ -18,36 +17,29 @@ vitest.mock('svgo', async importOriginal => { }); const __dirname = dirname(fileURLToPath(import.meta.url)) - , elements = new Map(Array.from(parse(resolve(__dirname, 'asset')).entries()).sort(([ a ], [ b ]) => a.localeCompare(b))) - , jsBeautifyOption: JSBeautifyOptions = { - indent_char: ' ', - indent_size: 4, - indent_with_tabs: false, - eol: '\n', - end_with_newline: true - }; + , elements = new Map(Array.from(parse(resolve(__dirname, 'asset')).entries()).sort(([ a ], [ b ]) => a.localeCompare(b))); describe('j-icon cli generate', () => { - it('generate esm code', () => { - const code = generate(elements, Format.ECMA_SCRIPT_MODULE) + it('generate esm code', async () => { + const code = await generate(elements, Format.ECMA_SCRIPT_MODULE) , template = readFileSync(resolve(__dirname, 'template', 'index.esm.js'), 'utf8'); - expect(code).toBe(js_beautify(template, jsBeautifyOption)); + expect(code).toBe(await prettierFormat(template, { tabWidth: 4, singleQuote: true, trailingComma: 'none', parser: 'babel' })); }); - it('generate umd code', () => { - const code = generate(elements, Format.UNIVERSAL_MODULE) + it('generate umd code', async () => { + const code = await generate(elements, Format.UNIVERSAL_MODULE) , template = readFileSync(resolve(__dirname, 'template', 'index.umd.js'), 'utf8'); - expect(code).toBe(js_beautify(template, jsBeautifyOption)); + expect(code).toBe(await prettierFormat(template, { tabWidth: 4, singleQuote: true, trailingComma: 'none', parser: 'babel' })); }); - it('generate ts code', () => { - const code = generate(elements, Format.TYPESCRIPT) + it('generate ts code', async () => { + const code = await generate(elements, Format.TYPESCRIPT) , template = readFileSync(resolve(__dirname, 'template', 'index.ts'), 'utf8'); - expect(code).toBe(js_beautify(template, jsBeautifyOption)); + expect(code).toBe(await prettierFormat(template, { tabWidth: 4, singleQuote: true, trailingComma: 'none', parser: 'typescript' })); }); - it('generate declare code', () => { - const code = generate(elements, Format.DECLARE) + it('generate declare code', async () => { + const code = await generate(elements, Format.DECLARE) , template = readFileSync(resolve(__dirname, 'template', 'index.d.ts'), 'utf8'); expect(code).toBe(template); });