sparkle-design-cli 1.6.0 → 1.6.2

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.
@@ -18,6 +18,7 @@ function parseGenerateOptions(args) {
18
18
  const options = {
19
19
  configPath: null,
20
20
  outputPath: null,
21
+ globalsPath: null,
21
22
  help: false,
22
23
  };
23
24
 
@@ -32,6 +33,9 @@ function parseGenerateOptions(args) {
32
33
  } else if (arg === '-o' || arg === '--output') {
33
34
  options.outputPath = requireOptionValue(args, i, '-o/--output');
34
35
  i += 1;
36
+ } else if (arg === '--globals-path') {
37
+ options.globalsPath = requireOptionValue(args, i, '--globals-path');
38
+ i += 1;
35
39
  } else {
36
40
  throw new Error(`Unknown option for generate: ${arg}`);
37
41
  }
@@ -148,6 +152,7 @@ Generate options:
148
152
  -h, --help このヘルプメッセージを表示
149
153
  -c, --config <path> 設定ファイルのパス (default: ./sparkle.config.json)
150
154
  -o, --output <path> 出力ファイルのパス (default: ./src/app/sparkle-design.css)
155
+ --globals-path <path> Tailwind エントリポイント CSS のパス (default: 自動検出)
151
156
 
152
157
  sparkle.config.json の設定フィールド:
153
158
 
@@ -166,6 +171,8 @@ sparkle.config.json の設定フィールド:
166
171
  extend.fonts.mono モノスペースフォント定義(形式は fonts.pro と同じ)
167
172
  extend.source-packages @source で追加スキャンする npm パッケージ名の配列
168
173
  extend.custom-css プロジェクト固有のカスタムトークン CSS ファイルパス
174
+ extend.globals-path Tailwind エントリポイント CSS のパス(未指定時は自動検出)
175
+ Vite の場合: "src/index.css" など
169
176
 
170
177
  extend.fonts がある場合、font-pro / font-mono より優先される。
171
178
  ない場合は font-pro / font-mono + デフォルトウェイト [400, 700] が使われる。
@@ -242,7 +249,7 @@ function main() {
242
249
  process.exit(0);
243
250
  }
244
251
 
245
- generateCSS(options.configPath, options.outputPath);
252
+ generateCSS(options.configPath, options.outputPath, options.globalsPath);
246
253
  return;
247
254
  }
248
255
 
@@ -285,7 +292,7 @@ function main() {
285
292
  process.exit(0);
286
293
  }
287
294
 
288
- generateCSS(options.configPath, options.outputPath);
295
+ generateCSS(options.configPath, options.outputPath, options.globalsPath);
289
296
  return;
290
297
  }
291
298
 
@@ -242,24 +242,91 @@ export function updateGlobalsWithFonts(fontImports, globalsPath, sourcePackages
242
242
  }
243
243
  }
244
244
 
245
+ /**
246
+ * sparkle-design.css と同じディレクトリで Tailwind のエントリポイント CSS を自動検出する
247
+ * @param {string} dir 検索対象ディレクトリ
248
+ * @returns {string|null} 検出されたファイルの絶対パス、見つからなければ null
249
+ */
250
+ function detectTailwindEntrypoint(dir) {
251
+ let entries;
252
+ try {
253
+ entries = fs.readdirSync(dir, { withFileTypes: true });
254
+ } catch {
255
+ return null;
256
+ }
257
+
258
+ for (const entry of entries) {
259
+ if (!entry.isFile() || path.extname(entry.name) !== '.css') continue;
260
+ if (entry.name === 'sparkle-design.css') continue;
261
+
262
+ const filePath = path.join(dir, entry.name);
263
+ const content = fs.readFileSync(filePath, 'utf8');
264
+ if (REGEX.TAILWIND_IMPORT.test(content)) {
265
+ return filePath;
266
+ }
267
+ }
268
+
269
+ return null;
270
+ }
271
+
272
+ /**
273
+ * globals パスを解決する
274
+ * 優先順位: 明示的指定 > 自動検出 > デフォルト(globals.css)
275
+ * @param {string} sparkleDesignPath sparkle-design.css のパス
276
+ * @param {string|null} explicitGlobalsPath 明示的に指定された globals パス
277
+ * @returns {{ path: string, source: 'explicit' | 'detected' | 'default' } | null}
278
+ */
279
+ function resolveGlobalsPath(sparkleDesignPath, explicitGlobalsPath = null) {
280
+ const dir = path.dirname(sparkleDesignPath);
281
+
282
+ if (explicitGlobalsPath) {
283
+ const resolved = path.resolve(process.cwd(), explicitGlobalsPath);
284
+ if (fs.existsSync(resolved)) {
285
+ return { path: resolved, source: 'explicit' };
286
+ }
287
+ console.warn(`⚠️ 指定された globals パスが見つかりません: ${explicitGlobalsPath}`);
288
+ return null;
289
+ }
290
+
291
+ // 自動検出: @import "tailwindcss" を含む CSS ファイルを探す
292
+ const detected = detectTailwindEntrypoint(dir);
293
+ if (detected) {
294
+ const basename = path.basename(detected);
295
+ if (basename !== 'globals.css') {
296
+ console.log(`📝 Tailwind エントリポイントを自動検出しました: ${basename}`);
297
+ }
298
+ return { path: detected, source: 'detected' };
299
+ }
300
+
301
+ // デフォルト: globals.css
302
+ const defaultPath = path.join(dir, 'globals.css');
303
+ if (fs.existsSync(defaultPath)) {
304
+ return { path: defaultPath, source: 'default' };
305
+ }
306
+
307
+ return null;
308
+ }
309
+
245
310
  /**
246
311
  * フォント管理の自動処理を実行する
247
- * sparkle-design.css からフォントimportを抽出し、globals.css に移動する
312
+ * sparkle-design.css からフォントimportを抽出し、Tailwind エントリポイント CSS に @source 等を挿入する
248
313
  * @param {string} sparkleDesignPath sparkle-design.cssのパス
249
314
  * @param {Array<string>|null} sourcePackages 追加パッケージ名の配列(null の場合は @source を生成しない)
250
315
  * @param {string|null} customCssPath custom-css ファイルの相対パス
316
+ * @param {string|null} globalsPathOverride 明示的に指定された globals パス
251
317
  */
252
- export function manageFontImports(sparkleDesignPath, sourcePackages = null, customCssPath = null) {
318
+ export function manageFontImports(sparkleDesignPath, sourcePackages = null, customCssPath = null, globalsPathOverride = null) {
253
319
  try {
254
- // 1. globals.cssのパスを推定(sparkle-design.cssと同じディレクトリ)
255
- const globalsPath = path.join(path.dirname(sparkleDesignPath), 'globals.css');
320
+ // 1. globals パスを解決
321
+ const resolved = resolveGlobalsPath(sparkleDesignPath, globalsPathOverride);
256
322
 
257
- // 2. globals.cssが存在しない場合はスキップ
258
- if (!fs.existsSync(globalsPath)) {
323
+ if (!resolved) {
259
324
  console.log(MESSAGES.GLOBALS_NOT_FOUND);
260
325
  return;
261
326
  }
262
327
 
328
+ const globalsPath = resolved.path;
329
+
263
330
  // 3. sparkle-design.css からフォントimportを抽出
264
331
  const sparkleContent = fs.readFileSync(sparkleDesignPath, 'utf8');
265
332
  const fontImports = extractFontImports(sparkleContent);
@@ -289,7 +289,7 @@ function processTemplate(template, config, grayMapping, radiusMapping, colors) {
289
289
  // 5. 基本的な設定値による置換(オブジェクト・配列・拡張フィールドはスキップ)
290
290
  Object.entries(config).forEach(([key, value]) => {
291
291
  // 配列・オブジェクト・拡張フィールドはスキップ
292
- if (Array.isArray(value) || (typeof value === 'object' && value !== null) || key === 'custom-css' || key === 'fonts' || key === 'extend' || key === 'source-packages') {
292
+ if (Array.isArray(value) || (typeof value === 'object' && value !== null) || key === 'custom-css' || key === 'fonts' || key === 'extend' || key === 'source-packages' || key === 'globals-path') {
293
293
  return;
294
294
  }
295
295
  // 通常のプレースホルダー(CSS用 - スペースはそのまま)
@@ -361,7 +361,7 @@ function writeCSS(cssContent, outputPath = null) {
361
361
  * @param {string|null} configPath カスタム設定ファイルのパス(オプション)
362
362
  * @param {string|null} outputPath カスタム出力パス(オプション)
363
363
  */
364
- export function generateCSS(configPath = null, outputPath = null) {
364
+ export function generateCSS(configPath = null, outputPath = null, globalsPath = null) {
365
365
  console.log(MESSAGES.START);
366
366
 
367
367
  // 1. 設定ファイルを読み込み
@@ -398,7 +398,8 @@ export function generateCSS(configPath = null, outputPath = null) {
398
398
  console.log(MESSAGES.FONT_MANAGEMENT_START);
399
399
  const sourcePackages = 'source-packages' in config ? (config['source-packages'] || []) : null;
400
400
  const customCssPath = config['custom-css'] || null;
401
- manageFontImports(resolvedOutputPath, sourcePackages, customCssPath);
401
+ const globalsPathOverride = globalsPath || config['globals-path'] || null;
402
+ manageFontImports(resolvedOutputPath, sourcePackages, customCssPath, globalsPathOverride);
402
403
 
403
404
  console.log(MESSAGES.SUCCESS);
404
405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparkle-design-cli",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Sparkle Design CSS Generator - デザインシステムCSSを設定ファイルから生成するツール",
5
5
  "main": "lib/generate-css.js",
6
6
  "type": "module",