-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathcss-to-ts.ts
More file actions
46 lines (41 loc) · 1.06 KB
/
css-to-ts.ts
File metadata and controls
46 lines (41 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'fs';
import * as util from 'util';
const {values, positionals} = util.parseArgs({
allowPositionals: true,
options: {
suffix: {
type: 'string',
},
},
});
const cssFilePath = positionals[0];
if (!cssFilePath) {
throw new Error(
`Usage: node scripts/css-to-ts.js <input.css> [output.ts] [--suffix=<suffix>]`,
);
}
const tsFilePath =
positionals[1] || cssFilePath.replace('.css', `${values.suffix || ''}.ts`);
const cssContent = fs
.readFileSync(cssFilePath, {encoding: 'utf8'})
// Remove source map comments since the css is embedded.
// "/*# sourceMappingURL=checkbox-styles.css.map */"
.replace(/\/\*#\ sourceMappingURL=[^\*]+ \*\//, '');
fs.writeFileSync(
tsFilePath,
`/**
* @license
* Copyright ${new Date().getFullYear()} Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// Generated stylesheet for ${cssFilePath}.
import {css} from 'lit';
export const styles = css\`${cssContent}\`;
export default styles.styleSheet!;
`,
);