Skip to content

Commit 1c2197b

Browse files
asynclizcopybara-github
authored andcommitted
chore: update css-to-ts script
PiperOrigin-RevId: 612919272
1 parent 41bfda8 commit 1c2197b

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
node_modules
22
*.js
33
!web-test-runner.config.js
4-
!css-to-ts.js
54
!commitlint.config.js
65
*.css
76
*-styles.ts

css-to-ts.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

package.json

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@
3939
"**/*.js.map",
4040
"**/*.d.ts",
4141
"**/*.scss",
42-
"!css-to-ts.js",
4342
"!web-test-runner.config.js",
4443
"!commitlint.config.js",
4544
"!**/test/**",
4645
"!**/*_test.*",
4746
"!.wireit/**",
48-
"!catalog",
47+
"!catalog/",
4948
"!scripts/",
5049
"!**/testing/**",
5150
"testing/harness.{js,js.map,d.ts}",
@@ -87,20 +86,18 @@
8786
"**/*.ts",
8887
"!**/*.d.ts",
8988
"!**/*-styles.ts",
90-
"!catalog",
91-
"!scripts/",
92-
"!node_modules"
89+
"!catalog/",
90+
"!scripts/"
9391
],
9492
"output": [
9593
".tsbuildinfo",
9694
"**/*.js",
9795
"**/*.js.map",
9896
"**/*.d.ts",
99-
"!css-to-ts.js",
10097
"!web-test-runner.config.js",
10198
"!commitlint.config.js",
10299
"!types/",
103-
"!catalog",
100+
"!catalog/",
104101
"!scripts/"
105102
],
106103
"clean": "if-file-deleted",
@@ -109,34 +106,30 @@
109106
]
110107
},
111108
"build:css-to-ts": {
112-
"command": "find . \\( -path ./.wireit -o -path ./node_modules -o -path ./catalog \\) -prune -o -name '*-styles.css' -print | xargs node css-to-ts.js",
109+
"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",
113110
"files": [
114-
"css-to-ts.js",
115-
"!scripts/",
116-
"!node_modules"
111+
"**/*-styles.css",
112+
"!catalog/"
117113
],
118114
"output": [
119115
"**/*-styles.ts",
120-
"!catalog",
121-
"!scripts/"
116+
"!catalog/"
122117
],
123118
"dependencies": [
119+
"build:scripts",
124120
"build:sass"
125121
]
126122
},
127123
"build:sass": {
128124
"command": "sass --style=compressed --load-path=node_modules --load-path=node_modules/sass-true/sass $(ls -d */ | grep -vE 'node_modules|catalog')",
129125
"files": [
130126
"**/*.scss",
131-
"!catalog",
132-
"!scripts/",
133-
"!node_modules"
127+
"!catalog/"
134128
],
135129
"output": [
136130
"**/*.css",
137131
"**/*.css.map",
138-
"!catalog",
139-
"!scripts/"
132+
"!catalog/"
140133
]
141134
},
142135
"test": {
@@ -177,10 +170,9 @@
177170
"**/*.ts",
178171
"!**/*.d.ts",
179172
"!**/*-styles.ts",
180-
"!catalog",
173+
"!catalog/",
181174
"!scripts/",
182-
"scripts/analyzer/update-docs.js",
183-
"!node_modules"
175+
"scripts/analyzer/update-docs.js"
184176
],
185177
"output": [],
186178
"dependencies": [

scripts/css-to-ts.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as fs from 'fs';
8+
9+
const cssFilePath = process.argv[2];
10+
if (!cssFilePath) {
11+
throw new Error(`Usage: node scripts/css-to-ts.js <input.css> [output.ts]`);
12+
}
13+
14+
const tsFilePath = process.argv[3] || cssFilePath.replace('.css', '.ts');
15+
const cssContent = fs
16+
.readFileSync(cssFilePath, {encoding: 'utf8'})
17+
// Remove source map comments since the css is embedded.
18+
// "/*# sourceMappingURL=checkbox-styles.css.map */"
19+
.replace(/\/\*#\ sourceMappingURL=[^\*]+ \*\//, '');
20+
21+
fs.writeFileSync(
22+
tsFilePath,
23+
`/**
24+
* @license
25+
* Copyright 2024 Google LLC
26+
* SPDX-License-Identifier: Apache-2.0
27+
*/
28+
// Generated stylesheet for ${cssFilePath}.
29+
import {css} from 'lit';
30+
export const styles = css\`${cssContent}\`;
31+
`,
32+
);

0 commit comments

Comments
 (0)