sparkle-design-cli 1.6.0 → 1.6.1
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/bin/sparkle-design.js +11 -2
- package/lib/font-manager.js +73 -6
- package/lib/generate-css.js +4 -3
- package/package.json +1 -1
package/bin/sparkle-design.js
CHANGED
|
@@ -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
|
|
|
@@ -167,6 +172,10 @@ sparkle.config.json の設定フィールド:
|
|
|
167
172
|
extend.source-packages @source で追加スキャンする npm パッケージ名の配列
|
|
168
173
|
extend.custom-css プロジェクト固有のカスタムトークン CSS ファイルパス
|
|
169
174
|
|
|
175
|
+
その他:
|
|
176
|
+
globals-path Tailwind エントリポイント CSS のパス(未指定時は自動検出)
|
|
177
|
+
Vite の場合: "src/index.css" など
|
|
178
|
+
|
|
170
179
|
extend.fonts がある場合、font-pro / font-mono より優先される。
|
|
171
180
|
ない場合は font-pro / font-mono + デフォルトウェイト [400, 700] が使われる。
|
|
172
181
|
同じフォントファミリーが pro と mono で重複する場合、ウェイトはマージされ import は 1 行になる。
|
|
@@ -242,7 +251,7 @@ function main() {
|
|
|
242
251
|
process.exit(0);
|
|
243
252
|
}
|
|
244
253
|
|
|
245
|
-
generateCSS(options.configPath, options.outputPath);
|
|
254
|
+
generateCSS(options.configPath, options.outputPath, options.globalsPath);
|
|
246
255
|
return;
|
|
247
256
|
}
|
|
248
257
|
|
|
@@ -285,7 +294,7 @@ function main() {
|
|
|
285
294
|
process.exit(0);
|
|
286
295
|
}
|
|
287
296
|
|
|
288
|
-
generateCSS(options.configPath, options.outputPath);
|
|
297
|
+
generateCSS(options.configPath, options.outputPath, options.globalsPath);
|
|
289
298
|
return;
|
|
290
299
|
}
|
|
291
300
|
|
package/lib/font-manager.js
CHANGED
|
@@ -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を抽出し、
|
|
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
|
|
255
|
-
const
|
|
320
|
+
// 1. globals パスを解決
|
|
321
|
+
const resolved = resolveGlobalsPath(sparkleDesignPath, globalsPathOverride);
|
|
256
322
|
|
|
257
|
-
|
|
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);
|
package/lib/generate-css.js
CHANGED
|
@@ -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
|
-
|
|
401
|
+
const globalsPathOverride = globalsPath || config['globals-path'] || null;
|
|
402
|
+
manageFontImports(resolvedOutputPath, sourcePackages, customCssPath, globalsPathOverride);
|
|
402
403
|
|
|
403
404
|
console.log(MESSAGES.SUCCESS);
|
|
404
405
|
}
|