sparkle-design-cli 1.3.3 → 1.3.4
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/font-manager.js +32 -5
- package/package.json +1 -1
package/lib/font-manager.js
CHANGED
|
@@ -35,28 +35,55 @@ function createFontImportBlock(fontImports) {
|
|
|
35
35
|
return [COMMENTS.FONT_IMPORT, ...fontImports, ''].join('\n');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* globals.css から node_modules への相対パスを計算する
|
|
40
|
+
* @param {string} globalsPath globals.css の絶対パス
|
|
41
|
+
* @returns {string} node_modules への相対パス(例: "../../node_modules")
|
|
42
|
+
*/
|
|
43
|
+
function resolveNodeModulesRelPath(globalsPath) {
|
|
44
|
+
const globalsDir = path.dirname(globalsPath);
|
|
45
|
+
// globals.css と同じプロジェクトルートにある node_modules を探す
|
|
46
|
+
let dir = globalsDir;
|
|
47
|
+
while (dir !== path.dirname(dir)) {
|
|
48
|
+
const candidate = path.join(dir, 'node_modules');
|
|
49
|
+
if (fs.existsSync(candidate)) {
|
|
50
|
+
const rel = path.relative(globalsDir, candidate);
|
|
51
|
+
// POSIX パス区切りに変換
|
|
52
|
+
return rel.split(path.sep).join('/');
|
|
53
|
+
}
|
|
54
|
+
dir = path.dirname(dir);
|
|
55
|
+
}
|
|
56
|
+
// 見つからない場合はプロジェクトルート(cwd)からの相対パスを使用
|
|
57
|
+
const fallback = path.join(process.cwd(), 'node_modules');
|
|
58
|
+
const rel = path.relative(globalsDir, fallback);
|
|
59
|
+
return rel.split(path.sep).join('/');
|
|
60
|
+
}
|
|
61
|
+
|
|
38
62
|
/**
|
|
39
63
|
* @source ディレクティブブロックを生成する
|
|
40
64
|
* @param {Array<string>} sourcePackages 追加パッケージ名の配列
|
|
65
|
+
* @param {string} nodeModulesRel node_modules への相対パス
|
|
41
66
|
* @returns {string} @source ディレクティブブロック
|
|
42
67
|
*/
|
|
43
|
-
function createSourceBlock(sourcePackages = []) {
|
|
68
|
+
function createSourceBlock(sourcePackages = [], nodeModulesRel = '../node_modules') {
|
|
44
69
|
const defaultPackage = '@goodpatch/sparkle-design';
|
|
45
70
|
const allPackages = [defaultPackage, ...sourcePackages.filter(p => p !== defaultPackage)];
|
|
46
|
-
const sourceLines = allPackages.map(pkg => `@source "
|
|
71
|
+
const sourceLines = allPackages.map(pkg => `@source "${nodeModulesRel}/${pkg}/dist";`);
|
|
47
72
|
return [COMMENTS.SOURCE_DIRECTIVE, ...sourceLines].join('\n');
|
|
48
73
|
}
|
|
49
74
|
|
|
50
75
|
/**
|
|
51
76
|
* sparkle-design.css importブロックを生成する
|
|
52
77
|
* @param {Array<string>} sourcePackages 追加パッケージ名の配列
|
|
78
|
+
* @param {string} globalsPath globals.css の絶対パス(@source パス計算用)
|
|
53
79
|
* @returns {string} sparkle-design.css importブロック
|
|
54
80
|
*/
|
|
55
|
-
function createSparkleImportBlock(sourcePackages = []) {
|
|
81
|
+
function createSparkleImportBlock(sourcePackages = [], globalsPath = null) {
|
|
56
82
|
if (sourcePackages === null || sourcePackages === undefined) {
|
|
57
83
|
return ['', COMMENTS.SPARKLE_IMPORT, IMPORTS.SPARKLE_DESIGN, ''].join('\n');
|
|
58
84
|
}
|
|
59
|
-
|
|
85
|
+
const nodeModulesRel = globalsPath ? resolveNodeModulesRelPath(globalsPath) : '../node_modules';
|
|
86
|
+
return ['', createSourceBlock(sourcePackages, nodeModulesRel), COMMENTS.SPARKLE_IMPORT, IMPORTS.SPARKLE_DESIGN, ''].join('\n');
|
|
60
87
|
}
|
|
61
88
|
|
|
62
89
|
/**
|
|
@@ -155,7 +182,7 @@ export function updateGlobalsWithFonts(fontImports, globalsPath, sourcePackages
|
|
|
155
182
|
|
|
156
183
|
// 4. importブロックを生成
|
|
157
184
|
const fontImportBlock = createFontImportBlock(fontImports);
|
|
158
|
-
const sparkleImportBlock = createSparkleImportBlock(sourcePackages);
|
|
185
|
+
const sparkleImportBlock = createSparkleImportBlock(sourcePackages, globalsPath);
|
|
159
186
|
|
|
160
187
|
// 5. globals.css を再構築
|
|
161
188
|
const reconstructedContent = reconstructGlobalsCss(
|