@wyw-in-js/cli 1.0.8 → 2.0.0-alpha.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/bin/wyw-in-js.js +2 -2
- package/esm/diagnostics.js +14 -0
- package/esm/diagnostics.js.map +1 -0
- package/esm/metadata.js +18 -0
- package/esm/metadata.js.map +1 -0
- package/esm/wyw-in-js.js +192 -174
- package/esm/wyw-in-js.js.map +1 -1
- package/package.json +16 -11
- package/types/diagnostics.d.ts +3 -0
- package/types/diagnostics.js +16 -0
- package/types/metadata.d.ts +15 -0
- package/types/metadata.js +19 -0
- package/types/wyw-in-js.js +57 -36
- package/lib/wyw-in-js.js +0 -188
- package/lib/wyw-in-js.js.map +0 -1
package/bin/wyw-in-js.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const formatLocation = (diagnostic) => {
|
|
2
|
+
if (!diagnostic.start) {
|
|
3
|
+
return diagnostic.filename;
|
|
4
|
+
}
|
|
5
|
+
return `${diagnostic.filename}:${diagnostic.start.line}:${diagnostic.start.column + 1}`;
|
|
6
|
+
};
|
|
7
|
+
export const formatTransformDiagnostic = (diagnostic) => [`[wyw-in-js] ${diagnostic.severity} [${diagnostic.category}] ${diagnostic.message}`, ` at ${formatLocation(diagnostic)} (${diagnostic.displayName})`].join("\n");
|
|
8
|
+
export const reportTransformDiagnostics = (diagnostics) => {
|
|
9
|
+
diagnostics.forEach((diagnostic) => {
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
console.warn(formatTransformDiagnostic(diagnostic));
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAEA,MAAM,kBAAkB,eAAuC;AAC7D,KAAI,CAAC,WAAW,OAAO;AACrB,SAAO,WAAW;;AAGpB,QAAO,GAAG,WAAW,SAAS,GAAG,WAAW,MAAM,KAAK,GACrD,WAAW,MAAM,SAAS;;AAI9B,OAAO,MAAM,6BAA6B,eACxC,CACE,eAAe,WAAW,SAAS,IAAI,WAAW,SAAS,IAAI,WAAW,WAC1E,QAAQ,eAAe,WAAW,CAAC,IAAI,WAAW,YAAY,GAC/D,CAAC,KAAK,KAAK;AAEd,OAAO,MAAM,8BACX,gBACG;AACH,aAAY,SAAS,eAAe;;AAElC,UAAQ,KAAK,0BAA0B,WAAW,CAAC;GACnD","names":[],"sources":["../src/diagnostics.ts"],"version":3,"sourcesContent":["import type { WYWTransformDiagnostic } from '@wyw-in-js/transform';\n\nconst formatLocation = (diagnostic: WYWTransformDiagnostic) => {\n if (!diagnostic.start) {\n return diagnostic.filename;\n }\n\n return `${diagnostic.filename}:${diagnostic.start.line}:${\n diagnostic.start.column + 1\n }`;\n};\n\nexport const formatTransformDiagnostic = (diagnostic: WYWTransformDiagnostic) =>\n [\n `[wyw-in-js] ${diagnostic.severity} [${diagnostic.category}] ${diagnostic.message}`,\n ` at ${formatLocation(diagnostic)} (${diagnostic.displayName})`,\n ].join('\\n');\n\nexport const reportTransformDiagnostics = (\n diagnostics: WYWTransformDiagnostic[]\n) => {\n diagnostics.forEach((diagnostic) => {\n // eslint-disable-next-line no-console\n console.warn(formatTransformDiagnostic(diagnostic));\n });\n};\n"],"file":"diagnostics.js"}
|
package/esm/metadata.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import normalize from "normalize-path";
|
|
3
|
+
import { createTransformManifest, stringifyTransformManifest } from "@wyw-in-js/transform";
|
|
4
|
+
export function resolveMetadataFilename(outputFilename) {
|
|
5
|
+
const extension = path.extname(outputFilename);
|
|
6
|
+
return `${outputFilename.slice(0, -extension.length)}.wyw-in-js.json`;
|
|
7
|
+
}
|
|
8
|
+
export function createMetadataFile({ metadata, outputRoot, outputFilename, sourceRoot, sourceFilename, cssFile }) {
|
|
9
|
+
const filename = resolveMetadataFilename(outputFilename);
|
|
10
|
+
return {
|
|
11
|
+
content: stringifyTransformManifest(createTransformManifest(metadata, {
|
|
12
|
+
cssFile: cssFile ? normalize(path.relative(outputRoot, cssFile)) : undefined,
|
|
13
|
+
source: normalize(path.relative(sourceRoot, sourceFilename))
|
|
14
|
+
})),
|
|
15
|
+
filename
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,OAAO,UAAU;AAEjB,OAAO,eAAe;AAGtB,SACE,yBACA,kCACK;AAWP,OAAO,SAAS,wBAAwB,gBAAwB;CAC9D,MAAM,YAAY,KAAK,QAAQ,eAAe;AAC9C,QAAO,GAAG,eAAe,MAAM,GAAG,CAAC,UAAU,OAAO,CAAC;;AAGvD,OAAO,SAAS,mBAAmB,EACjC,UACA,YACA,gBACA,YACA,gBACA,WAC4B;CAC5B,MAAM,WAAW,wBAAwB,eAAe;AAExD,QAAO;EACL,SAAS,2BACP,wBAAwB,UAAU;GAChC,SAAS,UACL,UAAU,KAAK,SAAS,YAAY,QAAQ,CAAC,GAC7C;GACJ,QAAQ,UAAU,KAAK,SAAS,YAAY,eAAe,CAAC;GAC7D,CAAC,CACH;EACD;EACD","names":[],"sources":["../src/metadata.ts"],"version":3,"sourcesContent":["import path from 'path';\n\nimport normalize from 'normalize-path';\n\nimport type { WYWTransformResultMetadata } from '@wyw-in-js/transform';\nimport {\n createTransformManifest,\n stringifyTransformManifest,\n} from '@wyw-in-js/transform';\n\ntype CreateMetadataFileOptions = {\n cssFile?: string;\n metadata: WYWTransformResultMetadata;\n outputRoot: string;\n outputFilename: string;\n sourceRoot: string;\n sourceFilename: string;\n};\n\nexport function resolveMetadataFilename(outputFilename: string) {\n const extension = path.extname(outputFilename);\n return `${outputFilename.slice(0, -extension.length)}.wyw-in-js.json`;\n}\n\nexport function createMetadataFile({\n metadata,\n outputRoot,\n outputFilename,\n sourceRoot,\n sourceFilename,\n cssFile,\n}: CreateMetadataFileOptions) {\n const filename = resolveMetadataFilename(outputFilename);\n\n return {\n content: stringifyTransformManifest(\n createTransformManifest(metadata, {\n cssFile: cssFile\n ? normalize(path.relative(outputRoot, cssFile))\n : undefined,\n source: normalize(path.relative(sourceRoot, sourceFilename)),\n })\n ),\n filename,\n };\n}\n"],"file":"metadata.js"}
|
package/esm/wyw-in-js.js
CHANGED
|
@@ -1,184 +1,202 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}).option(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}).option(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}).option(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}).
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
3
|
+
* This file contains a CLI for wyw-in-js.
|
|
4
|
+
*/
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { asyncResolveFallback } from "@wyw-in-js/shared";
|
|
8
|
+
import { createFileReporter, TransformCacheCollection, transform } from "@wyw-in-js/transform";
|
|
9
|
+
import { globSync } from "glob";
|
|
10
|
+
import mkdirp from "mkdirp";
|
|
11
|
+
import normalize from "normalize-path";
|
|
12
|
+
import yargs from "yargs";
|
|
13
|
+
import { reportTransformDiagnostics } from "./diagnostics.js";
|
|
14
|
+
import { createMetadataFile } from "./metadata.js";
|
|
15
|
+
const modulesOptions = [
|
|
16
|
+
"commonjs",
|
|
17
|
+
"es2015",
|
|
18
|
+
"es6",
|
|
19
|
+
"esnext",
|
|
20
|
+
"native"
|
|
21
|
+
];
|
|
22
|
+
const argv = yargs.usage("Usage: $0 [options] <files ...>").option("config", {
|
|
23
|
+
alias: "c",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Path to a config file",
|
|
26
|
+
requiresArg: true,
|
|
27
|
+
coerce: path.resolve
|
|
28
|
+
}).option("debug", {
|
|
29
|
+
alias: "d",
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Path for debug output",
|
|
32
|
+
coerce: path.resolve
|
|
33
|
+
}).option("out-dir", {
|
|
34
|
+
alias: "o",
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Output directory for the extracted CSS files",
|
|
37
|
+
demandOption: true,
|
|
38
|
+
requiresArg: true,
|
|
39
|
+
coerce: path.resolve
|
|
40
|
+
}).option("source-maps", {
|
|
41
|
+
alias: "s",
|
|
42
|
+
type: "boolean",
|
|
43
|
+
description: "Generate source maps for the CSS files",
|
|
44
|
+
default: false
|
|
45
|
+
}).option("parallel", {
|
|
46
|
+
alias: "p",
|
|
47
|
+
type: "boolean",
|
|
48
|
+
description: "Run extraction in parallel",
|
|
49
|
+
default: false
|
|
50
|
+
}).option("output-metadata", {
|
|
51
|
+
type: "boolean",
|
|
52
|
+
description: "Emit sidecar .wyw-in-js.json metadata manifests for transformed files"
|
|
53
|
+
}).option("source-root", {
|
|
54
|
+
alias: "r",
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "Directory containing the source JS files",
|
|
57
|
+
demandOption: true,
|
|
58
|
+
requiresArg: true,
|
|
59
|
+
coerce: path.resolve
|
|
60
|
+
}).option("insert-css-requires", {
|
|
61
|
+
alias: "i",
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Directory containing JS files to insert require statements for the CSS files",
|
|
64
|
+
requiresArg: true,
|
|
65
|
+
coerce: path.resolve
|
|
66
|
+
}).option("transform", {
|
|
67
|
+
alias: "t",
|
|
68
|
+
type: "boolean",
|
|
69
|
+
description: "Replace template tags with evaluated values"
|
|
70
|
+
}).option("modules", {
|
|
71
|
+
alias: "m",
|
|
72
|
+
choices: modulesOptions,
|
|
73
|
+
description: "Specifies a type of used imports",
|
|
74
|
+
default: "commonjs",
|
|
75
|
+
coerce: (s) => s.toLowerCase()
|
|
76
|
+
}).implies("insert-css-requires", "source-root").implies("transform", "insert-css-requires").option("ignore", {
|
|
77
|
+
alias: "x",
|
|
78
|
+
type: "string",
|
|
79
|
+
description: "Pattern of files to ignore. Be sure to provide a string",
|
|
80
|
+
requiresArg: true
|
|
81
|
+
}).alias("help", "h").alias("version", "v").parseSync();
|
|
72
82
|
function resolveRequireInsertionFilename(filename) {
|
|
73
|
-
|
|
83
|
+
return filename.replace(/\.tsx?/, ".js");
|
|
74
84
|
}
|
|
75
85
|
function resolveOutputFilename(filename, outDir, sourceRoot) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
const outputFolder = path.relative(sourceRoot, path.dirname(filename));
|
|
87
|
+
const outputBasename = path.basename(filename).replace(path.extname(filename), ".css");
|
|
88
|
+
return path.join(outDir, outputFolder, outputBasename);
|
|
79
89
|
}
|
|
80
90
|
async function processFiles(files, options) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
91
|
+
const { emitter, onDone } = createFileReporter(options.debug ? {
|
|
92
|
+
dir: options.debug,
|
|
93
|
+
print: true
|
|
94
|
+
} : false);
|
|
95
|
+
const resolvedFiles = files.reduce((acc, pattern) => [...acc, ...globSync(pattern.toString(), {
|
|
96
|
+
absolute: true,
|
|
97
|
+
ignore: options.ignore
|
|
98
|
+
})], []);
|
|
99
|
+
const cache = new TransformCacheCollection();
|
|
100
|
+
const modifiedFiles = [];
|
|
101
|
+
const tasks = [];
|
|
102
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
103
|
+
for (const filename of resolvedFiles) {
|
|
104
|
+
if (fs.lstatSync(filename).isDirectory()) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const outputFilename = resolveOutputFilename(filename, options.outDir, options.sourceRoot);
|
|
108
|
+
const transformServices = {
|
|
109
|
+
options: {
|
|
110
|
+
filename,
|
|
111
|
+
outputFilename,
|
|
112
|
+
pluginOptions: {
|
|
113
|
+
configFile: options.configFile,
|
|
114
|
+
outputMetadata: options.outputMetadata
|
|
115
|
+
},
|
|
116
|
+
root: options.sourceRoot
|
|
117
|
+
},
|
|
118
|
+
cache,
|
|
119
|
+
eventEmitter: emitter
|
|
120
|
+
};
|
|
121
|
+
tasks.push(() => transform(transformServices, fs.readFileSync(filename).toString(), asyncResolveFallback).then(({ code, cssText, diagnostics, metadata, sourceMap, cssSourceMapText }) => {
|
|
122
|
+
if (diagnostics?.length) {
|
|
123
|
+
reportTransformDiagnostics(diagnostics);
|
|
124
|
+
}
|
|
125
|
+
const shouldWriteCss = typeof cssText === "string" && cssText.length > 0;
|
|
126
|
+
if (!shouldWriteCss && !metadata) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
mkdirp.sync(path.dirname(outputFilename));
|
|
130
|
+
if (metadata) {
|
|
131
|
+
const metadataFile = createMetadataFile({
|
|
132
|
+
cssFile: shouldWriteCss ? outputFilename : undefined,
|
|
133
|
+
metadata,
|
|
134
|
+
outputRoot: options.outDir,
|
|
135
|
+
outputFilename,
|
|
136
|
+
sourceRoot: options.sourceRoot,
|
|
137
|
+
sourceFilename: filename
|
|
138
|
+
});
|
|
139
|
+
fs.writeFileSync(metadataFile.filename, metadataFile.content);
|
|
140
|
+
}
|
|
141
|
+
if (!shouldWriteCss) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
const cssContent = options.sourceMaps && sourceMap ? `${cssText}\n/*# sourceMappingURL=${outputFilename}.map */` : cssText;
|
|
145
|
+
fs.writeFileSync(outputFilename, cssContent);
|
|
146
|
+
if (options.sourceMaps && sourceMap && typeof cssSourceMapText !== "undefined") {
|
|
147
|
+
fs.writeFileSync(`${outputFilename}.map`, cssSourceMapText);
|
|
148
|
+
}
|
|
149
|
+
if (options.sourceRoot && options.insertCssRequires) {
|
|
150
|
+
const inputFilename = path.resolve(options.insertCssRequires, path.relative(options.sourceRoot, filename));
|
|
151
|
+
const relativePath = normalize(path.relative(path.dirname(inputFilename), outputFilename));
|
|
152
|
+
const pathForImport = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
153
|
+
const statement = options.modules === "commonjs" ? `\nrequire('${pathForImport}');` : `\nimport "${pathForImport}";`;
|
|
154
|
+
const normalizedInputFilename = resolveRequireInsertionFilename(inputFilename);
|
|
155
|
+
const inputContent = options.transform ? code : fs.readFileSync(normalizedInputFilename, "utf-8");
|
|
156
|
+
if (!inputContent.trim().endsWith(statement)) {
|
|
157
|
+
modifiedFiles.push({
|
|
158
|
+
name: normalizedInputFilename,
|
|
159
|
+
content: `${inputContent}\n${statement}\n`
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
if (options.parallel) {
|
|
167
|
+
const res = await Promise.all(tasks.map((task) => task()));
|
|
168
|
+
console.log(`Successfully extracted ${res.filter((i) => i).length} CSS files.`);
|
|
169
|
+
} else {
|
|
170
|
+
let count = 0;
|
|
171
|
+
for (const task of tasks) {
|
|
172
|
+
// eslint-disable-next-line no-await-in-loop
|
|
173
|
+
const res = await task();
|
|
174
|
+
if (res) {
|
|
175
|
+
count += 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
console.log(`Successfully extracted ${count} CSS files.`);
|
|
179
|
+
}
|
|
180
|
+
modifiedFiles.forEach(({ name, content }) => {
|
|
181
|
+
fs.writeFileSync(name, content);
|
|
182
|
+
});
|
|
183
|
+
cache.clear("all");
|
|
184
|
+
modifiedFiles.length = 0;
|
|
185
|
+
resolvedFiles.length = 0;
|
|
186
|
+
tasks.length = 0;
|
|
187
|
+
onDone(options.sourceRoot ?? process.cwd());
|
|
171
188
|
}
|
|
172
189
|
processFiles(argv._, {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
190
|
+
configFile: argv.config,
|
|
191
|
+
debug: argv.debug,
|
|
192
|
+
ignore: argv.ignore,
|
|
193
|
+
insertCssRequires: argv["insert-css-requires"],
|
|
194
|
+
modules: argv.modules,
|
|
195
|
+
parallel: argv.parallel,
|
|
196
|
+
outDir: argv["out-dir"],
|
|
197
|
+
outputMetadata: argv["output-metadata"],
|
|
198
|
+
sourceMaps: argv["source-maps"],
|
|
199
|
+
sourceRoot: argv["source-root"],
|
|
200
|
+
transform: argv.transform
|
|
183
201
|
});
|
|
184
|
-
//# sourceMappingURL=wyw-in-js.js.map
|
|
202
|
+
//# sourceMappingURL=wyw-in-js.js.map
|
package/esm/wyw-in-js.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wyw-in-js.js","names":["fs","path","asyncResolveFallback","createFileReporter","TransformCacheCollection","transform","globSync","mkdirp","normalize","yargs","modulesOptions","argv","usage","option","alias","type","description","requiresArg","coerce","resolve","demandOption","default","choices","s","toLowerCase","implies","parseSync","resolveRequireInsertionFilename","filename","replace","resolveOutputFilename","outDir","sourceRoot","outputFolder","relative","dirname","outputBasename","basename","extname","join","processFiles","files","options","emitter","onDone","debug","dir","print","resolvedFiles","reduce","acc","pattern","toString","absolute","ignore","cache","modifiedFiles","tasks","lstatSync","isDirectory","outputFilename","transformServices","pluginOptions","configFile","root","eventEmitter","push","readFileSync","then","code","cssText","sourceMap","cssSourceMapText","sync","cssContent","sourceMaps","writeFileSync","insertCssRequires","inputFilename","relativePath","pathForImport","startsWith","statement","modules","normalizedInputFilename","inputContent","trim","endsWith","name","content","parallel","res","Promise","all","map","task","console","log","filter","i","length","count","forEach","clear","process","cwd","_","config"],"sources":["../src/wyw-in-js.ts"],"sourcesContent":["/* eslint-disable no-console */\n/**\n * This file contains a CLI for wyw-in-js.\n */\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { asyncResolveFallback } from '@wyw-in-js/shared';\nimport {\n createFileReporter,\n TransformCacheCollection,\n transform,\n} from '@wyw-in-js/transform';\nimport { globSync } from 'glob';\nimport mkdirp from 'mkdirp';\nimport normalize from 'normalize-path';\nimport yargs from 'yargs';\n\nconst modulesOptions = [\n 'commonjs',\n 'es2015',\n 'es6',\n 'esnext',\n 'native',\n] as const;\n\nconst argv = yargs\n .usage('Usage: $0 [options] <files ...>')\n .option('config', {\n alias: 'c',\n type: 'string',\n description: 'Path to a config file',\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('debug', {\n alias: 'd',\n type: 'string',\n description: 'Path for debug output',\n coerce: path.resolve,\n })\n .option('out-dir', {\n alias: 'o',\n type: 'string',\n description: 'Output directory for the extracted CSS files',\n demandOption: true,\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('source-maps', {\n alias: 's',\n type: 'boolean',\n description: 'Generate source maps for the CSS files',\n default: false,\n })\n .option('parallel', {\n alias: 'p',\n type: 'boolean',\n description: 'Run extraction in parallel',\n default: false,\n })\n .option('source-root', {\n alias: 'r',\n type: 'string',\n description: 'Directory containing the source JS files',\n demandOption: true,\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('insert-css-requires', {\n alias: 'i',\n type: 'string',\n description:\n 'Directory containing JS files to insert require statements for the CSS files',\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('transform', {\n alias: 't',\n type: 'boolean',\n description: 'Replace template tags with evaluated values',\n })\n .option('modules', {\n alias: 'm',\n choices: modulesOptions,\n description: 'Specifies a type of used imports',\n default: 'commonjs' as const,\n coerce: (s) => s.toLowerCase(),\n })\n .implies('insert-css-requires', 'source-root')\n .implies('transform', 'insert-css-requires')\n .option('ignore', {\n alias: 'x',\n type: 'string',\n description: 'Pattern of files to ignore. Be sure to provide a string',\n requiresArg: true,\n })\n .alias('help', 'h')\n .alias('version', 'v')\n .parseSync();\n\ntype Options = {\n configFile?: string;\n debug?: string;\n ignore?: string;\n insertCssRequires?: string;\n modules: (typeof modulesOptions)[number];\n outDir: string;\n parallel?: boolean;\n sourceMaps?: boolean;\n sourceRoot: string;\n transform?: boolean;\n};\n\nfunction resolveRequireInsertionFilename(filename: string) {\n return filename.replace(/\\.tsx?/, '.js');\n}\n\nfunction resolveOutputFilename(\n filename: string,\n outDir: string,\n sourceRoot: string\n) {\n const outputFolder = path.relative(sourceRoot, path.dirname(filename));\n const outputBasename = path\n .basename(filename)\n .replace(path.extname(filename), '.css');\n\n return path.join(outDir, outputFolder, outputBasename);\n}\n\nasync function processFiles(files: (number | string)[], options: Options) {\n const { emitter, onDone } = createFileReporter(\n options.debug ? { dir: options.debug, print: true } : false\n );\n\n const resolvedFiles = files.reduce(\n (acc, pattern) => [\n ...acc,\n ...globSync(pattern.toString(), {\n absolute: true,\n ignore: options.ignore,\n }),\n ],\n [] as string[]\n );\n const cache = new TransformCacheCollection();\n\n const modifiedFiles: { content: string; name: string }[] = [];\n\n const tasks: (() => Promise<boolean>)[] = [];\n\n // eslint-disable-next-line no-restricted-syntax\n for (const filename of resolvedFiles) {\n if (fs.lstatSync(filename).isDirectory()) {\n return;\n }\n\n const outputFilename = resolveOutputFilename(\n filename,\n options.outDir,\n options.sourceRoot\n );\n\n const transformServices = {\n options: {\n filename,\n outputFilename,\n pluginOptions: {\n configFile: options.configFile,\n },\n root: options.sourceRoot,\n },\n cache,\n eventEmitter: emitter,\n };\n\n tasks.push(() =>\n transform(\n transformServices,\n fs.readFileSync(filename).toString(),\n asyncResolveFallback\n ).then(({ code, cssText, sourceMap, cssSourceMapText }): boolean => {\n if (!cssText) {\n return false;\n }\n mkdirp.sync(path.dirname(outputFilename));\n\n const cssContent =\n options.sourceMaps && sourceMap\n ? `${cssText}\\n/*# sourceMappingURL=${outputFilename}.map */`\n : cssText;\n\n fs.writeFileSync(outputFilename, cssContent);\n\n if (\n options.sourceMaps &&\n sourceMap &&\n typeof cssSourceMapText !== 'undefined'\n ) {\n fs.writeFileSync(`${outputFilename}.map`, cssSourceMapText);\n }\n\n if (options.sourceRoot && options.insertCssRequires) {\n const inputFilename = path.resolve(\n options.insertCssRequires,\n path.relative(options.sourceRoot, filename)\n );\n\n const relativePath = normalize(\n path.relative(path.dirname(inputFilename), outputFilename)\n );\n\n const pathForImport = relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n\n const statement =\n options.modules === 'commonjs'\n ? `\\nrequire('${pathForImport}');`\n : `\\nimport \"${pathForImport}\";`;\n\n const normalizedInputFilename =\n resolveRequireInsertionFilename(inputFilename);\n\n const inputContent = options.transform\n ? code\n : fs.readFileSync(normalizedInputFilename, 'utf-8');\n\n if (!inputContent.trim().endsWith(statement)) {\n modifiedFiles.push({\n name: normalizedInputFilename,\n content: `${inputContent}\\n${statement}\\n`,\n });\n }\n }\n\n return true;\n })\n );\n }\n\n if (options.parallel) {\n const res = await Promise.all(tasks.map((task) => task()));\n console.log(\n `Successfully extracted ${res.filter((i) => i).length} CSS files.`\n );\n } else {\n let count = 0;\n for (const task of tasks) {\n // eslint-disable-next-line no-await-in-loop\n const res = await task();\n if (res) {\n count += 1;\n }\n }\n\n console.log(`Successfully extracted ${count} CSS files.`);\n }\n\n modifiedFiles.forEach(({ name, content }) => {\n fs.writeFileSync(name, content);\n });\n\n cache.clear('all');\n modifiedFiles.length = 0;\n resolvedFiles.length = 0;\n tasks.length = 0;\n\n onDone(options.sourceRoot ?? process.cwd());\n}\n\nprocessFiles(argv._, {\n configFile: argv.config,\n debug: argv.debug,\n ignore: argv.ignore,\n insertCssRequires: argv['insert-css-requires'],\n modules: argv.modules,\n parallel: argv.parallel,\n outDir: argv['out-dir'],\n sourceMaps: argv['source-maps'],\n sourceRoot: argv['source-root'],\n transform: argv.transform,\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAEvB,SAASC,oBAAoB,QAAQ,mBAAmB;AACxD,SACEC,kBAAkB,EAClBC,wBAAwB,EACxBC,SAAS,QACJ,sBAAsB;AAC7B,SAASC,QAAQ,QAAQ,MAAM;AAC/B,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAOC,KAAK,MAAM,OAAO;AAEzB,MAAMC,cAAc,GAAG,CACrB,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,QAAQ,CACA;AAEV,MAAMC,IAAI,GAAGF,KAAK,CACfG,KAAK,CAAC,iCAAiC,CAAC,CACxCC,MAAM,CAAC,QAAQ,EAAE;EAChBC,KAAK,EAAE,GAAG;EACVC,IAAI,EAAE,QAAQ;EACdC,WAAW,EAAE,uBAAuB;EACpCC,WAAW,EAAE,IAAI;EACjBC,MAAM,EAAEjB,IAAI,CAACkB;AACf,CAAC,CAAC,CACDN,MAAM,CAAC,OAAO,EAAE;EACfC,KAAK,EAAE,GAAG;EACVC,IAAI,EAAE,QAAQ;EACdC,WAAW,EAAE,uBAAuB;EACpCE,MAAM,EAAEjB,IAAI,CAACkB;AACf,CAAC,CAAC,CACDN,MAAM,CAAC,SAAS,EAAE;EACjBC,KAAK,EAAE,GAAG;EACVC,IAAI,EAAE,QAAQ;EACdC,WAAW,EAAE,8CAA8C;EAC3DI,YAAY,EAAE,IAAI;EAClBH,WAAW,EAAE,IAAI;EACjBC,MAAM,EAAEjB,IAAI,CAACkB;AACf,CAAC,CAAC,CACDN,MAAM,CAAC,aAAa,EAAE;EACrBC,KAAK,EAAE,GAAG;EACVC,IAAI,EAAE,SAAS;EACf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AM,CAAC,CAAC;AAC1D,UAAQ,IACN,0BAA0B,IAAI,QAAQ,MAAM,EAAE,CAAC,OAAO,aACvD;QACI;EACL,IAAI,QAAQ;AACZ,OAAK,MAAM,QAAQ,OAAO;;GAExB,MAAM,MAAM,MAAM,MAAM;AACxB,OAAI,KAAK;AACP,aAAS;;;AAIb,UAAQ,IAAI,0BAA0B,MAAM,aAAa;;AAG3D,eAAc,SAAS,EAAE,MAAM,cAAc;AAC3C,KAAG,cAAc,MAAM,QAAQ;GAC/B;AAEF,OAAM,MAAM,MAAM;AAClB,eAAc,SAAS;AACvB,eAAc,SAAS;AACvB,OAAM,SAAS;AAEf,QAAO,QAAQ,cAAc,QAAQ,KAAK,CAAC;;AAG7C,aAAa,KAAK,GAAG;CACnB,YAAY,KAAK;CACjB,OAAO,KAAK;CACZ,QAAQ,KAAK;CACb,mBAAmB,KAAK;CACxB,SAAS,KAAK;CACd,UAAU,KAAK;CACf,QAAQ,KAAK;CACb,gBAAgB,KAAK;CACrB,YAAY,KAAK;CACjB,YAAY,KAAK;CACjB,WAAW,KAAK;CACjB,CAAC","names":[],"sources":["../src/wyw-in-js.ts"],"version":3,"sourcesContent":["/* eslint-disable no-console */\n/**\n * This file contains a CLI for wyw-in-js.\n */\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { asyncResolveFallback } from '@wyw-in-js/shared';\nimport {\n createFileReporter,\n TransformCacheCollection,\n transform,\n} from '@wyw-in-js/transform';\nimport { globSync } from 'glob';\nimport mkdirp from 'mkdirp';\nimport normalize from 'normalize-path';\nimport yargs from 'yargs';\n\nimport { reportTransformDiagnostics } from './diagnostics';\nimport { createMetadataFile } from './metadata';\n\nconst modulesOptions = [\n 'commonjs',\n 'es2015',\n 'es6',\n 'esnext',\n 'native',\n] as const;\n\nconst argv = yargs\n .usage('Usage: $0 [options] <files ...>')\n .option('config', {\n alias: 'c',\n type: 'string',\n description: 'Path to a config file',\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('debug', {\n alias: 'd',\n type: 'string',\n description: 'Path for debug output',\n coerce: path.resolve,\n })\n .option('out-dir', {\n alias: 'o',\n type: 'string',\n description: 'Output directory for the extracted CSS files',\n demandOption: true,\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('source-maps', {\n alias: 's',\n type: 'boolean',\n description: 'Generate source maps for the CSS files',\n default: false,\n })\n .option('parallel', {\n alias: 'p',\n type: 'boolean',\n description: 'Run extraction in parallel',\n default: false,\n })\n .option('output-metadata', {\n type: 'boolean',\n description:\n 'Emit sidecar .wyw-in-js.json metadata manifests for transformed files',\n })\n .option('source-root', {\n alias: 'r',\n type: 'string',\n description: 'Directory containing the source JS files',\n demandOption: true,\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('insert-css-requires', {\n alias: 'i',\n type: 'string',\n description:\n 'Directory containing JS files to insert require statements for the CSS files',\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('transform', {\n alias: 't',\n type: 'boolean',\n description: 'Replace template tags with evaluated values',\n })\n .option('modules', {\n alias: 'm',\n choices: modulesOptions,\n description: 'Specifies a type of used imports',\n default: 'commonjs' as const,\n coerce: (s) => s.toLowerCase(),\n })\n .implies('insert-css-requires', 'source-root')\n .implies('transform', 'insert-css-requires')\n .option('ignore', {\n alias: 'x',\n type: 'string',\n description: 'Pattern of files to ignore. Be sure to provide a string',\n requiresArg: true,\n })\n .alias('help', 'h')\n .alias('version', 'v')\n .parseSync();\n\ntype Options = {\n configFile?: string;\n debug?: string;\n ignore?: string;\n insertCssRequires?: string;\n modules: (typeof modulesOptions)[number];\n outDir: string;\n outputMetadata?: boolean;\n parallel?: boolean;\n sourceMaps?: boolean;\n sourceRoot: string;\n transform?: boolean;\n};\n\nfunction resolveRequireInsertionFilename(filename: string) {\n return filename.replace(/\\.tsx?/, '.js');\n}\n\nfunction resolveOutputFilename(\n filename: string,\n outDir: string,\n sourceRoot: string\n) {\n const outputFolder = path.relative(sourceRoot, path.dirname(filename));\n const outputBasename = path\n .basename(filename)\n .replace(path.extname(filename), '.css');\n\n return path.join(outDir, outputFolder, outputBasename);\n}\n\nasync function processFiles(files: (number | string)[], options: Options) {\n const { emitter, onDone } = createFileReporter(\n options.debug ? { dir: options.debug, print: true } : false\n );\n\n const resolvedFiles = files.reduce(\n (acc, pattern) => [\n ...acc,\n ...globSync(pattern.toString(), {\n absolute: true,\n ignore: options.ignore,\n }),\n ],\n [] as string[]\n );\n const cache = new TransformCacheCollection();\n\n const modifiedFiles: { content: string; name: string }[] = [];\n\n const tasks: (() => Promise<boolean>)[] = [];\n\n // eslint-disable-next-line no-restricted-syntax\n for (const filename of resolvedFiles) {\n if (fs.lstatSync(filename).isDirectory()) {\n return;\n }\n\n const outputFilename = resolveOutputFilename(\n filename,\n options.outDir,\n options.sourceRoot\n );\n\n const transformServices = {\n options: {\n filename,\n outputFilename,\n pluginOptions: {\n configFile: options.configFile,\n outputMetadata: options.outputMetadata,\n },\n root: options.sourceRoot,\n },\n cache,\n eventEmitter: emitter,\n };\n\n tasks.push(() =>\n transform(\n transformServices,\n fs.readFileSync(filename).toString(),\n asyncResolveFallback\n ).then(\n ({\n code,\n cssText,\n diagnostics,\n metadata,\n sourceMap,\n cssSourceMapText,\n }): boolean => {\n if (diagnostics?.length) {\n reportTransformDiagnostics(diagnostics);\n }\n\n const shouldWriteCss =\n typeof cssText === 'string' && cssText.length > 0;\n\n if (!shouldWriteCss && !metadata) {\n return false;\n }\n\n mkdirp.sync(path.dirname(outputFilename));\n\n if (metadata) {\n const metadataFile = createMetadataFile({\n cssFile: shouldWriteCss ? outputFilename : undefined,\n metadata,\n outputRoot: options.outDir,\n outputFilename,\n sourceRoot: options.sourceRoot,\n sourceFilename: filename,\n });\n\n fs.writeFileSync(metadataFile.filename, metadataFile.content);\n }\n\n if (!shouldWriteCss) {\n return false;\n }\n\n const cssContent =\n options.sourceMaps && sourceMap\n ? `${cssText}\\n/*# sourceMappingURL=${outputFilename}.map */`\n : cssText;\n\n fs.writeFileSync(outputFilename, cssContent);\n\n if (\n options.sourceMaps &&\n sourceMap &&\n typeof cssSourceMapText !== 'undefined'\n ) {\n fs.writeFileSync(`${outputFilename}.map`, cssSourceMapText);\n }\n\n if (options.sourceRoot && options.insertCssRequires) {\n const inputFilename = path.resolve(\n options.insertCssRequires,\n path.relative(options.sourceRoot, filename)\n );\n\n const relativePath = normalize(\n path.relative(path.dirname(inputFilename), outputFilename)\n );\n\n const pathForImport = relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n\n const statement =\n options.modules === 'commonjs'\n ? `\\nrequire('${pathForImport}');`\n : `\\nimport \"${pathForImport}\";`;\n\n const normalizedInputFilename =\n resolveRequireInsertionFilename(inputFilename);\n\n const inputContent = options.transform\n ? code\n : fs.readFileSync(normalizedInputFilename, 'utf-8');\n\n if (!inputContent.trim().endsWith(statement)) {\n modifiedFiles.push({\n name: normalizedInputFilename,\n content: `${inputContent}\\n${statement}\\n`,\n });\n }\n }\n\n return true;\n }\n )\n );\n }\n\n if (options.parallel) {\n const res = await Promise.all(tasks.map((task) => task()));\n console.log(\n `Successfully extracted ${res.filter((i) => i).length} CSS files.`\n );\n } else {\n let count = 0;\n for (const task of tasks) {\n // eslint-disable-next-line no-await-in-loop\n const res = await task();\n if (res) {\n count += 1;\n }\n }\n\n console.log(`Successfully extracted ${count} CSS files.`);\n }\n\n modifiedFiles.forEach(({ name, content }) => {\n fs.writeFileSync(name, content);\n });\n\n cache.clear('all');\n modifiedFiles.length = 0;\n resolvedFiles.length = 0;\n tasks.length = 0;\n\n onDone(options.sourceRoot ?? process.cwd());\n}\n\nprocessFiles(argv._, {\n configFile: argv.config,\n debug: argv.debug,\n ignore: argv.ignore,\n insertCssRequires: argv['insert-css-requires'],\n modules: argv.modules,\n parallel: argv.parallel,\n outDir: argv['out-dir'],\n outputMetadata: argv['output-metadata'],\n sourceMaps: argv['source-maps'],\n sourceRoot: argv['source-root'],\n transform: argv.transform,\n});\n"],"file":"wyw-in-js.js"}
|
package/package.json
CHANGED
|
@@ -1,45 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"bin": {
|
|
5
6
|
"wyw-in-js": "bin/wyw-in-js.js"
|
|
6
7
|
},
|
|
7
8
|
"dependencies": {
|
|
8
|
-
"@wyw-in-js/shared": "
|
|
9
|
-
"@wyw-in-js/transform": "
|
|
9
|
+
"@wyw-in-js/shared": "2.0.0-alpha.0",
|
|
10
|
+
"@wyw-in-js/transform": "2.0.0-alpha.0",
|
|
10
11
|
"glob": "^10.3.10",
|
|
11
12
|
"mkdirp": "^0.5.1",
|
|
12
13
|
"normalize-path": "^3.0.0",
|
|
13
14
|
"yargs": "^17.5.0"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
|
-
"@babel/core": "^7.23.5",
|
|
17
17
|
"@types/mkdirp": "^0.5.2",
|
|
18
18
|
"@types/normalize-path": "^3.0.0",
|
|
19
19
|
"@types/yargs": "^17.0.10",
|
|
20
|
-
"@wyw-in-js/babel-config": "workspace:*",
|
|
21
20
|
"@wyw-in-js/eslint-config": "workspace:*",
|
|
22
21
|
"@wyw-in-js/ts-config": "workspace:*"
|
|
23
22
|
},
|
|
24
23
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
24
|
+
"node": ">=22.0.0"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./types/wyw-in-js.d.ts",
|
|
29
|
+
"default": "./esm/wyw-in-js.js"
|
|
30
|
+
}
|
|
26
31
|
},
|
|
27
32
|
"files": [
|
|
33
|
+
"bin/",
|
|
28
34
|
"esm/",
|
|
29
|
-
"lib/",
|
|
30
35
|
"types/"
|
|
31
36
|
],
|
|
32
37
|
"license": "MIT",
|
|
33
|
-
"main": "
|
|
38
|
+
"main": "esm/wyw-in-js.js",
|
|
34
39
|
"module": "esm/wyw-in-js.js",
|
|
35
40
|
"publishConfig": {
|
|
36
41
|
"access": "public"
|
|
37
42
|
},
|
|
38
43
|
"scripts": {
|
|
39
|
-
"build:esm": "
|
|
40
|
-
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
44
|
+
"build:esm": "node ../../scripts/build-esm-oxc.mjs",
|
|
41
45
|
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
42
|
-
"lint": "eslint --ext .js,.ts ."
|
|
46
|
+
"lint": "eslint --ext .js,.ts .",
|
|
47
|
+
"test": "bun test src"
|
|
43
48
|
},
|
|
44
49
|
"types": "types/wyw-in-js.d.ts",
|
|
45
50
|
"repository": {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const formatLocation = (diagnostic) => {
|
|
2
|
+
if (!diagnostic.start) {
|
|
3
|
+
return diagnostic.filename;
|
|
4
|
+
}
|
|
5
|
+
return `${diagnostic.filename}:${diagnostic.start.line}:${diagnostic.start.column + 1}`;
|
|
6
|
+
};
|
|
7
|
+
export const formatTransformDiagnostic = (diagnostic) => [
|
|
8
|
+
`[wyw-in-js] ${diagnostic.severity} [${diagnostic.category}] ${diagnostic.message}`,
|
|
9
|
+
` at ${formatLocation(diagnostic)} (${diagnostic.displayName})`,
|
|
10
|
+
].join('\n');
|
|
11
|
+
export const reportTransformDiagnostics = (diagnostics) => {
|
|
12
|
+
diagnostics.forEach((diagnostic) => {
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
console.warn(formatTransformDiagnostic(diagnostic));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WYWTransformResultMetadata } from '@wyw-in-js/transform';
|
|
2
|
+
type CreateMetadataFileOptions = {
|
|
3
|
+
cssFile?: string;
|
|
4
|
+
metadata: WYWTransformResultMetadata;
|
|
5
|
+
outputRoot: string;
|
|
6
|
+
outputFilename: string;
|
|
7
|
+
sourceRoot: string;
|
|
8
|
+
sourceFilename: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function resolveMetadataFilename(outputFilename: string): string;
|
|
11
|
+
export declare function createMetadataFile({ metadata, outputRoot, outputFilename, sourceRoot, sourceFilename, cssFile, }: CreateMetadataFileOptions): {
|
|
12
|
+
content: string;
|
|
13
|
+
filename: string;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import normalize from 'normalize-path';
|
|
3
|
+
import { createTransformManifest, stringifyTransformManifest, } from '@wyw-in-js/transform';
|
|
4
|
+
export function resolveMetadataFilename(outputFilename) {
|
|
5
|
+
const extension = path.extname(outputFilename);
|
|
6
|
+
return `${outputFilename.slice(0, -extension.length)}.wyw-in-js.json`;
|
|
7
|
+
}
|
|
8
|
+
export function createMetadataFile({ metadata, outputRoot, outputFilename, sourceRoot, sourceFilename, cssFile, }) {
|
|
9
|
+
const filename = resolveMetadataFilename(outputFilename);
|
|
10
|
+
return {
|
|
11
|
+
content: stringifyTransformManifest(createTransformManifest(metadata, {
|
|
12
|
+
cssFile: cssFile
|
|
13
|
+
? normalize(path.relative(outputRoot, cssFile))
|
|
14
|
+
: undefined,
|
|
15
|
+
source: normalize(path.relative(sourceRoot, sourceFilename)),
|
|
16
|
+
})),
|
|
17
|
+
filename,
|
|
18
|
+
};
|
|
19
|
+
}
|
package/types/wyw-in-js.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable no-console */
|
|
3
2
|
/**
|
|
4
3
|
* This file contains a CLI for wyw-in-js.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
17
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { asyncResolveFallback } from '@wyw-in-js/shared';
|
|
8
|
+
import { createFileReporter, TransformCacheCollection, transform, } from '@wyw-in-js/transform';
|
|
9
|
+
import { globSync } from 'glob';
|
|
10
|
+
import mkdirp from 'mkdirp';
|
|
11
|
+
import normalize from 'normalize-path';
|
|
12
|
+
import yargs from 'yargs';
|
|
13
|
+
import { reportTransformDiagnostics } from './diagnostics';
|
|
14
|
+
import { createMetadataFile } from './metadata';
|
|
18
15
|
const modulesOptions = [
|
|
19
16
|
'commonjs',
|
|
20
17
|
'es2015',
|
|
@@ -22,20 +19,20 @@ const modulesOptions = [
|
|
|
22
19
|
'esnext',
|
|
23
20
|
'native',
|
|
24
21
|
];
|
|
25
|
-
const argv =
|
|
22
|
+
const argv = yargs
|
|
26
23
|
.usage('Usage: $0 [options] <files ...>')
|
|
27
24
|
.option('config', {
|
|
28
25
|
alias: 'c',
|
|
29
26
|
type: 'string',
|
|
30
27
|
description: 'Path to a config file',
|
|
31
28
|
requiresArg: true,
|
|
32
|
-
coerce:
|
|
29
|
+
coerce: path.resolve,
|
|
33
30
|
})
|
|
34
31
|
.option('debug', {
|
|
35
32
|
alias: 'd',
|
|
36
33
|
type: 'string',
|
|
37
34
|
description: 'Path for debug output',
|
|
38
|
-
coerce:
|
|
35
|
+
coerce: path.resolve,
|
|
39
36
|
})
|
|
40
37
|
.option('out-dir', {
|
|
41
38
|
alias: 'o',
|
|
@@ -43,7 +40,7 @@ const argv = yargs_1.default
|
|
|
43
40
|
description: 'Output directory for the extracted CSS files',
|
|
44
41
|
demandOption: true,
|
|
45
42
|
requiresArg: true,
|
|
46
|
-
coerce:
|
|
43
|
+
coerce: path.resolve,
|
|
47
44
|
})
|
|
48
45
|
.option('source-maps', {
|
|
49
46
|
alias: 's',
|
|
@@ -56,6 +53,10 @@ const argv = yargs_1.default
|
|
|
56
53
|
type: 'boolean',
|
|
57
54
|
description: 'Run extraction in parallel',
|
|
58
55
|
default: false,
|
|
56
|
+
})
|
|
57
|
+
.option('output-metadata', {
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
description: 'Emit sidecar .wyw-in-js.json metadata manifests for transformed files',
|
|
59
60
|
})
|
|
60
61
|
.option('source-root', {
|
|
61
62
|
alias: 'r',
|
|
@@ -63,14 +64,14 @@ const argv = yargs_1.default
|
|
|
63
64
|
description: 'Directory containing the source JS files',
|
|
64
65
|
demandOption: true,
|
|
65
66
|
requiresArg: true,
|
|
66
|
-
coerce:
|
|
67
|
+
coerce: path.resolve,
|
|
67
68
|
})
|
|
68
69
|
.option('insert-css-requires', {
|
|
69
70
|
alias: 'i',
|
|
70
71
|
type: 'string',
|
|
71
72
|
description: 'Directory containing JS files to insert require statements for the CSS files',
|
|
72
73
|
requiresArg: true,
|
|
73
|
-
coerce:
|
|
74
|
+
coerce: path.resolve,
|
|
74
75
|
})
|
|
75
76
|
.option('transform', {
|
|
76
77
|
alias: 't',
|
|
@@ -99,27 +100,27 @@ function resolveRequireInsertionFilename(filename) {
|
|
|
99
100
|
return filename.replace(/\.tsx?/, '.js');
|
|
100
101
|
}
|
|
101
102
|
function resolveOutputFilename(filename, outDir, sourceRoot) {
|
|
102
|
-
const outputFolder =
|
|
103
|
-
const outputBasename =
|
|
103
|
+
const outputFolder = path.relative(sourceRoot, path.dirname(filename));
|
|
104
|
+
const outputBasename = path
|
|
104
105
|
.basename(filename)
|
|
105
|
-
.replace(
|
|
106
|
-
return
|
|
106
|
+
.replace(path.extname(filename), '.css');
|
|
107
|
+
return path.join(outDir, outputFolder, outputBasename);
|
|
107
108
|
}
|
|
108
109
|
async function processFiles(files, options) {
|
|
109
|
-
const { emitter, onDone } =
|
|
110
|
+
const { emitter, onDone } = createFileReporter(options.debug ? { dir: options.debug, print: true } : false);
|
|
110
111
|
const resolvedFiles = files.reduce((acc, pattern) => [
|
|
111
112
|
...acc,
|
|
112
|
-
...
|
|
113
|
+
...globSync(pattern.toString(), {
|
|
113
114
|
absolute: true,
|
|
114
115
|
ignore: options.ignore,
|
|
115
116
|
}),
|
|
116
117
|
], []);
|
|
117
|
-
const cache = new
|
|
118
|
+
const cache = new TransformCacheCollection();
|
|
118
119
|
const modifiedFiles = [];
|
|
119
120
|
const tasks = [];
|
|
120
121
|
// eslint-disable-next-line no-restricted-syntax
|
|
121
122
|
for (const filename of resolvedFiles) {
|
|
122
|
-
if (
|
|
123
|
+
if (fs.lstatSync(filename).isDirectory()) {
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
const outputFilename = resolveOutputFilename(filename, options.outDir, options.sourceRoot);
|
|
@@ -129,29 +130,48 @@ async function processFiles(files, options) {
|
|
|
129
130
|
outputFilename,
|
|
130
131
|
pluginOptions: {
|
|
131
132
|
configFile: options.configFile,
|
|
133
|
+
outputMetadata: options.outputMetadata,
|
|
132
134
|
},
|
|
133
135
|
root: options.sourceRoot,
|
|
134
136
|
},
|
|
135
137
|
cache,
|
|
136
138
|
eventEmitter: emitter,
|
|
137
139
|
};
|
|
138
|
-
tasks.push(() =>
|
|
139
|
-
if (
|
|
140
|
+
tasks.push(() => transform(transformServices, fs.readFileSync(filename).toString(), asyncResolveFallback).then(({ code, cssText, diagnostics, metadata, sourceMap, cssSourceMapText, }) => {
|
|
141
|
+
if (diagnostics?.length) {
|
|
142
|
+
reportTransformDiagnostics(diagnostics);
|
|
143
|
+
}
|
|
144
|
+
const shouldWriteCss = typeof cssText === 'string' && cssText.length > 0;
|
|
145
|
+
if (!shouldWriteCss && !metadata) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
mkdirp.sync(path.dirname(outputFilename));
|
|
149
|
+
if (metadata) {
|
|
150
|
+
const metadataFile = createMetadataFile({
|
|
151
|
+
cssFile: shouldWriteCss ? outputFilename : undefined,
|
|
152
|
+
metadata,
|
|
153
|
+
outputRoot: options.outDir,
|
|
154
|
+
outputFilename,
|
|
155
|
+
sourceRoot: options.sourceRoot,
|
|
156
|
+
sourceFilename: filename,
|
|
157
|
+
});
|
|
158
|
+
fs.writeFileSync(metadataFile.filename, metadataFile.content);
|
|
159
|
+
}
|
|
160
|
+
if (!shouldWriteCss) {
|
|
140
161
|
return false;
|
|
141
162
|
}
|
|
142
|
-
mkdirp_1.default.sync(path_1.default.dirname(outputFilename));
|
|
143
163
|
const cssContent = options.sourceMaps && sourceMap
|
|
144
164
|
? `${cssText}\n/*# sourceMappingURL=${outputFilename}.map */`
|
|
145
165
|
: cssText;
|
|
146
|
-
|
|
166
|
+
fs.writeFileSync(outputFilename, cssContent);
|
|
147
167
|
if (options.sourceMaps &&
|
|
148
168
|
sourceMap &&
|
|
149
169
|
typeof cssSourceMapText !== 'undefined') {
|
|
150
|
-
|
|
170
|
+
fs.writeFileSync(`${outputFilename}.map`, cssSourceMapText);
|
|
151
171
|
}
|
|
152
172
|
if (options.sourceRoot && options.insertCssRequires) {
|
|
153
|
-
const inputFilename =
|
|
154
|
-
const relativePath = (
|
|
173
|
+
const inputFilename = path.resolve(options.insertCssRequires, path.relative(options.sourceRoot, filename));
|
|
174
|
+
const relativePath = normalize(path.relative(path.dirname(inputFilename), outputFilename));
|
|
155
175
|
const pathForImport = relativePath.startsWith('.')
|
|
156
176
|
? relativePath
|
|
157
177
|
: `./${relativePath}`;
|
|
@@ -161,7 +181,7 @@ async function processFiles(files, options) {
|
|
|
161
181
|
const normalizedInputFilename = resolveRequireInsertionFilename(inputFilename);
|
|
162
182
|
const inputContent = options.transform
|
|
163
183
|
? code
|
|
164
|
-
:
|
|
184
|
+
: fs.readFileSync(normalizedInputFilename, 'utf-8');
|
|
165
185
|
if (!inputContent.trim().endsWith(statement)) {
|
|
166
186
|
modifiedFiles.push({
|
|
167
187
|
name: normalizedInputFilename,
|
|
@@ -188,7 +208,7 @@ async function processFiles(files, options) {
|
|
|
188
208
|
console.log(`Successfully extracted ${count} CSS files.`);
|
|
189
209
|
}
|
|
190
210
|
modifiedFiles.forEach(({ name, content }) => {
|
|
191
|
-
|
|
211
|
+
fs.writeFileSync(name, content);
|
|
192
212
|
});
|
|
193
213
|
cache.clear('all');
|
|
194
214
|
modifiedFiles.length = 0;
|
|
@@ -204,6 +224,7 @@ processFiles(argv._, {
|
|
|
204
224
|
modules: argv.modules,
|
|
205
225
|
parallel: argv.parallel,
|
|
206
226
|
outDir: argv['out-dir'],
|
|
227
|
+
outputMetadata: argv['output-metadata'],
|
|
207
228
|
sourceMaps: argv['source-maps'],
|
|
208
229
|
sourceRoot: argv['source-root'],
|
|
209
230
|
transform: argv.transform,
|
package/lib/wyw-in-js.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
4
|
-
var _path = _interopRequireDefault(require("path"));
|
|
5
|
-
var _shared = require("@wyw-in-js/shared");
|
|
6
|
-
var _transform = require("@wyw-in-js/transform");
|
|
7
|
-
var _glob = require("glob");
|
|
8
|
-
var _mkdirp = _interopRequireDefault(require("mkdirp"));
|
|
9
|
-
var _normalizePath = _interopRequireDefault(require("normalize-path"));
|
|
10
|
-
var _yargs = _interopRequireDefault(require("yargs"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
/* eslint-disable no-console */
|
|
13
|
-
/**
|
|
14
|
-
* This file contains a CLI for wyw-in-js.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const modulesOptions = ['commonjs', 'es2015', 'es6', 'esnext', 'native'];
|
|
18
|
-
const argv = _yargs.default.usage('Usage: $0 [options] <files ...>').option('config', {
|
|
19
|
-
alias: 'c',
|
|
20
|
-
type: 'string',
|
|
21
|
-
description: 'Path to a config file',
|
|
22
|
-
requiresArg: true,
|
|
23
|
-
coerce: _path.default.resolve
|
|
24
|
-
}).option('debug', {
|
|
25
|
-
alias: 'd',
|
|
26
|
-
type: 'string',
|
|
27
|
-
description: 'Path for debug output',
|
|
28
|
-
coerce: _path.default.resolve
|
|
29
|
-
}).option('out-dir', {
|
|
30
|
-
alias: 'o',
|
|
31
|
-
type: 'string',
|
|
32
|
-
description: 'Output directory for the extracted CSS files',
|
|
33
|
-
demandOption: true,
|
|
34
|
-
requiresArg: true,
|
|
35
|
-
coerce: _path.default.resolve
|
|
36
|
-
}).option('source-maps', {
|
|
37
|
-
alias: 's',
|
|
38
|
-
type: 'boolean',
|
|
39
|
-
description: 'Generate source maps for the CSS files',
|
|
40
|
-
default: false
|
|
41
|
-
}).option('parallel', {
|
|
42
|
-
alias: 'p',
|
|
43
|
-
type: 'boolean',
|
|
44
|
-
description: 'Run extraction in parallel',
|
|
45
|
-
default: false
|
|
46
|
-
}).option('source-root', {
|
|
47
|
-
alias: 'r',
|
|
48
|
-
type: 'string',
|
|
49
|
-
description: 'Directory containing the source JS files',
|
|
50
|
-
demandOption: true,
|
|
51
|
-
requiresArg: true,
|
|
52
|
-
coerce: _path.default.resolve
|
|
53
|
-
}).option('insert-css-requires', {
|
|
54
|
-
alias: 'i',
|
|
55
|
-
type: 'string',
|
|
56
|
-
description: 'Directory containing JS files to insert require statements for the CSS files',
|
|
57
|
-
requiresArg: true,
|
|
58
|
-
coerce: _path.default.resolve
|
|
59
|
-
}).option('transform', {
|
|
60
|
-
alias: 't',
|
|
61
|
-
type: 'boolean',
|
|
62
|
-
description: 'Replace template tags with evaluated values'
|
|
63
|
-
}).option('modules', {
|
|
64
|
-
alias: 'm',
|
|
65
|
-
choices: modulesOptions,
|
|
66
|
-
description: 'Specifies a type of used imports',
|
|
67
|
-
default: 'commonjs',
|
|
68
|
-
coerce: s => s.toLowerCase()
|
|
69
|
-
}).implies('insert-css-requires', 'source-root').implies('transform', 'insert-css-requires').option('ignore', {
|
|
70
|
-
alias: 'x',
|
|
71
|
-
type: 'string',
|
|
72
|
-
description: 'Pattern of files to ignore. Be sure to provide a string',
|
|
73
|
-
requiresArg: true
|
|
74
|
-
}).alias('help', 'h').alias('version', 'v').parseSync();
|
|
75
|
-
function resolveRequireInsertionFilename(filename) {
|
|
76
|
-
return filename.replace(/\.tsx?/, '.js');
|
|
77
|
-
}
|
|
78
|
-
function resolveOutputFilename(filename, outDir, sourceRoot) {
|
|
79
|
-
const outputFolder = _path.default.relative(sourceRoot, _path.default.dirname(filename));
|
|
80
|
-
const outputBasename = _path.default.basename(filename).replace(_path.default.extname(filename), '.css');
|
|
81
|
-
return _path.default.join(outDir, outputFolder, outputBasename);
|
|
82
|
-
}
|
|
83
|
-
async function processFiles(files, options) {
|
|
84
|
-
var _options$sourceRoot;
|
|
85
|
-
const {
|
|
86
|
-
emitter,
|
|
87
|
-
onDone
|
|
88
|
-
} = (0, _transform.createFileReporter)(options.debug ? {
|
|
89
|
-
dir: options.debug,
|
|
90
|
-
print: true
|
|
91
|
-
} : false);
|
|
92
|
-
const resolvedFiles = files.reduce((acc, pattern) => [...acc, ...(0, _glob.globSync)(pattern.toString(), {
|
|
93
|
-
absolute: true,
|
|
94
|
-
ignore: options.ignore
|
|
95
|
-
})], []);
|
|
96
|
-
const cache = new _transform.TransformCacheCollection();
|
|
97
|
-
const modifiedFiles = [];
|
|
98
|
-
const tasks = [];
|
|
99
|
-
|
|
100
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
101
|
-
for (const filename of resolvedFiles) {
|
|
102
|
-
if (_fs.default.lstatSync(filename).isDirectory()) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const outputFilename = resolveOutputFilename(filename, options.outDir, options.sourceRoot);
|
|
106
|
-
const transformServices = {
|
|
107
|
-
options: {
|
|
108
|
-
filename,
|
|
109
|
-
outputFilename,
|
|
110
|
-
pluginOptions: {
|
|
111
|
-
configFile: options.configFile
|
|
112
|
-
},
|
|
113
|
-
root: options.sourceRoot
|
|
114
|
-
},
|
|
115
|
-
cache,
|
|
116
|
-
eventEmitter: emitter
|
|
117
|
-
};
|
|
118
|
-
tasks.push(() => (0, _transform.transform)(transformServices, _fs.default.readFileSync(filename).toString(), _shared.asyncResolveFallback).then(({
|
|
119
|
-
code,
|
|
120
|
-
cssText,
|
|
121
|
-
sourceMap,
|
|
122
|
-
cssSourceMapText
|
|
123
|
-
}) => {
|
|
124
|
-
if (!cssText) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
_mkdirp.default.sync(_path.default.dirname(outputFilename));
|
|
128
|
-
const cssContent = options.sourceMaps && sourceMap ? `${cssText}\n/*# sourceMappingURL=${outputFilename}.map */` : cssText;
|
|
129
|
-
_fs.default.writeFileSync(outputFilename, cssContent);
|
|
130
|
-
if (options.sourceMaps && sourceMap && typeof cssSourceMapText !== 'undefined') {
|
|
131
|
-
_fs.default.writeFileSync(`${outputFilename}.map`, cssSourceMapText);
|
|
132
|
-
}
|
|
133
|
-
if (options.sourceRoot && options.insertCssRequires) {
|
|
134
|
-
const inputFilename = _path.default.resolve(options.insertCssRequires, _path.default.relative(options.sourceRoot, filename));
|
|
135
|
-
const relativePath = (0, _normalizePath.default)(_path.default.relative(_path.default.dirname(inputFilename), outputFilename));
|
|
136
|
-
const pathForImport = relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
137
|
-
const statement = options.modules === 'commonjs' ? `\nrequire('${pathForImport}');` : `\nimport "${pathForImport}";`;
|
|
138
|
-
const normalizedInputFilename = resolveRequireInsertionFilename(inputFilename);
|
|
139
|
-
const inputContent = options.transform ? code : _fs.default.readFileSync(normalizedInputFilename, 'utf-8');
|
|
140
|
-
if (!inputContent.trim().endsWith(statement)) {
|
|
141
|
-
modifiedFiles.push({
|
|
142
|
-
name: normalizedInputFilename,
|
|
143
|
-
content: `${inputContent}\n${statement}\n`
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
if (options.parallel) {
|
|
151
|
-
const res = await Promise.all(tasks.map(task => task()));
|
|
152
|
-
console.log(`Successfully extracted ${res.filter(i => i).length} CSS files.`);
|
|
153
|
-
} else {
|
|
154
|
-
let count = 0;
|
|
155
|
-
for (const task of tasks) {
|
|
156
|
-
// eslint-disable-next-line no-await-in-loop
|
|
157
|
-
const res = await task();
|
|
158
|
-
if (res) {
|
|
159
|
-
count += 1;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
console.log(`Successfully extracted ${count} CSS files.`);
|
|
163
|
-
}
|
|
164
|
-
modifiedFiles.forEach(({
|
|
165
|
-
name,
|
|
166
|
-
content
|
|
167
|
-
}) => {
|
|
168
|
-
_fs.default.writeFileSync(name, content);
|
|
169
|
-
});
|
|
170
|
-
cache.clear('all');
|
|
171
|
-
modifiedFiles.length = 0;
|
|
172
|
-
resolvedFiles.length = 0;
|
|
173
|
-
tasks.length = 0;
|
|
174
|
-
onDone((_options$sourceRoot = options.sourceRoot) !== null && _options$sourceRoot !== void 0 ? _options$sourceRoot : process.cwd());
|
|
175
|
-
}
|
|
176
|
-
processFiles(argv._, {
|
|
177
|
-
configFile: argv.config,
|
|
178
|
-
debug: argv.debug,
|
|
179
|
-
ignore: argv.ignore,
|
|
180
|
-
insertCssRequires: argv['insert-css-requires'],
|
|
181
|
-
modules: argv.modules,
|
|
182
|
-
parallel: argv.parallel,
|
|
183
|
-
outDir: argv['out-dir'],
|
|
184
|
-
sourceMaps: argv['source-maps'],
|
|
185
|
-
sourceRoot: argv['source-root'],
|
|
186
|
-
transform: argv.transform
|
|
187
|
-
});
|
|
188
|
-
//# sourceMappingURL=wyw-in-js.js.map
|
package/lib/wyw-in-js.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wyw-in-js.js","names":["_fs","_interopRequireDefault","require","_path","_shared","_transform","_glob","_mkdirp","_normalizePath","_yargs","e","__esModule","default","modulesOptions","argv","yargs","usage","option","alias","type","description","requiresArg","coerce","path","resolve","demandOption","choices","s","toLowerCase","implies","parseSync","resolveRequireInsertionFilename","filename","replace","resolveOutputFilename","outDir","sourceRoot","outputFolder","relative","dirname","outputBasename","basename","extname","join","processFiles","files","options","_options$sourceRoot","emitter","onDone","createFileReporter","debug","dir","print","resolvedFiles","reduce","acc","pattern","globSync","toString","absolute","ignore","cache","TransformCacheCollection","modifiedFiles","tasks","fs","lstatSync","isDirectory","outputFilename","transformServices","pluginOptions","configFile","root","eventEmitter","push","transform","readFileSync","asyncResolveFallback","then","code","cssText","sourceMap","cssSourceMapText","mkdirp","sync","cssContent","sourceMaps","writeFileSync","insertCssRequires","inputFilename","relativePath","normalize","pathForImport","startsWith","statement","modules","normalizedInputFilename","inputContent","trim","endsWith","name","content","parallel","res","Promise","all","map","task","console","log","filter","i","length","count","forEach","clear","process","cwd","_","config"],"sources":["../src/wyw-in-js.ts"],"sourcesContent":["/* eslint-disable no-console */\n/**\n * This file contains a CLI for wyw-in-js.\n */\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { asyncResolveFallback } from '@wyw-in-js/shared';\nimport {\n createFileReporter,\n TransformCacheCollection,\n transform,\n} from '@wyw-in-js/transform';\nimport { globSync } from 'glob';\nimport mkdirp from 'mkdirp';\nimport normalize from 'normalize-path';\nimport yargs from 'yargs';\n\nconst modulesOptions = [\n 'commonjs',\n 'es2015',\n 'es6',\n 'esnext',\n 'native',\n] as const;\n\nconst argv = yargs\n .usage('Usage: $0 [options] <files ...>')\n .option('config', {\n alias: 'c',\n type: 'string',\n description: 'Path to a config file',\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('debug', {\n alias: 'd',\n type: 'string',\n description: 'Path for debug output',\n coerce: path.resolve,\n })\n .option('out-dir', {\n alias: 'o',\n type: 'string',\n description: 'Output directory for the extracted CSS files',\n demandOption: true,\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('source-maps', {\n alias: 's',\n type: 'boolean',\n description: 'Generate source maps for the CSS files',\n default: false,\n })\n .option('parallel', {\n alias: 'p',\n type: 'boolean',\n description: 'Run extraction in parallel',\n default: false,\n })\n .option('source-root', {\n alias: 'r',\n type: 'string',\n description: 'Directory containing the source JS files',\n demandOption: true,\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('insert-css-requires', {\n alias: 'i',\n type: 'string',\n description:\n 'Directory containing JS files to insert require statements for the CSS files',\n requiresArg: true,\n coerce: path.resolve,\n })\n .option('transform', {\n alias: 't',\n type: 'boolean',\n description: 'Replace template tags with evaluated values',\n })\n .option('modules', {\n alias: 'm',\n choices: modulesOptions,\n description: 'Specifies a type of used imports',\n default: 'commonjs' as const,\n coerce: (s) => s.toLowerCase(),\n })\n .implies('insert-css-requires', 'source-root')\n .implies('transform', 'insert-css-requires')\n .option('ignore', {\n alias: 'x',\n type: 'string',\n description: 'Pattern of files to ignore. Be sure to provide a string',\n requiresArg: true,\n })\n .alias('help', 'h')\n .alias('version', 'v')\n .parseSync();\n\ntype Options = {\n configFile?: string;\n debug?: string;\n ignore?: string;\n insertCssRequires?: string;\n modules: (typeof modulesOptions)[number];\n outDir: string;\n parallel?: boolean;\n sourceMaps?: boolean;\n sourceRoot: string;\n transform?: boolean;\n};\n\nfunction resolveRequireInsertionFilename(filename: string) {\n return filename.replace(/\\.tsx?/, '.js');\n}\n\nfunction resolveOutputFilename(\n filename: string,\n outDir: string,\n sourceRoot: string\n) {\n const outputFolder = path.relative(sourceRoot, path.dirname(filename));\n const outputBasename = path\n .basename(filename)\n .replace(path.extname(filename), '.css');\n\n return path.join(outDir, outputFolder, outputBasename);\n}\n\nasync function processFiles(files: (number | string)[], options: Options) {\n const { emitter, onDone } = createFileReporter(\n options.debug ? { dir: options.debug, print: true } : false\n );\n\n const resolvedFiles = files.reduce(\n (acc, pattern) => [\n ...acc,\n ...globSync(pattern.toString(), {\n absolute: true,\n ignore: options.ignore,\n }),\n ],\n [] as string[]\n );\n const cache = new TransformCacheCollection();\n\n const modifiedFiles: { content: string; name: string }[] = [];\n\n const tasks: (() => Promise<boolean>)[] = [];\n\n // eslint-disable-next-line no-restricted-syntax\n for (const filename of resolvedFiles) {\n if (fs.lstatSync(filename).isDirectory()) {\n return;\n }\n\n const outputFilename = resolveOutputFilename(\n filename,\n options.outDir,\n options.sourceRoot\n );\n\n const transformServices = {\n options: {\n filename,\n outputFilename,\n pluginOptions: {\n configFile: options.configFile,\n },\n root: options.sourceRoot,\n },\n cache,\n eventEmitter: emitter,\n };\n\n tasks.push(() =>\n transform(\n transformServices,\n fs.readFileSync(filename).toString(),\n asyncResolveFallback\n ).then(({ code, cssText, sourceMap, cssSourceMapText }): boolean => {\n if (!cssText) {\n return false;\n }\n mkdirp.sync(path.dirname(outputFilename));\n\n const cssContent =\n options.sourceMaps && sourceMap\n ? `${cssText}\\n/*# sourceMappingURL=${outputFilename}.map */`\n : cssText;\n\n fs.writeFileSync(outputFilename, cssContent);\n\n if (\n options.sourceMaps &&\n sourceMap &&\n typeof cssSourceMapText !== 'undefined'\n ) {\n fs.writeFileSync(`${outputFilename}.map`, cssSourceMapText);\n }\n\n if (options.sourceRoot && options.insertCssRequires) {\n const inputFilename = path.resolve(\n options.insertCssRequires,\n path.relative(options.sourceRoot, filename)\n );\n\n const relativePath = normalize(\n path.relative(path.dirname(inputFilename), outputFilename)\n );\n\n const pathForImport = relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n\n const statement =\n options.modules === 'commonjs'\n ? `\\nrequire('${pathForImport}');`\n : `\\nimport \"${pathForImport}\";`;\n\n const normalizedInputFilename =\n resolveRequireInsertionFilename(inputFilename);\n\n const inputContent = options.transform\n ? code\n : fs.readFileSync(normalizedInputFilename, 'utf-8');\n\n if (!inputContent.trim().endsWith(statement)) {\n modifiedFiles.push({\n name: normalizedInputFilename,\n content: `${inputContent}\\n${statement}\\n`,\n });\n }\n }\n\n return true;\n })\n );\n }\n\n if (options.parallel) {\n const res = await Promise.all(tasks.map((task) => task()));\n console.log(\n `Successfully extracted ${res.filter((i) => i).length} CSS files.`\n );\n } else {\n let count = 0;\n for (const task of tasks) {\n // eslint-disable-next-line no-await-in-loop\n const res = await task();\n if (res) {\n count += 1;\n }\n }\n\n console.log(`Successfully extracted ${count} CSS files.`);\n }\n\n modifiedFiles.forEach(({ name, content }) => {\n fs.writeFileSync(name, content);\n });\n\n cache.clear('all');\n modifiedFiles.length = 0;\n resolvedFiles.length = 0;\n tasks.length = 0;\n\n onDone(options.sourceRoot ?? process.cwd());\n}\n\nprocessFiles(argv._, {\n configFile: argv.config,\n debug: argv.debug,\n ignore: argv.ignore,\n insertCssRequires: argv['insert-css-requires'],\n modules: argv.modules,\n parallel: argv.parallel,\n outDir: argv['out-dir'],\n sourceMaps: argv['source-maps'],\n sourceRoot: argv['source-root'],\n transform: argv.transform,\n});\n"],"mappings":";;AAKA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAKA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,cAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAS,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAjB1B;AACA;AACA;AACA;;AAgBA,MAAMG,cAAc,GAAG,CACrB,UAAU,EACV,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,QAAQ,CACA;AAEV,MAAMC,IAAI,GAAGC,cAAK,CACfC,KAAK,CAAC,iCAAiC,CAAC,CACxCC,MAAM,CAAC,QAAQ,EAAE;EAChBC,KAAK,EAAE,GAAG;EACVC,IAAI,EAAE,QAAQ;EACdC,WAAW,EAAE,uBAAuB;EACpCC,WAAW,EAAE,IAAI;EACjBC,MAAM,EAAEC,aAAI,CAACC;AACf,CAAC,CAAC,CACDP,MAAM,CAAC,OAAO,EAAE;EACfC,K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