Skip to content

Commit fb8a059

Browse files
asynclizcopybara-github
authored andcommitted
chore: generate *.cssresult.js for CSS files
PiperOrigin-RevId: 895557948
1 parent 763a973 commit fb8a059

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules
33
!web-test-runner.config.js
44
!commitlint.config.js
55
*.css
6+
*.cssresult.ts
67
*-styles.ts
78
*.map
89
*.d.ts

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@
113113
]
114114
},
115115
"build:css-to-ts": {
116+
"dependencies": [
117+
"build:css-to-ts:cssresult",
118+
"build:css-to-ts:styles"
119+
]
120+
},
121+
"build:css-to-ts:cssresult": {
122+
"command": "find . \\( -path ./.wireit -o -path ./node_modules -o -path ./catalog \\) -prune -o -name '*.css' -print | xargs -L1 node scripts/css-to-ts.js --suffix=.cssresult",
123+
"files": [
124+
"**/*.css",
125+
"!catalog/"
126+
],
127+
"output": [
128+
"**/*.cssresult.ts",
129+
"!catalog/"
130+
],
131+
"dependencies": [
132+
"build:scripts",
133+
"build:sass"
134+
]
135+
},
136+
"build:css-to-ts:styles": {
116137
"command": "find . \\( -path ./.wireit -o -path ./node_modules -o -path ./catalog \\) -prune -o -name '*-styles.css' -print | xargs -L1 node scripts/css-to-ts.js",
117138
"files": [
118139
"**/*-styles.css",

scripts/css-to-ts.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@
55
*/
66

77
import * as fs from 'fs';
8+
import * as util from 'util';
89

9-
const cssFilePath = process.argv[2];
10+
const {values, positionals} = util.parseArgs({
11+
allowPositionals: true,
12+
options: {
13+
suffix: {
14+
type: 'string',
15+
},
16+
},
17+
});
18+
19+
const cssFilePath = positionals[0];
1020
if (!cssFilePath) {
11-
throw new Error(`Usage: node scripts/css-to-ts.js <input.css> [output.ts]`);
21+
throw new Error(
22+
`Usage: node scripts/css-to-ts.js <input.css> [output.ts] [--suffix=<suffix>]`,
23+
);
1224
}
1325

14-
const tsFilePath = process.argv[3] || cssFilePath.replace('.css', '.ts');
26+
const tsFilePath =
27+
positionals[1] || cssFilePath.replace('.css', `${values.suffix || ''}.ts`);
1528
const cssContent = fs
1629
.readFileSync(cssFilePath, {encoding: 'utf8'})
1730
// Remove source map comments since the css is embedded.
@@ -22,7 +35,7 @@ fs.writeFileSync(
2235
tsFilePath,
2336
`/**
2437
* @license
25-
* Copyright 2024 Google LLC
38+
* Copyright ${new Date().getFullYear()} Google LLC
2639
* SPDX-License-Identifier: Apache-2.0
2740
*/
2841
// Generated stylesheet for ${cssFilePath}.

0 commit comments

Comments
 (0)