From 0db56dfb54fe3f6dd233643a4d9f3b3557fbfd1e Mon Sep 17 00:00:00 2001 From: jorenbroekema Date: Tue, 17 Dec 2024 11:01:34 +0100 Subject: [PATCH] fix: cli --platform flag --- .changeset/strange-bananas-switch.md | 5 ++++ bin/style-dictionary.js | 38 ++++++++++++++++++++++++---- package-lock.json | 21 +++++++++++---- package.json | 2 +- tsconfig.json | 2 +- 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 .changeset/strange-bananas-switch.md diff --git a/.changeset/strange-bananas-switch.md b/.changeset/strange-bananas-switch.md new file mode 100644 index 000000000..84d4d7838 --- /dev/null +++ b/.changeset/strange-bananas-switch.md @@ -0,0 +1,5 @@ +--- +'style-dictionary': patch +--- + +Add and check types to CLI file, fix typo for --platform flag. diff --git a/bin/style-dictionary.js b/bin/style-dictionary.js index 6365a1513..3ae887567 100755 --- a/bin/style-dictionary.js +++ b/bin/style-dictionary.js @@ -6,21 +6,39 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import node_fs from 'node:fs'; import JSON5 from 'json5'; -import program from 'commander'; +import { Command } from 'commander'; // usually also node:fs in this context, but can be customized by user import { fs } from 'style-dictionary/fs'; import StyleDictionary from 'style-dictionary'; import { logWarningLevels, logVerbosityLevels } from '../lib/enums/index.js'; +/** + * @typedef {{ + * config?: string; + * platform?: string[]; + * verbose?: boolean; + * warn?: boolean; + * silent?: boolean; + * }} BuildOptions + */ + +const program = new Command(); const __dirname = path.dirname(fileURLToPath(import.meta.url)); const { silent, verbose } = logVerbosityLevels; const pkg = JSON5.parse(node_fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')); +/** + * @param {string} val + * @param {string[]} arr + */ function collect(val, arr) { arr.push(val); return arr; } +/** + * @param {BuildOptions} options + */ function getConfigPath(options) { let configPath = options.config; @@ -108,6 +126,10 @@ program.on('command:*', function () { process.exit(1); }); +/** + * @param {string} configPath + * @param {BuildOptions} options + */ function getSD(configPath, options) { let verbosity; let warnings; @@ -120,27 +142,33 @@ function getSD(configPath, options) { return new StyleDictionary(configPath, { verbosity, warnings }); } +/** + * @param {BuildOptions} [options] + */ async function styleDictionaryBuild(options) { options = options || {}; const configPath = getConfigPath(options); const sd = getSD(configPath, options); if (options.platform && options.platform.length > 0) { - return Promise.all(options.platforms.map((platform) => sd.buildPlatform(platform))); + await Promise.all(options.platform.map((platform) => sd.buildPlatform(platform))); } else { - return sd.buildAllPlatforms(); + await sd.buildAllPlatforms(); } } +/** + * @param {BuildOptions} [options] + */ async function styleDictionaryClean(options) { options = options || {}; const configPath = getConfigPath(options); const sd = getSD(configPath, options); if (options.platform && options.platform.length > 0) { - return Promise.all(options.platforms.map((platform) => sd.cleanPlatform(platform))); + await Promise.all(options.platform.map((platform) => sd.cleanPlatform(platform))); } else { - return sd.cleanAllPlatforms(); + await sd.cleanAllPlatforms(); } } diff --git a/package-lock.json b/package-lock.json index f6b0675e5..f7dc3d319 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@zip.js/zip.js": "^2.7.44", "chalk": "^5.3.0", "change-case": "^5.3.0", - "commander": "^8.3.0", + "commander": "^12.1.0", "is-plain-obj": "^4.1.0", "json5": "^2.2.2", "patch-package": "^8.0.0", @@ -7307,11 +7307,12 @@ } }, "node_modules/commander": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", - "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==", + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "license": "MIT", "engines": { - "node": ">= 12" + "node": ">=18" } }, "node_modules/common-ancestor-path": { @@ -12425,6 +12426,16 @@ "katex": "cli.js" } }, + "node_modules/katex/node_modules/commander": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", + "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, "node_modules/keygrip": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz", diff --git a/package.json b/package.json index 19f371396..45ea0d61a 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "@zip.js/zip.js": "^2.7.44", "chalk": "^5.3.0", "change-case": "^5.3.0", - "commander": "^8.3.0", + "commander": "^12.1.0", "is-plain-obj": "^4.1.0", "json5": "^2.2.2", "patch-package": "^8.0.0", diff --git a/tsconfig.json b/tsconfig.json index 55ac62ddb..4559771dc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,6 @@ "skipLibCheck": true, "declaration": true }, - "include": ["lib/**/*.js", "**/*.ts"], + "include": ["lib/**/*.js", "**/*.ts", "bin/**/*.js"], "exclude": ["node_modules", "**/coverage/*"] }