@ship-ui/core 0.15.40 → 0.16.0

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.
@@ -307,16 +307,49 @@ export const main = async (values) => {
307
307
  };
308
308
  }, {});
309
309
 
310
- const LIB_ICONS = packageJson.libraryIcons;
310
+ let LIB_ICONS = packageJson.libraryIcons;
311
+
312
+ try {
313
+ await textMateSnippet(GLYPH_MAP);
314
+ await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
315
+ } catch (error) {
316
+ console.error('An error occurred during the initial run:', error);
317
+ if (!values.watch && !values.watchLib) {
318
+ process.exit(1);
319
+ }
320
+ }
321
+
322
+ if (!values.watch && !values.watchLib) {
323
+ return;
324
+ }
325
+
326
+ console.log('\nWatching for file changes. Press Cmd+C to stop.');
311
327
  let watchers = [];
312
328
 
313
- await textMateSnippet(GLYPH_MAP);
329
+ function killWatchers() {
330
+ console.log(`\n✅ The icon font generation watch process has been stopped.`);
331
+
332
+ for (const watcher of watchers) {
333
+ watcher.close();
334
+ }
335
+
336
+ process.exit(0);
337
+ }
338
+
339
+ process.on('SIGINT', killWatchers);
340
+ process.on('SIGTERM', killWatchers);
341
+ process.on('SIGBREAK', killWatchers);
314
342
 
315
343
  if (values.watch) {
316
344
  const excludeFolders = ['node_modules', '.git', '.vscode', 'bin', 'assets'].concat([PROJECT_PUBLIC]);
317
- const watcher = watch(PROJECT_SRC, { recursive: true }, (_, filename) => {
345
+ const watcher = watch(PROJECT_SRC, { recursive: true }, async (_, filename) => {
318
346
  if (filename && !excludeFolders.some((folder) => resolve(join(PROJECT_SRC, filename)).includes(folder))) {
319
- run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
347
+ console.log(`Change detected in ${filename}, regenerating...`);
348
+ try {
349
+ await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
350
+ } catch (error) {
351
+ console.error('Error during watched run:', error);
352
+ }
320
353
  }
321
354
  });
322
355
 
@@ -325,29 +358,16 @@ export const main = async (values) => {
325
358
 
326
359
  if (values.watchLib) {
327
360
  const watcher = watch(packageJsonPath, {}, async (_, filename) => {
328
- const updatedPackageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
329
- const newLibIcons = updatedPackageJson.libraryIcons;
330
-
331
- run(PROJECT_SRC, newLibIcons, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
361
+ console.log(`Change detected in package.json, regenerating...`);
362
+ try {
363
+ const updatedPackageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
364
+ LIB_ICONS = updatedPackageJson.libraryIcons;
365
+ await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
366
+ } catch (error) {
367
+ console.error('Error during package.json watched run:', error);
368
+ }
332
369
  });
333
370
 
334
371
  watchers.push(watcher);
335
372
  }
336
-
337
- await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
338
-
339
- if (values.watch) {
340
- process.on('SIGINT', killWatchers);
341
- process.on('SIGTERM', killWatchers);
342
- process.on('SIGBREAK', killWatchers);
343
- }
344
- function killWatchers() {
345
- console.log(`✅ The icon font generation watch process has been stopped.`);
346
-
347
- for (const watcher of watchers) {
348
- watcher.close();
349
- }
350
-
351
- process.exit(0);
352
- }
353
373
  };
@@ -117,7 +117,6 @@ const run = async (
117
117
 
118
118
  writeCssFile(PROJECT_PUBLIC, values, groupedIcons, TARGET_FONT_TYPE);
119
119
 
120
- // We dont load fonts we dont use
121
120
  const fontTypes = ['bold', 'thin', 'light', 'fill', 'regular'].filter((x) => groupedIcons[x].length > 0);
122
121
  const targetFormat = (TARGET_FONT_TYPE as SupportedFontTypes) === 'ttf' ? 'truetype' : TARGET_FONT_TYPE;
123
122
  const fonts = fontTypes.map(async (fontType) => {
@@ -180,14 +179,13 @@ const run = async (
180
179
  };
181
180
 
182
181
  function uniqueString(s: string): string {
183
- const seen = new Set<string>(); // Use a Set to track seen characters
182
+ const seen = new Set<string>();
184
183
  let result = '';
185
184
 
186
185
  for (const char of s) {
187
186
  if (!seen.has(char)) {
188
- // Check if the character has been seen
189
- seen.add(char); // Add the character to the seen set
190
- result += char; // Append the character to the result
187
+ seen.add(char);
188
+ result += char;
191
189
  }
192
190
  }
193
191
 
@@ -226,12 +224,11 @@ sh-icon.${key} {
226
224
  font-family: 'sh${suffix}' !important;
227
225
  }`;
228
226
  });
229
- // Create a new css file
227
+
230
228
  const cssFileContent = `
231
229
  ${groupedIconsEntries.join('\n')}
232
230
  ${keys.join('\n')}
233
231
  sh-icon {
234
- /* use !important to prevent issues with browser extensions that change fonts */
235
232
  font-family: "sh" !important;
236
233
  speak: never;
237
234
  font-style: normal;
@@ -240,7 +237,6 @@ sh-icon {
240
237
  text-transform: none;
241
238
  line-height: 1;
242
239
 
243
- /* Enable Ligatures ================ */
244
240
  letter-spacing: 0;
245
241
  -webkit-font-feature-settings: "liga";
246
242
  -moz-font-feature-settings: "liga=1";
@@ -250,7 +246,6 @@ sh-icon {
250
246
  -webkit-font-variant-ligatures: discretionary-ligatures;
251
247
  font-variant-ligatures: discretionary-ligatures;
252
248
 
253
- /* Better Font Rendering =========== */
254
249
  -webkit-font-smoothing: antialiased;
255
250
  -moz-osx-font-smoothing: grayscale;
256
251
  }`;
@@ -293,6 +288,7 @@ export const main = async (values: InputArguments) => {
293
288
  const PROJECT_SRC = values.src;
294
289
  const PROJECT_PUBLIC = values.out;
295
290
  const fontVariants = ['bold', 'thin', 'light', 'fill', 'regular'];
291
+
296
292
  const GLYPH_MAPS = await Promise.all(
297
293
  fontVariants.map(async (fontVariant) => {
298
294
  const selectionJsonFullPath = path.resolve(
@@ -322,19 +318,51 @@ export const main = async (values: InputArguments) => {
322
318
  {} as Record<string, [string, string]>
323
319
  );
324
320
 
325
- const LIB_ICONS = packageJson.libraryIcons as string[];
321
+ let LIB_ICONS = packageJson.libraryIcons as string[];
322
+
323
+ try {
324
+ await textMateSnippet(GLYPH_MAP);
325
+ await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
326
+ } catch (error) {
327
+ console.error('An error occurred during the initial run:', error);
328
+ if (!values.watch && !values.watchLib) {
329
+ process.exit(1);
330
+ }
331
+ }
332
+
333
+ if (!values.watch && !values.watchLib) {
334
+ return;
335
+ }
336
+
337
+ console.log('\nWatching for file changes. Press Cmd+C to stop.');
326
338
  let watchers: FSWatcher[] = [];
327
339
 
328
- textMateSnippet(GLYPH_MAP);
340
+ function killWatchers() {
341
+ console.log(`\n✅ The icon font generation watch process has been stopped.`);
342
+
343
+ for (let index = 0; index < watchers.length; index++) {
344
+ const watcher = watchers[index];
345
+ watcher.close();
346
+ watcher.removeAllListeners();
347
+ }
348
+
349
+ process.exit(0);
350
+ }
351
+
352
+ process.on('SIGINT', killWatchers);
353
+ process.on('SIGTERM', killWatchers);
354
+ process.on('SIGBREAK', killWatchers);
329
355
 
330
356
  if (values.watch) {
331
357
  const excludeFolders = ['node_modules', '.git', '.vscode', 'bin', 'assets'].concat([PROJECT_PUBLIC]);
332
- const watcher = watch(PROJECT_SRC, { recursive: true }, (_, filename) => {
333
- if (
334
- filename && // Ensure filename is provided (can be null in some cases)
335
- !excludeFolders.some((folder) => resolve(join(PROJECT_SRC, filename)).includes(folder))
336
- ) {
337
- run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
358
+ const watcher = watch(PROJECT_SRC, { recursive: true }, async (_, filename) => {
359
+ if (filename && !excludeFolders.some((folder) => resolve(join(PROJECT_SRC, filename)).includes(folder))) {
360
+ console.log(`Change detected in ${filename}, regenerating...`);
361
+ try {
362
+ await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
363
+ } catch (error) {
364
+ console.error('Error during watched run:', error);
365
+ }
338
366
  }
339
367
  });
340
368
 
@@ -343,32 +371,16 @@ export const main = async (values: InputArguments) => {
343
371
 
344
372
  if (values.watchLib) {
345
373
  const watcher = watch(packageJsonPath, {}, async (_, filename) => {
346
- const packageJson = await Bun.file(packageJsonPath).json();
347
- const newLibIcons = packageJson.libraryIcons as string[];
348
-
349
- run(PROJECT_SRC, newLibIcons, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
374
+ console.log(`Change detected in package.json, regenerating...`);
375
+ try {
376
+ const packageJson = await Bun.file(packageJsonPath).json();
377
+ LIB_ICONS = packageJson.libraryIcons as string[];
378
+ await run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
379
+ } catch (error) {
380
+ console.error('Error during package.json watched run:', error);
381
+ }
350
382
  });
351
383
 
352
384
  watchers.push(watcher);
353
385
  }
354
-
355
- run(PROJECT_SRC, LIB_ICONS, PROJECT_PUBLIC, GLYPH_MAP, TARGET_FONT_TYPE, values);
356
-
357
- process.on('SIGKILL', killWatchers);
358
- process.on('SIGINT', killWatchers);
359
- process.on('SIGTERM', killWatchers);
360
- process.on('SIGBREAK', killWatchers);
361
-
362
- function killWatchers() {
363
- console.log(`✅ The icon font generation watch process has been stopped.`);
364
-
365
- for (let index = 0; index < watchers.length; index++) {
366
- const watcher = watchers[index];
367
-
368
- watcher.close();
369
- watcher.removeAllListeners();
370
- }
371
-
372
- process.exit(0);
373
- }
374
386
  };