mirror of
https://github.com/material-components/material-web.git
synced 2024-08-16 09:00:32 +03:00
chore: update css-to-ts script
PiperOrigin-RevId: 612919272
This commit is contained in:
parent
41bfda8dca
commit
1c2197bd30
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,7 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
*.js
|
*.js
|
||||||
!web-test-runner.config.js
|
!web-test-runner.config.js
|
||||||
!css-to-ts.js
|
|
||||||
!commitlint.config.js
|
!commitlint.config.js
|
||||||
*.css
|
*.css
|
||||||
*-styles.ts
|
*-styles.ts
|
||||||
|
25
css-to-ts.js
25
css-to-ts.js
@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright 2022 Google LLC
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
for (let i = 2; i < process.argv.length; i++) {
|
|
||||||
try {
|
|
||||||
const filePath = process.argv[i];
|
|
||||||
const content = fs.readFileSync(filePath);
|
|
||||||
fs.writeFileSync(filePath.replace('.css', '.ts'), `/**
|
|
||||||
* @license
|
|
||||||
* Copyright 2022 Google LLC
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
import {css} from 'lit';
|
|
||||||
export const styles = css\`${content.toString('utf8')}\`;
|
|
||||||
`);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
34
package.json
34
package.json
@ -39,13 +39,12 @@
|
|||||||
"**/*.js.map",
|
"**/*.js.map",
|
||||||
"**/*.d.ts",
|
"**/*.d.ts",
|
||||||
"**/*.scss",
|
"**/*.scss",
|
||||||
"!css-to-ts.js",
|
|
||||||
"!web-test-runner.config.js",
|
"!web-test-runner.config.js",
|
||||||
"!commitlint.config.js",
|
"!commitlint.config.js",
|
||||||
"!**/test/**",
|
"!**/test/**",
|
||||||
"!**/*_test.*",
|
"!**/*_test.*",
|
||||||
"!.wireit/**",
|
"!.wireit/**",
|
||||||
"!catalog",
|
"!catalog/",
|
||||||
"!scripts/",
|
"!scripts/",
|
||||||
"!**/testing/**",
|
"!**/testing/**",
|
||||||
"testing/harness.{js,js.map,d.ts}",
|
"testing/harness.{js,js.map,d.ts}",
|
||||||
@ -87,20 +86,18 @@
|
|||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"!**/*.d.ts",
|
"!**/*.d.ts",
|
||||||
"!**/*-styles.ts",
|
"!**/*-styles.ts",
|
||||||
"!catalog",
|
"!catalog/",
|
||||||
"!scripts/",
|
"!scripts/"
|
||||||
"!node_modules"
|
|
||||||
],
|
],
|
||||||
"output": [
|
"output": [
|
||||||
".tsbuildinfo",
|
".tsbuildinfo",
|
||||||
"**/*.js",
|
"**/*.js",
|
||||||
"**/*.js.map",
|
"**/*.js.map",
|
||||||
"**/*.d.ts",
|
"**/*.d.ts",
|
||||||
"!css-to-ts.js",
|
|
||||||
"!web-test-runner.config.js",
|
"!web-test-runner.config.js",
|
||||||
"!commitlint.config.js",
|
"!commitlint.config.js",
|
||||||
"!types/",
|
"!types/",
|
||||||
"!catalog",
|
"!catalog/",
|
||||||
"!scripts/"
|
"!scripts/"
|
||||||
],
|
],
|
||||||
"clean": "if-file-deleted",
|
"clean": "if-file-deleted",
|
||||||
@ -109,18 +106,17 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"build:css-to-ts": {
|
"build:css-to-ts": {
|
||||||
"command": "find . \\( -path ./.wireit -o -path ./node_modules -o -path ./catalog \\) -prune -o -name '*-styles.css' -print | xargs node css-to-ts.js",
|
"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",
|
||||||
"files": [
|
"files": [
|
||||||
"css-to-ts.js",
|
"**/*-styles.css",
|
||||||
"!scripts/",
|
"!catalog/"
|
||||||
"!node_modules"
|
|
||||||
],
|
],
|
||||||
"output": [
|
"output": [
|
||||||
"**/*-styles.ts",
|
"**/*-styles.ts",
|
||||||
"!catalog",
|
"!catalog/"
|
||||||
"!scripts/"
|
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
"build:scripts",
|
||||||
"build:sass"
|
"build:sass"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -128,15 +124,12 @@
|
|||||||
"command": "sass --style=compressed --load-path=node_modules --load-path=node_modules/sass-true/sass $(ls -d */ | grep -vE 'node_modules|catalog')",
|
"command": "sass --style=compressed --load-path=node_modules --load-path=node_modules/sass-true/sass $(ls -d */ | grep -vE 'node_modules|catalog')",
|
||||||
"files": [
|
"files": [
|
||||||
"**/*.scss",
|
"**/*.scss",
|
||||||
"!catalog",
|
"!catalog/"
|
||||||
"!scripts/",
|
|
||||||
"!node_modules"
|
|
||||||
],
|
],
|
||||||
"output": [
|
"output": [
|
||||||
"**/*.css",
|
"**/*.css",
|
||||||
"**/*.css.map",
|
"**/*.css.map",
|
||||||
"!catalog",
|
"!catalog/"
|
||||||
"!scripts/"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
@ -177,10 +170,9 @@
|
|||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"!**/*.d.ts",
|
"!**/*.d.ts",
|
||||||
"!**/*-styles.ts",
|
"!**/*-styles.ts",
|
||||||
"!catalog",
|
"!catalog/",
|
||||||
"!scripts/",
|
"!scripts/",
|
||||||
"scripts/analyzer/update-docs.js",
|
"scripts/analyzer/update-docs.js"
|
||||||
"!node_modules"
|
|
||||||
],
|
],
|
||||||
"output": [],
|
"output": [],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
32
scripts/css-to-ts.ts
Normal file
32
scripts/css-to-ts.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2022 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
const cssFilePath = process.argv[2];
|
||||||
|
if (!cssFilePath) {
|
||||||
|
throw new Error(`Usage: node scripts/css-to-ts.js <input.css> [output.ts]`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tsFilePath = process.argv[3] || cssFilePath.replace('.css', '.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 2024 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
// Generated stylesheet for ${cssFilePath}.
|
||||||
|
import {css} from 'lit';
|
||||||
|
export const styles = css\`${cssContent}\`;
|
||||||
|
`,
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user