nobadfonts-cli 1.1.6 → 1.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/index.js +16 -41
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -133,7 +133,10 @@ async function addFont(fontName) {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
if (mainFileDownloaded) {
|
|
136
|
-
|
|
136
|
+
// Only add main variant if "regular" is NOT present in variants to avoid duplicates
|
|
137
|
+
const hasRegular = font.font_variants && font.font_variants.some(v => v.variant_name.toLowerCase().includes('regular'));
|
|
138
|
+
if (!hasRegular) {
|
|
139
|
+
cssContent.push(`
|
|
137
140
|
@font-face {
|
|
138
141
|
font-family: '${font.name}';
|
|
139
142
|
src: ${mainCssSrc.join(',\n ')};
|
|
@@ -142,6 +145,7 @@ async function addFont(fontName) {
|
|
|
142
145
|
font-display: swap;
|
|
143
146
|
}
|
|
144
147
|
`);
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
// Download Variants
|
|
@@ -160,12 +164,15 @@ async function addFont(fontName) {
|
|
|
160
164
|
let style = 'normal';
|
|
161
165
|
const nameLower = variant.variant_name.toLowerCase();
|
|
162
166
|
|
|
163
|
-
if (nameLower.includes('bold')) weight = 700;
|
|
164
|
-
if (nameLower.includes('light')) weight = 300;
|
|
165
|
-
if (nameLower.includes('medium')) weight = 500;
|
|
166
|
-
if (nameLower.includes('black')) weight = 900;
|
|
167
167
|
if (nameLower.includes('thin')) weight = 100;
|
|
168
|
-
if (nameLower.includes('extra')) weight =
|
|
168
|
+
else if (nameLower.includes('extra light') || nameLower.includes('extralight')) weight = 200;
|
|
169
|
+
else if (nameLower.includes('light')) weight = 300;
|
|
170
|
+
else if (nameLower.includes('regular')) weight = 400;
|
|
171
|
+
else if (nameLower.includes('medium')) weight = 500;
|
|
172
|
+
else if (nameLower.includes('semi bold') || nameLower.includes('semibold')) weight = 600;
|
|
173
|
+
else if (nameLower.includes('extra bold') || nameLower.includes('extrabold')) weight = 800;
|
|
174
|
+
else if (nameLower.includes('bold')) weight = 700;
|
|
175
|
+
else if (nameLower.includes('black')) weight = 900;
|
|
169
176
|
|
|
170
177
|
if (nameLower.includes('italic')) style = 'italic';
|
|
171
178
|
|
|
@@ -215,45 +222,13 @@ ${cssContent.join('\n')}
|
|
|
215
222
|
if (!existingCss.includes(`Font: ${font.name}`)) {
|
|
216
223
|
await fs.outputFile(outputCssPath, existingCss + newCssBlock);
|
|
217
224
|
spinner.succeed(chalk.green(`Updated src/fonts.css with @font-face definitions.`));
|
|
225
|
+
console.log(chalk.blue(`\nSuccess! To use the font, add this to your CSS:`));
|
|
226
|
+
console.log(chalk.cyan(`font-family: '${font.name}', sans-serif;`));
|
|
227
|
+
console.log(chalk.gray(`(Make sure to import './fonts.css' in your main execution file)`));
|
|
218
228
|
} else {
|
|
219
229
|
spinner.info(chalk.yellow(`Font ${font.name} definitions already exist in src/fonts.css`));
|
|
220
230
|
}
|
|
221
231
|
|
|
222
|
-
// Update src/index.css with @theme variable
|
|
223
|
-
const indexCssPath = path.join(process.cwd(), 'src', 'index.css');
|
|
224
|
-
if (await fs.pathExists(indexCssPath)) {
|
|
225
|
-
let indexCss = await fs.readFile(indexCssPath, 'utf8');
|
|
226
|
-
const variableName = `--font-${font.slug}`;
|
|
227
|
-
const variableValue = `"${font.name}", sans-serif;`;
|
|
228
|
-
|
|
229
|
-
if (indexCss.includes('@theme {')) {
|
|
230
|
-
if (!indexCss.includes(variableName)) {
|
|
231
|
-
const themeStart = indexCss.indexOf('@theme {');
|
|
232
|
-
const insertPos = themeStart + '@theme {'.length;
|
|
233
|
-
const newEntry = `\n ${variableName}: ${variableValue}`;
|
|
234
|
-
indexCss = indexCss.slice(0, insertPos) + newEntry + indexCss.slice(insertPos);
|
|
235
|
-
|
|
236
|
-
await fs.writeFile(indexCssPath, indexCss);
|
|
237
|
-
spinner.succeed(chalk.green(`Added ${variableName} to src/index.css @theme block.`));
|
|
238
|
-
} else {
|
|
239
|
-
spinner.info(chalk.yellow(`Variable ${variableName} already exists in src/index.css`));
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
const newThemeBlock = `
|
|
243
|
-
@theme {
|
|
244
|
-
${variableName}: ${variableValue}
|
|
245
|
-
}
|
|
246
|
-
`;
|
|
247
|
-
await fs.appendFile(indexCssPath, newThemeBlock);
|
|
248
|
-
spinner.succeed(chalk.green(`Created @theme block in src/index.css with ${variableName}.`));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
console.log(chalk.blue(`\nSuccess! To use the font:`));
|
|
253
|
-
console.log(chalk.cyan(`1. In CSS: font-family: var(--font-${font.slug});`));
|
|
254
|
-
console.log(chalk.cyan(`2. In Tailwind: class="font-${font.slug}"`));
|
|
255
|
-
console.log(chalk.gray(`(Make sure to import './fonts.css' in your main execution file)`));
|
|
256
|
-
|
|
257
232
|
} catch (error) {
|
|
258
233
|
spinner.fail(chalk.red(`Error: ${error.message}`));
|
|
259
234
|
}
|