@uiscore/cli 0.1.6 → 0.1.7
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/dist/index.js +33 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -82,6 +82,7 @@ function devDependencyInstallArgs(packageManager, dependencies) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// src/commands/add.ts
|
|
85
|
+
var UISCORE_FONT_IMPORT = '@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700&display=swap");';
|
|
85
86
|
async function runAddCommand(options) {
|
|
86
87
|
const config = loadConfig(options.cwd);
|
|
87
88
|
const url = config.registryUrl.replace("{name}", options.name);
|
|
@@ -147,19 +148,30 @@ function writeCssVars({
|
|
|
147
148
|
const markerEnd = "/* uiscore:tokens:end */";
|
|
148
149
|
const nextBlock = buildCssVarBlock(cssVars, markerStart, markerEnd);
|
|
149
150
|
if (!existing) {
|
|
150
|
-
writeFileSync(outputPath,
|
|
151
|
+
writeFileSync(outputPath, `${UISCORE_FONT_IMPORT}
|
|
152
|
+
|
|
153
|
+
${nextBlock}`, "utf8");
|
|
151
154
|
return;
|
|
152
155
|
}
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
const withFontImport = existing.includes(UISCORE_FONT_IMPORT) ? existing : `${UISCORE_FONT_IMPORT}
|
|
157
|
+
|
|
158
|
+
${existing.trimStart()}`;
|
|
159
|
+
if (withFontImport.includes(markerStart) && withFontImport.includes(markerEnd)) {
|
|
160
|
+
const existingCssVars = parseCssVarsFromBlock(withFontImport, markerStart, markerEnd);
|
|
161
|
+
const mergedCssVars = {
|
|
162
|
+
...existingCssVars,
|
|
163
|
+
...cssVars
|
|
164
|
+
};
|
|
165
|
+
const mergedBlock = buildCssVarBlock(mergedCssVars, markerStart, markerEnd);
|
|
166
|
+
const updated = withFontImport.replace(
|
|
155
167
|
new RegExp(`${escapeForRegExp(markerStart)}[\\s\\S]*?${escapeForRegExp(markerEnd)}`),
|
|
156
|
-
|
|
168
|
+
mergedBlock.trimEnd()
|
|
157
169
|
);
|
|
158
170
|
writeFileSync(outputPath, `${updated.trimEnd()}
|
|
159
171
|
`, "utf8");
|
|
160
172
|
return;
|
|
161
173
|
}
|
|
162
|
-
writeFileSync(outputPath, `${
|
|
174
|
+
writeFileSync(outputPath, `${withFontImport.trimEnd()}
|
|
163
175
|
|
|
164
176
|
${nextBlock}`, "utf8");
|
|
165
177
|
}
|
|
@@ -172,6 +184,22 @@ ${vars}
|
|
|
172
184
|
${markerEnd}
|
|
173
185
|
`;
|
|
174
186
|
}
|
|
187
|
+
function parseCssVarsFromBlock(source, markerStart, markerEnd) {
|
|
188
|
+
const blockMatch = source.match(
|
|
189
|
+
new RegExp(
|
|
190
|
+
`${escapeForRegExp(markerStart)}([\\s\\S]*?)${escapeForRegExp(markerEnd)}`
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
if (!blockMatch) {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
const cssVars = {};
|
|
197
|
+
const matches = blockMatch[1].matchAll(/--([a-z0-9-]+)\s*:\s*([^;]+);/gi);
|
|
198
|
+
for (const match of matches) {
|
|
199
|
+
cssVars[match[1]] = match[2].trim();
|
|
200
|
+
}
|
|
201
|
+
return cssVars;
|
|
202
|
+
}
|
|
175
203
|
function escapeForRegExp(value) {
|
|
176
204
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
177
205
|
}
|