sparkle-design-cli 1.2.0 → 1.2.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.
package/README.md
CHANGED
|
@@ -99,7 +99,7 @@ CSS の仕様では、`@import` 文は `@charset` と `@layer` 以外のすべ
|
|
|
99
99
|
|
|
100
100
|
この機能により、以下の警告が自動的に解決されます:
|
|
101
101
|
|
|
102
|
-
```
|
|
102
|
+
```text
|
|
103
103
|
⚠️ @import rules must precede all rules aside from @charset and @layer statements
|
|
104
104
|
```
|
|
105
105
|
|
|
@@ -110,7 +110,7 @@ CSS の仕様では、`@import` 文は `@charset` と `@layer` 以外のすべ
|
|
|
110
110
|
|
|
111
111
|
### 出力例
|
|
112
112
|
|
|
113
|
-
```
|
|
113
|
+
```text
|
|
114
114
|
📦 フォント管理処理を開始します...
|
|
115
115
|
📝 3個のフォントimportを検出しました
|
|
116
116
|
✅ globals.css にフォントimportを追加しました
|
package/lib/constants.js
CHANGED
|
@@ -102,6 +102,9 @@ export const MESSAGES = {
|
|
|
102
102
|
NO_FONT_IMPORTS: 'ℹ️ sparkle-design.css にフォントimportが見つかりません。',
|
|
103
103
|
FONT_DETECTED: (count) => `📝 ${count}個のフォントimportを検出しました`,
|
|
104
104
|
|
|
105
|
+
// スキップメッセージ
|
|
106
|
+
FONT_REMOVE_SKIPPED: 'ℹ️ globals.css の更新に失敗したため、フォントimport削除をスキップします。',
|
|
107
|
+
|
|
105
108
|
// 警告メッセージ
|
|
106
109
|
TAILWIND_NOT_FOUND: '⚠️ globals.css に Tailwind import が見つかりません。',
|
|
107
110
|
GLOBALS_UPDATE_FAILED: (error) => `⚠️ globals.css の更新に失敗しました: ${error}`,
|
package/lib/file-loader.js
CHANGED
|
@@ -15,7 +15,7 @@ const __dirname = path.dirname(__filename);
|
|
|
15
15
|
* ファイルを読み込む共通関数
|
|
16
16
|
* @param {string} filePath ファイルパス
|
|
17
17
|
* @param {string} successMessage 成功時のメッセージ
|
|
18
|
-
* @param {string} errorMessage
|
|
18
|
+
* @param {string|Function} errorMessage エラー時のメッセージ(文字列 or (error) => string)
|
|
19
19
|
* @param {Function} additionalErrorHandler 追加のエラーハンドラ(オプション)
|
|
20
20
|
* @returns {string} ファイル内容
|
|
21
21
|
*/
|
|
@@ -25,7 +25,12 @@ function readFile(filePath, successMessage, errorMessage, additionalErrorHandler
|
|
|
25
25
|
console.log(successMessage);
|
|
26
26
|
return content;
|
|
27
27
|
} catch (error) {
|
|
28
|
-
|
|
28
|
+
const message =
|
|
29
|
+
typeof errorMessage === 'function'
|
|
30
|
+
? errorMessage(error)
|
|
31
|
+
: errorMessage || `❌ ファイルの読み込みに失敗しました: ${error.message}`;
|
|
32
|
+
|
|
33
|
+
console.error(message);
|
|
29
34
|
if (additionalErrorHandler) {
|
|
30
35
|
additionalErrorHandler(filePath, error);
|
|
31
36
|
}
|
|
@@ -37,13 +42,27 @@ function readFile(filePath, successMessage, errorMessage, additionalErrorHandler
|
|
|
37
42
|
* JSONファイルを読み込む共通関数
|
|
38
43
|
* @param {string} filePath ファイルパス
|
|
39
44
|
* @param {string} successMessage 成功時のメッセージ
|
|
40
|
-
* @param {string} errorMessage
|
|
45
|
+
* @param {string|Function} errorMessage エラー時のメッセージ(文字列 or (error) => string)
|
|
41
46
|
* @param {Function} additionalErrorHandler 追加のエラーハンドラ(オプション)
|
|
42
47
|
* @returns {Object} パース済みのJSONオブジェクト
|
|
43
48
|
*/
|
|
44
49
|
function readJsonFile(filePath, successMessage, errorMessage, additionalErrorHandler = null) {
|
|
45
50
|
const content = readFile(filePath, successMessage, errorMessage, additionalErrorHandler);
|
|
46
|
-
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(content);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const message =
|
|
56
|
+
typeof errorMessage === 'function'
|
|
57
|
+
? errorMessage(error)
|
|
58
|
+
: errorMessage || `❌ JSONのパースに失敗しました: ${error.message}`;
|
|
59
|
+
|
|
60
|
+
console.error(message);
|
|
61
|
+
if (additionalErrorHandler) {
|
|
62
|
+
additionalErrorHandler(filePath, error);
|
|
63
|
+
}
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
/**
|
|
@@ -67,7 +86,7 @@ export function loadConfig(configPath = null) {
|
|
|
67
86
|
const config = readJsonFile(
|
|
68
87
|
resolvedConfigPath,
|
|
69
88
|
MESSAGES.CONFIG_LOADED(resolvedConfigPath),
|
|
70
|
-
MESSAGES.CONFIG_LOAD_FAILED(
|
|
89
|
+
(error) => MESSAGES.CONFIG_LOAD_FAILED(error.message),
|
|
71
90
|
(filePath, _error) => {
|
|
72
91
|
console.error(MESSAGES.CONFIG_PATH_INFO(filePath));
|
|
73
92
|
console.error(MESSAGES.CONFIG_HELP);
|
|
@@ -88,7 +107,7 @@ export function loadTemplate() {
|
|
|
88
107
|
return readFile(
|
|
89
108
|
templatePath,
|
|
90
109
|
MESSAGES.TEMPLATE_LOADED,
|
|
91
|
-
MESSAGES.TEMPLATE_LOAD_FAILED(
|
|
110
|
+
(error) => MESSAGES.TEMPLATE_LOAD_FAILED(error.message),
|
|
92
111
|
(filePath) => {
|
|
93
112
|
console.error(MESSAGES.TEMPLATE_PATH_INFO(filePath));
|
|
94
113
|
}
|
|
@@ -102,7 +121,9 @@ export function loadTemplate() {
|
|
|
102
121
|
export function loadColors() {
|
|
103
122
|
const colorsPath = path.join(getTemplateDir(), FILE_NAMES.COLORS);
|
|
104
123
|
|
|
105
|
-
return readJsonFile(colorsPath, MESSAGES.COLORS_LOADED,
|
|
124
|
+
return readJsonFile(colorsPath, MESSAGES.COLORS_LOADED, (error) =>
|
|
125
|
+
MESSAGES.COLORS_LOAD_FAILED(error.message)
|
|
126
|
+
);
|
|
106
127
|
}
|
|
107
128
|
|
|
108
129
|
/**
|
|
@@ -112,7 +133,9 @@ export function loadColors() {
|
|
|
112
133
|
export function loadGrayMapping() {
|
|
113
134
|
const grayJsonPath = path.join(getTemplateDir(), FILE_NAMES.GRAY);
|
|
114
135
|
|
|
115
|
-
return readJsonFile(grayJsonPath, MESSAGES.GRAY_LOADED,
|
|
136
|
+
return readJsonFile(grayJsonPath, MESSAGES.GRAY_LOADED, (error) =>
|
|
137
|
+
MESSAGES.GRAY_LOAD_FAILED(error.message)
|
|
138
|
+
);
|
|
116
139
|
}
|
|
117
140
|
|
|
118
141
|
/**
|
|
@@ -122,10 +145,8 @@ export function loadGrayMapping() {
|
|
|
122
145
|
export function loadRadiusMapping() {
|
|
123
146
|
const radiusCsvPath = path.join(getTemplateDir(), FILE_NAMES.RADIUS);
|
|
124
147
|
|
|
125
|
-
const csvContent = readFile(
|
|
126
|
-
|
|
127
|
-
MESSAGES.RADIUS_LOADED,
|
|
128
|
-
MESSAGES.RADIUS_LOAD_FAILED('')
|
|
148
|
+
const csvContent = readFile(radiusCsvPath, MESSAGES.RADIUS_LOADED, (error) =>
|
|
149
|
+
MESSAGES.RADIUS_LOAD_FAILED(error.message)
|
|
129
150
|
);
|
|
130
151
|
|
|
131
152
|
// CSVをパース
|
package/lib/font-manager.js
CHANGED
|
@@ -111,10 +111,11 @@ function reconstructGlobalsCss(globalsContent, fontImportBlock, sparkleImportBlo
|
|
|
111
111
|
* - sparkle-design.css importをTailwindの後に配置
|
|
112
112
|
* @param {Array<string>} fontImports フォントimport文の配列
|
|
113
113
|
* @param {string} globalsPath globals.cssのパス
|
|
114
|
+
* @returns {boolean} globals.css の更新に成功した場合は true
|
|
114
115
|
*/
|
|
115
116
|
export function updateGlobalsWithFonts(fontImports, globalsPath) {
|
|
116
117
|
if (fontImports.length === 0) {
|
|
117
|
-
return;
|
|
118
|
+
return false;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
try {
|
|
@@ -128,7 +129,7 @@ export function updateGlobalsWithFonts(fontImports, globalsPath) {
|
|
|
128
129
|
const tailwindInfo = findTailwindImport(globalsContent);
|
|
129
130
|
if (!tailwindInfo) {
|
|
130
131
|
console.warn(MESSAGES.TAILWIND_NOT_FOUND);
|
|
131
|
-
return;
|
|
132
|
+
return false;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
// 4. importブロックを生成
|
|
@@ -146,9 +147,11 @@ export function updateGlobalsWithFonts(fontImports, globalsPath) {
|
|
|
146
147
|
// 6. 更新したglobals.cssを書き込む
|
|
147
148
|
fs.writeFileSync(globalsPath, reconstructedContent, 'utf8');
|
|
148
149
|
console.log(MESSAGES.GLOBALS_UPDATED(globalsPath));
|
|
150
|
+
return true;
|
|
149
151
|
} catch (error) {
|
|
150
152
|
console.error(MESSAGES.GLOBALS_UPDATE_FAILED(error.message));
|
|
151
153
|
// globals.cssの更新は必須ではないので、エラーでも処理を続行
|
|
154
|
+
return false;
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
|
|
@@ -180,7 +183,12 @@ export function manageFontImports(sparkleDesignPath) {
|
|
|
180
183
|
console.log(MESSAGES.FONT_DETECTED(fontImports.length));
|
|
181
184
|
|
|
182
185
|
// 4. globals.css にフォントimportを追加
|
|
183
|
-
updateGlobalsWithFonts(fontImports, globalsPath);
|
|
186
|
+
const globalsUpdated = updateGlobalsWithFonts(fontImports, globalsPath);
|
|
187
|
+
|
|
188
|
+
if (!globalsUpdated) {
|
|
189
|
+
console.log(MESSAGES.FONT_REMOVE_SKIPPED);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
184
192
|
|
|
185
193
|
// 5. sparkle-design.css からフォントimportを削除
|
|
186
194
|
const cleanedSparkleContent = removeFontImportsFromCSS(sparkleContent);
|
package/package.json
CHANGED
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
|
|
68
68
|
/* シャドウ */
|
|
69
69
|
/* Primitive */
|
|
70
|
-
--shadow-none: 0px 0px 0px 0px
|
|
71
|
-
--shadow-2xs: 0px 1px 0px 0px
|
|
72
|
-
--shadow-xs: 0px 1px 2px 0px
|
|
73
|
-
--shadow-sm: 0px 1px 3px 0px
|
|
74
|
-
--shadow-md: 0px 4px 6px -1px
|
|
75
|
-
--shadow-lg: 0px 10px 15px -3px
|
|
70
|
+
--shadow-none: 0px 0px 0px 0px var(--color-black);
|
|
71
|
+
--shadow-2xs: 0px 1px 0px 0px var(--color-black-alpha-50);
|
|
72
|
+
--shadow-xs: 0px 1px 2px 0px var(--color-black-alpha-50);
|
|
73
|
+
--shadow-sm: 0px 1px 3px 0px var(--color-black-alpha-100), 0px 1px 2px -1px var(--color-black-alpha-100);
|
|
74
|
+
--shadow-md: 0px 4px 6px -1px var(--color-black-alpha-100), 0px 2px 4px -2px var(--color-black-alpha-100);
|
|
75
|
+
--shadow-lg: 0px 10px 15px -3px var(--color-black-alpha-100), 0px 4px 6px -4px var(--color-black-alpha-100);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/* セマンティクスのトークン定義 */
|