Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 9cad742

Browse files
Merge pull request #9 from SimplrJS/feature/globby
Feature/globby
2 parents 38b4900 + 82ec067 commit 9cad742

27 files changed

Lines changed: 245 additions & 138 deletions

@types/arguments.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { Options } from "./contracts";
2-
export declare const Arguments: Options;
1+
import { CLIOptions } from "./contracts";
2+
export declare const Arguments: CLIOptions;

@types/cli-handler.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { Options } from "./contracts";
1+
import { CLIOptions } from "./contracts";
22
export declare class CLIHandler {
33
private options;
4-
constructor(options: Options);
4+
constructor(options: CLIOptions);
55
private handleGlob();
6-
private getFilesArray(pattern);
76
private watchCss();
87
private onWatchChange;
98
private onWatchError;
109
private emitWatchMessage();
1110
private convertFile(filePath);
1211
private resolveVarName(fileName);
1312
private constructFileName(fileName, extension?);
14-
private snakeCaseToCamelCase(fileName);
1513
}

@types/contracts.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
export interface Options extends CssToTsOptions {
1+
export interface CLIOptions extends CssToTsOptions {
22
removeSource?: boolean;
33
pattern: string;
44
watch?: boolean;
55
cwd?: string;
66
delimiter?: string;
77
exclude?: string[];
8+
outExt?: string;
89
}
910
export interface CssToTsOptions {
1011
rootDir: string;
@@ -13,6 +14,7 @@ export interface CssToTsOptions {
1314
prefix?: string;
1415
header?: string;
1516
varName?: string | boolean;
17+
varType?: string;
1618
}
1719
export interface BasePackage {
1820
name: string;
@@ -22,3 +24,8 @@ export interface BasePackage {
2224
author?: string;
2325
license?: string;
2426
}
27+
export declare enum VarType {
28+
Var = "var",
29+
Let = "let",
30+
Const = "const",
31+
}

@types/css-to-ts-converter.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { VarType } from "./contracts";
12
export declare class CssToTsConverter {
2-
private tsDir;
3-
private tsFileName;
3+
private outputDir;
4+
private outputFileName;
45
private cssDir;
56
private cssFileName;
67
private varName;
78
private header;
89
private removeSource;
9-
constructor(tsDir: string, tsFileName: string, cssDir: string, cssFileName: string, varName: string, header?: string | undefined, removeSource?: boolean | undefined);
10+
private varType;
11+
constructor(outputDir: string, outputFileName: string, cssDir: string, cssFileName: string, varName: string, header?: string | undefined, removeSource?: boolean | undefined, varType?: VarType | undefined);
1012
Convert(): Promise<void>;
1113
}

@types/css-to-ts.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export declare function ConvertCssToTs(stringifiedCss: string, variableName: string, headerComment?: string): string;
1+
import { VarType } from "./contracts";
2+
export declare function ConvertCssToTs(stringifiedCss: string, variableName: string, headerComment?: string, varType?: VarType): string;

@types/helpers.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference types="node" />
2-
import { Options } from "./contracts";
2+
import { CLIOptions } from "./contracts";
33
export declare const CLI_ERROR_PREFIX = "CssToTs";
44
export declare function EmitError(message: string): void;
5-
export declare const CLIDefaults: Options;
5+
export declare const CLIDefaults: CLIOptions;
66
export declare function IsNodeError(error: any): error is NodeJS.ErrnoException;
7+
export declare function SnakeCaseToCamelCase(fileName: string): string;

@types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export { Arguments } from "./arguments";
22
export { CLIHandler } from "./cli-handler";
33
export { CssToTsConverter } from "./css-to-ts-converter";
44
export { ConvertCssToTs } from "./css-to-ts";
5-
export { Options, CssToTsOptions } from "./contracts";
5+
export { CLIOptions, CssToTsOptions } from "./contracts";

@types/validators.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { VarType } from "./contracts";
2+
export declare function IsVarNameValid(varName: string): boolean;
3+
export declare function IsVarTypeValid(varType: string): varType is VarType;

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Compiles css files to importable TypeScript files.
88
npm install css-to-ts -g
99
```
1010

11-
Global installation is not necessary. You can install this package with
11+
Global installation is not necessary. You can install this package with:
1212

1313
```sh
1414
npm install css-to-ts
@@ -38,6 +38,7 @@ css-to-ts -h
3838
| -v, --version | boolean | `false` | Show current version. |
3939
| --rootDir | string | `./` | Specifies the root directory of input files. |
4040
| --outDir | string | `./` | Redirect output structure to the directory. |
41+
| --outExt | string | `ts` | Specifies extension of output TypeScript file. |
4142
| --pattern | string | `**/*.css` | Files glob pattern. |
4243
| -w, --watch | boolean | `false` | Watch for changes of input files. |
4344
| --prefix | string | | Prefix added to output file name. |
@@ -48,6 +49,7 @@ css-to-ts -h
4849
| --cwd | string | `process.cwd()` | Specifies current working directory. |
4950
| --exclude | array | `["**/node_modules/**"]` | Specifies an array of globs to exclude. |
5051
| --varName | string | | Specifies name of variable to be exported in TypeScript file. |
52+
| --varType | string | `const` | Specifies type of variable to be exported in TypeScript file. |
5153

5254
## Example
5355

@@ -68,7 +70,7 @@ Generated `./dist/orange.ts`:
6870

6971
```ts
7072
// File generated with css-to-ts
71-
export var Orange = `.orange {
73+
export const Orange = `.orange {
7274
color: orange;
7375
border: 1px solid yellow;
7476
}`;
@@ -77,7 +79,7 @@ export var Orange = `.orange {
7779

7880
## API
7981

80-
### `ConvertCssToTs(stringifiedCss: string, variableName: string, headerComment?: string): string`
82+
### `ConvertCssToTs(stringifiedCss: string, variableName: string, headerComment?: string, varType: VarType = VarType.Const): string`
8183

8284
Takes stringified css and outputs TypeScript code with exported string containing content of your css file.
8385

@@ -92,8 +94,17 @@ import { ConvertCssToTs } from "css-to-ts";
9294
| `stringifiedCss` | string | * | Stringified css to be exported in TypeScript file. |
9395
| `variableName` | string | * | Name of variable to be exported in TypeScript file. |
9496
| `headerComment` | string | | Comment placed in the top of exported TypeScript file. |
97+
| `varType` | string | | Type of variable to be exported in TypeScript file. |
9598

96-
### `new CssToTsConverter(tsDir, tsFileName, cssDir, cssFileName, varName, header, removeSource)`
99+
```ts
100+
export enum VarType {
101+
Var = "var",
102+
Let = "let",
103+
Const = "const"
104+
}
105+
```
106+
107+
### `new CssToTsConverter(outputDir, outputFileName, cssDir, cssFileName, varName, header, removeSource, varType)`
97108

98109
Compiles css files to importable TypeScript files.
99110

@@ -103,8 +114,8 @@ Usage:
103114
import { CssToTsConverter } from "css-to-ts";
104115

105116
const converter = new CssToTsConverter(
106-
tsDir,
107-
tsFileName,
117+
outputDir,
118+
outputFileName,
108119
cssDir,
109120
cssFileName,
110121
varName,
@@ -121,13 +132,14 @@ try {
121132

122133
| Constructor argument | Type | Required | Description |
123134
|-----------------------|-----------|-----------|---------------------------------------------------------------|
124-
| `tsDir` | string | * | Directory of TypeScript file. |
125-
| `tsFileName` | string | * | File name of TypeScript file. |
135+
| `outputDir` | string | * | Directory of output file. |
136+
| `outputFileName` | string | * | Name of output file. |
126137
| `cssDir` | string | * | Directory of css file. |
127138
| `cssFileName` | string | * | File name of css file. |
128139
| `varName` | string | * | Name of variable to be exported in TypeScript file. |
129140
| `header` | string | | Comment placed in the top of exported TypeScript file. |
130141
| `removeSource` | boolean | | Should css file be deleted after TypeScript file emitted. |
142+
| `varType` | VarType | | Type of variable to be exported in TypeScript file. |
131143

132144
## License
133145

dist/arguments.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,13 @@ exports.Arguments = yargs
5959
.option("varName", {
6060
describe: "Specifies name of variable to be exported in TypeScript file.",
6161
type: "string"
62+
})
63+
.option("varType", {
64+
describe: "Specifies type of variable to be exported in TypeScript file. Valid values: `var`, `let`, `const`.",
65+
type: "string"
66+
})
67+
.option("outExt", {
68+
describe: "Specifies extension of output TypeScript file.",
69+
type: "string"
6270
})
6371
.argv;

0 commit comments

Comments
 (0)