@css-modules-kit/codegen 0.3.0 → 0.4.1
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/README.md +1 -0
- package/bin/cmk.mjs +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/runner.d.ts +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +6 -3
- package/dist/runner.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +4 -0
- package/src/runner.ts +11 -4
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ Options:
|
|
|
40
40
|
--version, -v Show version number
|
|
41
41
|
--project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
42
42
|
--pretty Enable color and formatting in output to make errors easier to read.
|
|
43
|
+
--clean Remove the output directory before generating files. [default: false]
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
## Configuration
|
package/bin/cmk.mjs
CHANGED
package/dist/cli.d.ts
CHANGED
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAgBA,wBAAgB,aAAa,IAAI,IAAI,CAGpC;AAED,wBAAgB,YAAY,IAAI,IAAI,CAGnC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAuBpE"}
|
package/dist/cli.js
CHANGED
|
@@ -18,6 +18,7 @@ Options:
|
|
|
18
18
|
--version, -v Show version number
|
|
19
19
|
--project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
20
20
|
--pretty Enable color and formatting in output to make errors easier to read.
|
|
21
|
+
--clean Remove the output directory before generating files. [default: false]
|
|
21
22
|
`;
|
|
22
23
|
function printHelpText() {
|
|
23
24
|
// eslint-disable-next-line no-console
|
|
@@ -40,6 +41,7 @@ function parseCLIArgs(args, cwd) {
|
|
|
40
41
|
version: { type: 'boolean', short: 'v', default: false },
|
|
41
42
|
project: { type: 'string', short: 'p', default: '.' },
|
|
42
43
|
pretty: { type: 'boolean' },
|
|
44
|
+
clean: { type: 'boolean', default: false },
|
|
43
45
|
},
|
|
44
46
|
allowNegative: true,
|
|
45
47
|
});
|
|
@@ -48,6 +50,7 @@ function parseCLIArgs(args, cwd) {
|
|
|
48
50
|
version: values.version,
|
|
49
51
|
project: (0, core_1.resolve)(cwd, values.project),
|
|
50
52
|
pretty: values.pretty,
|
|
53
|
+
clean: values.clean,
|
|
51
54
|
};
|
|
52
55
|
}
|
|
53
56
|
catch (cause) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAgBA,sCAGC;AAED,oCAGC;AAcD,oCAuBC;AA7DD,yCAAsC;AACtC,gDAAgD;AAChD,mEAA0C;AAC1C,yCAA+C;AAE/C,MAAM,QAAQ,GAAG;;;;;;;;;CAShB,CAAC;AAEF,SAAgB,aAAa;IAC3B,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACxB,CAAC;AAED,SAAgB,YAAY;IAC1B,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,sBAAW,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAUD;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAc,EAAE,GAAW;IACtD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,qBAAS,EAAC;YAC3B,IAAI;YACJ,OAAO,EAAE;gBACP,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;gBACrD,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE;gBACxD,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;gBACrD,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC3B,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;aAC3C;YACD,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,IAAA,cAAO,EAAC,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC;YACrC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,4BAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import type { Logger } from './logger/logger.js';
|
|
|
5
5
|
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
|
|
6
6
|
* @throws {WriteDtsFileError}
|
|
7
7
|
*/
|
|
8
|
-
export declare function runCMK(project: string, logger: Logger): Promise<void>;
|
|
8
|
+
export declare function runCMK(project: string, clean: boolean, logger: Logger): Promise<void>;
|
|
9
9
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAoCjD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiE3F"}
|
package/dist/runner.js
CHANGED
|
@@ -25,8 +25,8 @@ async function parseCSSModuleByFileName(fileName) {
|
|
|
25
25
|
/**
|
|
26
26
|
* @throws {WriteDtsFileError}
|
|
27
27
|
*/
|
|
28
|
-
async function writeDtsByCSSModule(cssModule, { dtsOutDir, basePath, arbitraryExtensions, namedExports }, resolver, matchesPattern) {
|
|
29
|
-
const dts = (0, core_1.createDts)(cssModule, { resolver, matchesPattern, namedExports });
|
|
28
|
+
async function writeDtsByCSSModule(cssModule, { dtsOutDir, basePath, arbitraryExtensions, namedExports, prioritizeNamedImports }, resolver, matchesPattern) {
|
|
29
|
+
const dts = (0, core_1.createDts)(cssModule, { resolver, matchesPattern }, { namedExports, prioritizeNamedImports, forTsPlugin: false });
|
|
30
30
|
await (0, dts_writer_js_1.writeDtsFile)(dts.text, cssModule.fileName, {
|
|
31
31
|
outDir: dtsOutDir,
|
|
32
32
|
basePath,
|
|
@@ -39,7 +39,7 @@ async function writeDtsByCSSModule(cssModule, { dtsOutDir, basePath, arbitraryEx
|
|
|
39
39
|
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
|
|
40
40
|
* @throws {WriteDtsFileError}
|
|
41
41
|
*/
|
|
42
|
-
async function runCMK(project, logger) {
|
|
42
|
+
async function runCMK(project, clean, logger) {
|
|
43
43
|
const config = (0, core_1.readConfigFile)(project);
|
|
44
44
|
if (config.diagnostics.length > 0) {
|
|
45
45
|
logger.logDiagnostics(config.diagnostics);
|
|
@@ -84,6 +84,9 @@ async function runCMK(project, logger) {
|
|
|
84
84
|
// eslint-disable-next-line n/no-process-exit
|
|
85
85
|
process.exit(1);
|
|
86
86
|
}
|
|
87
|
+
if (clean) {
|
|
88
|
+
await (0, promises_1.rm)(config.dtsOutDir, { recursive: true, force: true });
|
|
89
|
+
}
|
|
87
90
|
await Promise.all(parseResults.map(async (parseResult) => writeDtsByCSSModule(parseResult.cssModule, config, resolver, matchesPattern)));
|
|
88
91
|
}
|
|
89
92
|
//# sourceMappingURL=runner.js.map
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":";;;;;AAiEA,wBAiEC;AAlID,+CAAgD;AAUhD,gDAS+B;AAC/B,4DAA4B;AAC5B,mDAA+C;AAC/C,yCAAoD;AAGpD;;GAEG;AACH,KAAK,UAAU,wBAAwB,CAAC,QAAgB;IACtD,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,iCAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,IAAA,qBAAc,EAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KA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AAE,SAAS,EAAE,IAAI,YAAY,EAAE,CAAC;QACzC,MAAM,WAAW,GAAG,IAAA,qBAAc,EAAC,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;QACrG,mBAAmB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;QAC3C,6CAA6C;QAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAA,aAAE,EAAC,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CACf,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CACrC,mBAAmB,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,CAAC,CAC7E,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@css-modules-kit/codegen",
|
|
3
3
|
"description": "A tool for generating `*.d.ts` files for `*.module.css`.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"repository": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@css-modules-kit/core": "^0.
|
|
49
|
+
"@css-modules-kit/core": "^0.4.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"typescript": "^5.7.3"
|
package/src/cli.ts
CHANGED
|
@@ -11,6 +11,7 @@ Options:
|
|
|
11
11
|
--version, -v Show version number
|
|
12
12
|
--project, -p The path to its configuration file, or to a folder with a 'tsconfig.json'.
|
|
13
13
|
--pretty Enable color and formatting in output to make errors easier to read.
|
|
14
|
+
--clean Remove the output directory before generating files. [default: false]
|
|
14
15
|
`;
|
|
15
16
|
|
|
16
17
|
export function printHelpText(): void {
|
|
@@ -28,6 +29,7 @@ export interface ParsedArgs {
|
|
|
28
29
|
version: boolean;
|
|
29
30
|
project: string;
|
|
30
31
|
pretty: boolean | undefined;
|
|
32
|
+
clean: boolean;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -43,6 +45,7 @@ export function parseCLIArgs(args: string[], cwd: string): ParsedArgs {
|
|
|
43
45
|
version: { type: 'boolean', short: 'v', default: false },
|
|
44
46
|
project: { type: 'string', short: 'p', default: '.' },
|
|
45
47
|
pretty: { type: 'boolean' },
|
|
48
|
+
clean: { type: 'boolean', default: false },
|
|
46
49
|
},
|
|
47
50
|
allowNegative: true,
|
|
48
51
|
});
|
|
@@ -51,6 +54,7 @@ export function parseCLIArgs(args: string[], cwd: string): ParsedArgs {
|
|
|
51
54
|
version: values.version,
|
|
52
55
|
project: resolve(cwd, values.project),
|
|
53
56
|
pretty: values.pretty,
|
|
57
|
+
clean: values.clean,
|
|
54
58
|
};
|
|
55
59
|
} catch (cause) {
|
|
56
60
|
throw new ParseCLIArgsError(cause);
|
package/src/runner.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
1
|
+
import { readFile, rm } from 'node:fs/promises';
|
|
2
2
|
import type {
|
|
3
3
|
CMKConfig,
|
|
4
4
|
CSSModule,
|
|
@@ -41,11 +41,15 @@ async function parseCSSModuleByFileName(fileName: string): Promise<ParseCSSModul
|
|
|
41
41
|
*/
|
|
42
42
|
async function writeDtsByCSSModule(
|
|
43
43
|
cssModule: CSSModule,
|
|
44
|
-
{ dtsOutDir, basePath, arbitraryExtensions, namedExports }: CMKConfig,
|
|
44
|
+
{ dtsOutDir, basePath, arbitraryExtensions, namedExports, prioritizeNamedImports }: CMKConfig,
|
|
45
45
|
resolver: Resolver,
|
|
46
46
|
matchesPattern: MatchesPattern,
|
|
47
47
|
): Promise<void> {
|
|
48
|
-
const dts = createDts(
|
|
48
|
+
const dts = createDts(
|
|
49
|
+
cssModule,
|
|
50
|
+
{ resolver, matchesPattern },
|
|
51
|
+
{ namedExports, prioritizeNamedImports, forTsPlugin: false },
|
|
52
|
+
);
|
|
49
53
|
await writeDtsFile(dts.text, cssModule.fileName, {
|
|
50
54
|
outDir: dtsOutDir,
|
|
51
55
|
basePath,
|
|
@@ -59,7 +63,7 @@ async function writeDtsByCSSModule(
|
|
|
59
63
|
* @throws {ReadCSSModuleFileError} When failed to read CSS Module file.
|
|
60
64
|
* @throws {WriteDtsFileError}
|
|
61
65
|
*/
|
|
62
|
-
export async function runCMK(project: string, logger: Logger): Promise<void> {
|
|
66
|
+
export async function runCMK(project: string, clean: boolean, logger: Logger): Promise<void> {
|
|
63
67
|
const config = readConfigFile(project);
|
|
64
68
|
if (config.diagnostics.length > 0) {
|
|
65
69
|
logger.logDiagnostics(config.diagnostics);
|
|
@@ -116,6 +120,9 @@ export async function runCMK(project: string, logger: Logger): Promise<void> {
|
|
|
116
120
|
process.exit(1);
|
|
117
121
|
}
|
|
118
122
|
|
|
123
|
+
if (clean) {
|
|
124
|
+
await rm(config.dtsOutDir, { recursive: true, force: true });
|
|
125
|
+
}
|
|
119
126
|
await Promise.all(
|
|
120
127
|
parseResults.map(async (parseResult) =>
|
|
121
128
|
writeDtsByCSSModule(parseResult.cssModule, config, resolver, matchesPattern),
|