sparkle-design-cli 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/generate-css.js +47 -1
- package/lib/setup.js +4 -0
- package/package.json +1 -1
package/lib/generate-css.js
CHANGED
|
@@ -332,6 +332,40 @@ function processTemplate(template, config, grayMapping, radiusMapping, colors) {
|
|
|
332
332
|
* @param {string} cssContent CSS内容
|
|
333
333
|
* @param {string|null} outputPath カスタム出力パス(オプション)
|
|
334
334
|
*/
|
|
335
|
+
// 自動検出対象の既知デザインシステムパッケージ。
|
|
336
|
+
// `sparkle-design` は CLI 側のデフォルトパッケージなのでリストには加えず「存在判定」にだけ使う。
|
|
337
|
+
// en: Known design-system packages to auto-detect. `sparkle-design` is the CLI's
|
|
338
|
+
// default source package, so it only acts as an "enables @source" signal.
|
|
339
|
+
const KNOWN_DESIGN_SYSTEM_PACKAGES = [
|
|
340
|
+
'@goodpatch/sparkle-design-internal',
|
|
341
|
+
];
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* package.json の dependencies / devDependencies から既知のデザインシステムパッケージを検出する。
|
|
345
|
+
* - `sparkle-design` が入っていれば(CLI のデフォルトで @source に含まれるため)空配列を返し、@source 挿入を有効化
|
|
346
|
+
* - `@goodpatch/sparkle-design-internal` など追加の既知パッケージが入っていればリストに含める
|
|
347
|
+
* - いずれも見つからなければ null(従来通り @source を生成しない)
|
|
348
|
+
* en: Scan package.json and surface source-packages when a design-system package is present.
|
|
349
|
+
*/
|
|
350
|
+
function detectSourcePackagesFromPackageJson(cwd = process.cwd()) {
|
|
351
|
+
try {
|
|
352
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
|
|
353
|
+
const deps = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
|
|
354
|
+
|
|
355
|
+
const hasDefault = Object.prototype.hasOwnProperty.call(deps, 'sparkle-design');
|
|
356
|
+
const extras = KNOWN_DESIGN_SYSTEM_PACKAGES.filter((name) =>
|
|
357
|
+
Object.prototype.hasOwnProperty.call(deps, name)
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
if (hasDefault || extras.length > 0) {
|
|
361
|
+
return extras;
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
} catch {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
335
369
|
function writeCSS(cssContent, outputPath = null) {
|
|
336
370
|
// カスタムパスが指定されていない場合は実行場所からsrc/appディレクトリに出力
|
|
337
371
|
const defaultOutputPath = path.resolve(
|
|
@@ -395,8 +429,19 @@ export function generateCSS(configPath = null, outputPath = null, globalsPath =
|
|
|
395
429
|
writeSparkleHead(sparkleHeadContent, resolvedOutputPath);
|
|
396
430
|
|
|
397
431
|
// 8. フォント管理の自動処理を実行(globals.css にはフォント @import を差し込まない)
|
|
432
|
+
// source-packages は以下の合成で決まる:
|
|
433
|
+
// 1. package.json から既知のデザインシステムパッケージを自動検出(baseline)
|
|
434
|
+
// 2. config の extend.source-packages(ユーザー追記分、例: クライアント固有パッケージ)
|
|
435
|
+
// 両方空なら null(@source を生成しない)。
|
|
436
|
+
// en: source-packages are resolved by merging auto-detection (from package.json)
|
|
437
|
+
// with explicit config entries. If neither surfaces anything, @source is skipped.
|
|
398
438
|
console.log(MESSAGES.FONT_MANAGEMENT_START);
|
|
399
|
-
const
|
|
439
|
+
const detectedPackages = detectSourcePackagesFromPackageJson();
|
|
440
|
+
const explicitPackages = 'source-packages' in config ? (config['source-packages'] || []) : null;
|
|
441
|
+
const sourcePackages =
|
|
442
|
+
detectedPackages !== null || explicitPackages !== null
|
|
443
|
+
? [...new Set([...(detectedPackages ?? []), ...(explicitPackages ?? [])])]
|
|
444
|
+
: null;
|
|
400
445
|
const customCssPath = config['custom-css'] || null;
|
|
401
446
|
const globalsPathOverride = globalsPath || config['globals-path'] || null;
|
|
402
447
|
manageFontImports(resolvedOutputPath, sourcePackages, customCssPath, globalsPathOverride);
|
|
@@ -414,6 +459,7 @@ export {
|
|
|
414
459
|
// メイン関数
|
|
415
460
|
processTemplate,
|
|
416
461
|
writeCSS,
|
|
462
|
+
detectSourcePackagesFromPackageJson,
|
|
417
463
|
// ファイル読み込み
|
|
418
464
|
loadConfig,
|
|
419
465
|
loadTemplate,
|
package/lib/setup.js
CHANGED
|
@@ -5,6 +5,10 @@ import { generateCSS } from './generate-css.js';
|
|
|
5
5
|
|
|
6
6
|
// デフォルトの sparkle.config.json テンプレート
|
|
7
7
|
// en: Default sparkle.config.json template
|
|
8
|
+
// @source ディレクティブの生成は generate 側が package.json から既知のデザインシステム
|
|
9
|
+
// パッケージ(sparkle-design / @goodpatch/sparkle-design-internal 等)を自動検出して
|
|
10
|
+
// 行うため、ここで extend.source-packages を指定する必要はない。独自パッケージを
|
|
11
|
+
// 追加する場合のみユーザーが extend.source-packages に追記する。
|
|
8
12
|
const DEFAULT_SPARKLE_CONFIG = {
|
|
9
13
|
primary: 'blue',
|
|
10
14
|
'font-pro': 'Inter',
|