@digdir/designsystemet 1.12.1 → 1.13.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.
- package/dist/bin/config.d.ts +4 -4
- package/dist/bin/config.d.ts.map +1 -1
- package/dist/bin/config.js +133 -28
- package/dist/bin/designsystemet.d.ts.map +1 -1
- package/dist/bin/designsystemet.js +208 -149
- package/dist/src/config.d.ts +2 -2
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +4 -4
- package/dist/src/index.js +5 -5
- package/dist/src/migrations/beta-to-v1.js +122 -16
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
- package/dist/src/migrations/codemods/css/run.js +122 -16
- package/dist/src/migrations/color-rename-next49.js +122 -16
- package/dist/src/migrations/index.js +122 -16
- package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -1
- package/dist/src/scripts/update-preview-tokens.js +122 -45
- package/dist/src/tokens/build.d.ts +2 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +128 -62
- package/dist/src/tokens/create/files.d.ts +10 -0
- package/dist/src/tokens/create/files.d.ts.map +1 -0
- package/dist/src/tokens/create/{write.js → files.js} +143 -61
- package/dist/src/tokens/create/generators/$designsystemet.js +5 -5
- package/dist/src/tokens/format.js +5 -5
- package/dist/src/tokens/generate-config.d.ts +0 -1
- package/dist/src/tokens/generate-config.d.ts.map +1 -1
- package/dist/src/tokens/generate-config.js +145 -26
- package/dist/src/tokens/index.js +5 -5
- package/dist/src/tokens/process/output/declarations.js +5 -5
- package/dist/src/tokens/process/output/theme.js +5 -5
- package/dist/src/tokens/process/platform.d.ts +0 -4
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/types.d.ts +2 -0
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/utils/filesystem.d.ts +40 -0
- package/dist/src/utils/filesystem.d.ts.map +1 -0
- package/dist/src/utils/filesystem.js +127 -0
- package/package.json +6 -6
- package/dist/src/tokens/create/write.d.ts +0 -12
- package/dist/src/tokens/create/write.d.ts.map +0 -1
- package/dist/src/utils.d.ts +0 -18
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -70
package/dist/bin/config.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Command, OptionValues } from '@commander-js/extra-typings';
|
|
2
2
|
import { type BuildConfigSchema, type CreateConfigSchema } from '../src/config.js';
|
|
3
|
-
export declare function readConfigFile(
|
|
3
|
+
export declare function readConfigFile(configFilePath: string, allowFileNotFound?: boolean): Promise<string>;
|
|
4
4
|
export declare function parseCreateConfig(configFile: string, options: {
|
|
5
5
|
theme: string;
|
|
6
6
|
cmd: Command<unknown[], OptionValues>;
|
|
7
|
-
|
|
7
|
+
configFilePath: string;
|
|
8
8
|
}): Promise<CreateConfigSchema>;
|
|
9
|
-
export declare function parseBuildConfig(configFile: string, {
|
|
10
|
-
|
|
9
|
+
export declare function parseBuildConfig(configFile: string, { configFilePath }: {
|
|
10
|
+
configFilePath: string;
|
|
11
11
|
}): Promise<BuildConfigSchema>;
|
|
12
12
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/bin/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../bin/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../bin/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGzE,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAKxB,MAAM,kBAAkB,CAAC;AAI1B,wBAAsB,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,iBAAiB,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBtG;AAED,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,CAiE7B;AAED,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,MAAM,EAClB,EAAE,cAAc,EAAE,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,GAC7C,OAAO,CAAC,iBAAiB,CAAC,CAI5B"}
|
package/dist/bin/config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// bin/config.ts
|
|
2
|
-
import path2 from "path";
|
|
3
2
|
import pc3 from "picocolors";
|
|
4
3
|
import * as R8 from "ramda";
|
|
5
4
|
|
|
@@ -360,24 +359,24 @@ function makeFriendlyError(err) {
|
|
|
360
359
|
console.error(err instanceof Error ? err.stack : "No stack trace available");
|
|
361
360
|
}
|
|
362
361
|
}
|
|
363
|
-
function validateConfig(schema, unvalidatedConfig,
|
|
362
|
+
function validateConfig(schema, unvalidatedConfig, configFilePath) {
|
|
364
363
|
try {
|
|
365
364
|
return schema.parse(unvalidatedConfig);
|
|
366
365
|
} catch (err) {
|
|
367
|
-
console.error(pc.redBright(`Invalid config file at ${pc.red(
|
|
366
|
+
console.error(pc.redBright(`Invalid config file at ${pc.red(configFilePath)}`));
|
|
368
367
|
const validationError = makeFriendlyError(err);
|
|
369
368
|
console.error(validationError?.toString());
|
|
370
369
|
process.exit(1);
|
|
371
370
|
}
|
|
372
371
|
}
|
|
373
|
-
function parseConfig(configFile,
|
|
372
|
+
function parseConfig(configFile, configFilePath) {
|
|
374
373
|
if (!configFile) {
|
|
375
374
|
return {};
|
|
376
375
|
}
|
|
377
376
|
try {
|
|
378
377
|
return JSON.parse(configFile);
|
|
379
378
|
} catch (err) {
|
|
380
|
-
console.error(pc.redBright(`Failed parsing config file at ${pc.red(
|
|
379
|
+
console.error(pc.redBright(`Failed parsing config file at ${pc.red(configFilePath)}`));
|
|
381
380
|
const validationError = makeFriendlyError(err);
|
|
382
381
|
console.error(validationError?.toString());
|
|
383
382
|
process.exit(1);
|
|
@@ -456,23 +455,130 @@ var _configFileCreateSchema = z.object({
|
|
|
456
455
|
}).required();
|
|
457
456
|
var configFileCreateSchema = _configFileCreateSchema.extend(commonConfig.shape);
|
|
458
457
|
|
|
459
|
-
// src/utils.ts
|
|
458
|
+
// src/utils/filesystem.ts
|
|
460
459
|
import fs from "fs/promises";
|
|
460
|
+
import path2 from "path";
|
|
461
461
|
import pc2 from "picocolors";
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
462
|
+
var FileSystem = class {
|
|
463
|
+
isInitialized = false;
|
|
464
|
+
dry = false;
|
|
465
|
+
verbose = false;
|
|
466
|
+
/** Default working directory is where the process was started */
|
|
467
|
+
workingDir = process.cwd();
|
|
468
|
+
outDir = this.workingDir;
|
|
469
|
+
/** Initialize the file system */
|
|
470
|
+
init({ dry, outdir, verbose }) {
|
|
471
|
+
if (this.isInitialized) {
|
|
472
|
+
console.warn(pc2.yellow("FileSystem is already initialized. Ignoring subsequent init call."));
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (dry) {
|
|
476
|
+
console.log(pc2.blue("Initializing FileSystem in dry-run mode. No files will be written."));
|
|
472
477
|
}
|
|
473
|
-
|
|
478
|
+
this.dry = dry ?? false;
|
|
479
|
+
this.verbose = verbose ?? false;
|
|
480
|
+
this.outDir = outdir ? path2.isAbsolute(outdir) ? outdir : path2.join(this.workingDir, outdir) : this.workingDir;
|
|
481
|
+
if (this.verbose) {
|
|
482
|
+
console.log(
|
|
483
|
+
`FileSystem initialized with workingDir: ${pc2.green(this.workingDir)}, outDir: ${pc2.green(this.outDir)}`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
this.isInitialized = true;
|
|
474
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Creates a directory if it does not already exist.
|
|
490
|
+
*
|
|
491
|
+
* @param dir - The path of the directory to create.
|
|
492
|
+
*
|
|
493
|
+
* @returns A promise that resolves when the operation is complete.
|
|
494
|
+
* If the directory already exists or `dry` is `true`, the promise resolves immediately.
|
|
495
|
+
*/
|
|
496
|
+
mkdir = async (dir) => {
|
|
497
|
+
if (this.dry) {
|
|
498
|
+
console.log(`${pc2.blue("mkdir")} ${dir}`);
|
|
499
|
+
return Promise.resolve();
|
|
500
|
+
}
|
|
501
|
+
const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
502
|
+
if (exists) {
|
|
503
|
+
return Promise.resolve();
|
|
504
|
+
}
|
|
505
|
+
return fs.mkdir(dir, { recursive: true });
|
|
506
|
+
};
|
|
507
|
+
writeFile = async (path3, data) => {
|
|
508
|
+
if (this.dry) {
|
|
509
|
+
console.log(`${pc2.blue("writeFile")} ${path3}`);
|
|
510
|
+
return Promise.resolve();
|
|
511
|
+
}
|
|
512
|
+
return fs.writeFile(path3, data, { encoding: "utf-8" }).catch((error) => {
|
|
513
|
+
console.error(pc2.red(`Error writing file: ${path3}`));
|
|
514
|
+
console.error(pc2.red(error));
|
|
515
|
+
throw error;
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
cp = async (src, dest, filter) => {
|
|
519
|
+
if (this.dry) {
|
|
520
|
+
console.log(`${pc2.blue("cp")} ${src} ${dest}`);
|
|
521
|
+
return Promise.resolve();
|
|
522
|
+
}
|
|
523
|
+
return fs.cp(src, dest, { recursive: true, filter });
|
|
524
|
+
};
|
|
525
|
+
copyFile = async (src, dest) => {
|
|
526
|
+
if (this.dry) {
|
|
527
|
+
console.log(`${pc2.blue("copyFile")} ${src} to ${dest}`);
|
|
528
|
+
return Promise.resolve();
|
|
529
|
+
}
|
|
530
|
+
return fs.copyFile(src, dest);
|
|
531
|
+
};
|
|
532
|
+
cleanDir = async (dir) => {
|
|
533
|
+
if (this.dry) {
|
|
534
|
+
console.log(`${pc2.blue("cleanDir")} ${dir}`);
|
|
535
|
+
return Promise.resolve();
|
|
536
|
+
}
|
|
537
|
+
console.log(`
|
|
538
|
+
\u{1F525} Cleaning dir ${pc2.red(`${dir.trim()}`)} `);
|
|
539
|
+
return fs.rm(dir, { recursive: true, force: true });
|
|
540
|
+
};
|
|
541
|
+
readFile = async (path3, allowFileNotFound) => {
|
|
542
|
+
if (this.dry) {
|
|
543
|
+
console.log(`${pc2.blue("readFile")} ${path3}`);
|
|
544
|
+
}
|
|
545
|
+
try {
|
|
546
|
+
return await fs.readFile(path3, "utf-8");
|
|
547
|
+
} catch (error) {
|
|
548
|
+
if (allowFileNotFound && error.code === "ENOENT") {
|
|
549
|
+
return "";
|
|
550
|
+
}
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
readdir = async (path3) => {
|
|
555
|
+
if (this.dry) {
|
|
556
|
+
console.log(`${pc2.blue("readdir")} ${path3}`);
|
|
557
|
+
}
|
|
558
|
+
try {
|
|
559
|
+
return await fs.readdir(path3);
|
|
560
|
+
} catch (error) {
|
|
561
|
+
if (error.code === "ENOENT") {
|
|
562
|
+
return [];
|
|
563
|
+
}
|
|
564
|
+
throw error;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
writeFiles = async (files, outDir, log) => {
|
|
568
|
+
for (const { destination: filename, output } of files) {
|
|
569
|
+
if (filename) {
|
|
570
|
+
const filePath = path2.join(outDir, filename);
|
|
571
|
+
const fileDir = path2.dirname(filePath);
|
|
572
|
+
if (log) {
|
|
573
|
+
console.log(filename);
|
|
574
|
+
}
|
|
575
|
+
await this.mkdir(fileDir);
|
|
576
|
+
await this.writeFile(filePath, output);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
475
580
|
};
|
|
581
|
+
var dsfs = new FileSystem();
|
|
476
582
|
|
|
477
583
|
// bin/options.ts
|
|
478
584
|
var getOptionIfMatchingSource = (...sources) => (command, option) => {
|
|
@@ -486,26 +592,25 @@ var getDefaultCliOption = getOptionIfMatchingSource("default");
|
|
|
486
592
|
var getCliOption = getOptionIfMatchingSource("cli", "default");
|
|
487
593
|
|
|
488
594
|
// bin/config.ts
|
|
489
|
-
async function readConfigFile(
|
|
490
|
-
const resolvedPath = path2.resolve(process.cwd(), configPath);
|
|
595
|
+
async function readConfigFile(configFilePath, allowFileNotFound = true) {
|
|
491
596
|
let configFile;
|
|
492
597
|
try {
|
|
493
|
-
configFile = await readFile(
|
|
598
|
+
configFile = await dsfs.readFile(configFilePath, allowFileNotFound);
|
|
494
599
|
} catch (err) {
|
|
495
600
|
if (allowFileNotFound) {
|
|
496
601
|
return "";
|
|
497
602
|
}
|
|
498
|
-
console.error(pc3.redBright(`Could not read config file at ${pc3.blue(
|
|
603
|
+
console.error(pc3.redBright(`Could not read config file at ${pc3.blue(configFilePath)}`));
|
|
499
604
|
throw err;
|
|
500
605
|
}
|
|
501
606
|
if (configFile) {
|
|
502
|
-
console.log(`Found config file: ${pc3.green(
|
|
607
|
+
console.log(`Found config file: ${pc3.green(configFilePath)}`);
|
|
503
608
|
}
|
|
504
609
|
return configFile;
|
|
505
610
|
}
|
|
506
611
|
async function parseCreateConfig(configFile, options) {
|
|
507
|
-
const { cmd, theme = "theme",
|
|
508
|
-
const configParsed = parseConfig(configFile,
|
|
612
|
+
const { cmd, theme = "theme", configFilePath } = options;
|
|
613
|
+
const configParsed = parseConfig(configFile, configFilePath);
|
|
509
614
|
const themeColors = Object.values(configParsed?.themes ?? {}).map(
|
|
510
615
|
(x) => /* @__PURE__ */ new Set([...R8.keys(x.colors.main), ...R8.keys(x.colors.support)])
|
|
511
616
|
);
|
|
@@ -548,11 +653,11 @@ async function parseCreateConfig(configFile, options) {
|
|
|
548
653
|
}
|
|
549
654
|
)
|
|
550
655
|
});
|
|
551
|
-
return validateConfig(configFileCreateSchema, unvalidatedConfig,
|
|
656
|
+
return validateConfig(configFileCreateSchema, unvalidatedConfig, configFilePath);
|
|
552
657
|
}
|
|
553
|
-
async function parseBuildConfig(configFile, {
|
|
554
|
-
const configParsed = parseConfig(configFile,
|
|
555
|
-
return validateConfig(commonConfig, configParsed,
|
|
658
|
+
async function parseBuildConfig(configFile, { configFilePath }) {
|
|
659
|
+
const configParsed = parseConfig(configFile, configFilePath);
|
|
660
|
+
return validateConfig(commonConfig, configParsed, configFilePath);
|
|
556
661
|
}
|
|
557
662
|
export {
|
|
558
663
|
parseBuildConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"designsystemet.d.ts","sourceRoot":"","sources":["../../bin/designsystemet.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"designsystemet.d.ts","sourceRoot":"","sources":["../../bin/designsystemet.ts"],"names":[],"mappings":";AAgBA,eAAO,MAAM,WAAW,4iBASvB,CAAC"}
|