项目作者: elarivie

项目描述 :
Creates *.ts files from *.css files
高级语言: TypeScript
项目地址: git://github.com/elarivie/css-ts.git
创建时间: 2020-07-14T00:05:49Z
项目社区:https://github.com/elarivie/css-ts

开源协议:MIT License

下载


css-ts

Build Status npm version

Generates TypeScript files (.ts) from (.css) files.

For example given the following css,

  1. /* styles.css */
  2. #myId {
  3. color: green;
  4. }
  5. .myClass {
  6. color: blue;
  7. }

css-ts creates the following styles.css.ts file from the above css:

  1. /* styles.css.ts */
  2. export const Styles = {
  3. 'myClass': 'myClass',
  4. 'myId': 'myId'
  5. };
  6. export default Styles;

So, you can import CSS class names and ids into your TypeScript sources:

  1. /* app.ts */
  2. import * as styles from './styles.css';
  3. console.log(`<div class="${styles.myClass}"></div>`);
  4. console.log(`<div id="${styles.myId}"></div>`);

Doing so allows:

  • To make sure that typescript and css are in sync since otherwise compilation errors are going to be generated.
  • To know where a given css class name or css id is being use.

Install instruction

  1. npm install css-ts

CLI

Use css-ts --help for full list of options

Basic usage

Exec css-ts <search path> [options] command.

  1. If search path points to a file, the file will be processed
  2. If search path points to a folder, files to process will be looked for using glob pattern (see --pattern).

For example, if you have .css files under src directory, exec the following:

  1. css-ts src

Then, this creates *.css.ts files under the directory which contains original .css files.

  1. (your project root)
  2. - src/
  3. | myStyle.css
  4. | myStyle.css.ts [created]

input file name pattern

By default, this tool searches files under <search directory> using the pattern **/*.css.
If you want to customize glob pattern, you can use --pattern option.
Note the quotes around the glob to --pattern (they are required, so that your shell does not perform the expansion).

  1. css-ts . --pattern 'src/**/*.css'

dry-run

A usefull CLI option is --dry-run which allows to validate the results without writing anything to disk.

You may also want to increase verbosity to obtain more detail with -v or --verbose. Every -v increase the verbosity level by 1.

watch

With -w or --watch, this will watch files and process them when needed.

⚖️ License

This software is released under the MIT License, see LICENSE.txt.