@scania/tegel 1.17.0-local-assets-beta.2 → 1.17.0-local-assets-beta.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/package.json +5 -1
- package/scripts/copy-fonts.mjs +88 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scania/tegel",
|
|
3
|
-
"version": "1.17.0-local-assets-beta.
|
|
3
|
+
"version": "1.17.0-local-assets-beta.4",
|
|
4
4
|
"description": "Tegel Design System",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -363,6 +363,9 @@
|
|
|
363
363
|
"publishConfig": {
|
|
364
364
|
"access": "public"
|
|
365
365
|
},
|
|
366
|
+
"bin": {
|
|
367
|
+
"copy-fonts": "./scripts/copy-fonts.mjs"
|
|
368
|
+
},
|
|
366
369
|
"scripts": {
|
|
367
370
|
"build": "stencil build && stencil build --docs",
|
|
368
371
|
"_comment": "Due to stencil bug with types creation, we need to run build two times!",
|
|
@@ -372,6 +375,7 @@
|
|
|
372
375
|
"update-snapshots": "docker run --rm --network host -v $(pwd):/work/ -w /work/ mcr.microsoft.com/playwright:v1.46.1-jammy /bin/bash -c 'npm install && npx playwright test --update-snapshots && exit'",
|
|
373
376
|
"test.watch": "stencil test --spec --e2e --watchAll",
|
|
374
377
|
"generate": "stencil generate",
|
|
378
|
+
"copy-fonts": "node scripts/copy-fonts.mjs",
|
|
375
379
|
"build-stencil:watch": "stencil build --docs-readme --watch",
|
|
376
380
|
"commit": "npm run --prefix ../ commit",
|
|
377
381
|
"build-storybook": "build-storybook --quiet",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
const currentFilePath = fileURLToPath(import.meta.url);
|
|
7
|
+
const currentDirPath = path.dirname(currentFilePath);
|
|
8
|
+
|
|
9
|
+
// Configuration options
|
|
10
|
+
const config = {
|
|
11
|
+
defaultTargetDir: 'public/assets/fonts',
|
|
12
|
+
dryRun: false, // Set to false to actually copy files
|
|
13
|
+
verbose: false // Set to false to reduce console output
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Get custom path from command line argument, if provided
|
|
17
|
+
const targetDir = path.resolve(process.cwd(), process.argv[2] || config.defaultTargetDir);
|
|
18
|
+
|
|
19
|
+
// Define the source directory for fonts in the package
|
|
20
|
+
const sourceDir = path.join(currentDirPath, '..', '..', '..', 'assets', 'fonts');
|
|
21
|
+
|
|
22
|
+
function copyFonts(src, dest) {
|
|
23
|
+
if (config.verbose) console.log(`Checking directory: ${src}`);
|
|
24
|
+
|
|
25
|
+
if (!fs.existsSync(src)) {
|
|
26
|
+
console.error(`Source directory does not exist: ${src}`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!config.dryRun && !fs.existsSync(dest)) {
|
|
31
|
+
if (config.verbose) console.log(`Creating directory: ${dest}`);
|
|
32
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
37
|
+
|
|
38
|
+
for (let entry of entries) {
|
|
39
|
+
const srcPath = path.join(src, entry.name);
|
|
40
|
+
const destPath = path.join(dest, entry.name);
|
|
41
|
+
|
|
42
|
+
if (entry.isDirectory()) {
|
|
43
|
+
copyFonts(srcPath, destPath);
|
|
44
|
+
} else if (entry.isFile() && (path.extname(entry.name) === '.woff' || path.extname(entry.name) === '.woff2')) {
|
|
45
|
+
if (config.dryRun) {
|
|
46
|
+
console.log(`Would copy: ${srcPath} to ${destPath}`);
|
|
47
|
+
} else {
|
|
48
|
+
fs.copyFileSync(srcPath, destPath);
|
|
49
|
+
console.log(`Copied: ${destPath}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(`Error accessing directory ${src}:`, error.message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log('Font copying script started');
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(sourceDir)) {
|
|
61
|
+
console.error(`Error: Source directory does not exist: ${sourceDir}`);
|
|
62
|
+
console.log('Please check if the fonts directory exists in the assets folder of the package.');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(`Source directory: ${sourceDir}`);
|
|
67
|
+
console.log(`Target directory: ${targetDir}`);
|
|
68
|
+
console.log(`Dry run: ${config.dryRun ? 'Yes' : 'No'}`);
|
|
69
|
+
|
|
70
|
+
// Copy fonts from both cyrillic and latin subdirectories
|
|
71
|
+
['cyrillic', 'latin'].forEach(subdir => {
|
|
72
|
+
const subSourceDir = path.join(sourceDir, subdir);
|
|
73
|
+
const subTargetDir = path.join(targetDir, subdir);
|
|
74
|
+
|
|
75
|
+
if (fs.existsSync(subSourceDir)) {
|
|
76
|
+
copyFonts(subSourceDir, subTargetDir);
|
|
77
|
+
} else {
|
|
78
|
+
console.warn(`Warning: ${subdir} subdirectory not found in source.`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
console.log('Font copying process complete!');
|
|
83
|
+
if (config.dryRun) {
|
|
84
|
+
console.log('This was a dry run. No files were actually copied.');
|
|
85
|
+
console.log('To actually copy files, set dryRun to false in the config.');
|
|
86
|
+
}
|
|
87
|
+
console.log(`Target directory: ${targetDir}`);
|
|
88
|
+
console.log('Please ensure your application is configured to serve static files from this location.');
|