forgecss 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +1 -1
- package/index.d.ts +5 -10
- package/index.js +11 -21
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ async function runForgeCSS(lookAtPath = null) {
|
|
|
31
31
|
// The very first run
|
|
32
32
|
config = await loadConfig(options.config);
|
|
33
33
|
if (options.watch) {
|
|
34
|
-
const watcher = chokidar.watch(
|
|
34
|
+
const watcher = chokidar.watch(config.source, {
|
|
35
35
|
persistent: true,
|
|
36
36
|
ignoreInitial: true,
|
|
37
37
|
ignored: (p, stats) => {
|
package/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
export type ForgeCSSOptions = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ui: {
|
|
7
|
-
sourceDir: string;
|
|
8
|
-
match?: string[];
|
|
9
|
-
attributes?: string[];
|
|
10
|
-
};
|
|
2
|
+
source: string;
|
|
3
|
+
stylesMatch?: string[];
|
|
4
|
+
declarationsMatch?: string[];
|
|
5
|
+
declarationsMatchAttributes?: string[];
|
|
11
6
|
mapping: {
|
|
12
7
|
queries: {
|
|
13
8
|
[key: string]: {
|
|
@@ -15,7 +10,7 @@ export type ForgeCSSOptions = {
|
|
|
15
10
|
};
|
|
16
11
|
};
|
|
17
12
|
};
|
|
18
|
-
output: string
|
|
13
|
+
output: string;
|
|
19
14
|
};
|
|
20
15
|
|
|
21
16
|
export default function forgecss(options?: ForgeCSSOptions): {
|
package/index.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import getAllFiles from "./lib/getAllFiles.js";
|
|
2
2
|
import { extractStyles } from "./lib/styles.js";
|
|
3
|
-
import { deleteDeclarations, extractDeclarations
|
|
3
|
+
import { deleteDeclarations, extractDeclarations } from "./lib/processFile.js";
|
|
4
4
|
import { generateOutputCSS } from "./lib/generator.js";
|
|
5
5
|
|
|
6
6
|
const DEFAULT_OPTIONS = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
ui: {
|
|
12
|
-
sourceDir: null,
|
|
13
|
-
match: ["html", "jsx", "tsx"],
|
|
14
|
-
attribute: ['class', 'className']
|
|
15
|
-
},
|
|
7
|
+
source: null,
|
|
8
|
+
stylesMatch: ['css', 'less', 'scss'],
|
|
9
|
+
declarationsMatch: ['html', 'jsx', 'tsx'],
|
|
10
|
+
declarationsMatchAttributes: ['class', 'className'],
|
|
16
11
|
mapping: {
|
|
17
12
|
queries: {}
|
|
18
13
|
},
|
|
@@ -22,16 +17,11 @@ const DEFAULT_OPTIONS = {
|
|
|
22
17
|
export default function forgecss(options = { styles: {}, ui: {}, mapping: {}, output: null }) {
|
|
23
18
|
const config = { ...DEFAULT_OPTIONS };
|
|
24
19
|
|
|
25
|
-
config.styles = Object.assign({}, DEFAULT_OPTIONS.styles, options.styles || {});
|
|
26
|
-
config.ui = Object.assign({}, DEFAULT_OPTIONS.ui, options.ui || {});
|
|
27
20
|
config.mapping = Object.assign({}, DEFAULT_OPTIONS.mapping, options.mapping || {});
|
|
28
21
|
config.output = options.output || DEFAULT_OPTIONS.output;
|
|
29
22
|
|
|
30
|
-
if (!config.
|
|
31
|
-
throw new Error('forgecss: "
|
|
32
|
-
}
|
|
33
|
-
if (!config.ui.sourceDir) {
|
|
34
|
-
throw new Error('forgecss: "ui.sourceDir" option is required.');
|
|
23
|
+
if (!config.source) {
|
|
24
|
+
throw new Error('forgecss: "source" option is required.');
|
|
35
25
|
}
|
|
36
26
|
if (!config.output) {
|
|
37
27
|
throw new Error('forgecss: "output" option is required.');
|
|
@@ -42,11 +32,11 @@ export default function forgecss(options = { styles: {}, ui: {}, mapping: {}, ou
|
|
|
42
32
|
// fetching the styles
|
|
43
33
|
try {
|
|
44
34
|
if (lookAtPath) {
|
|
45
|
-
if (config.
|
|
35
|
+
if (config.stylesMatch.includes(lookAtPath.split(".").pop().toLowerCase())) {
|
|
46
36
|
await extractStyles(lookAtPath);
|
|
47
37
|
}
|
|
48
38
|
} else {
|
|
49
|
-
let files = await getAllFiles(config.
|
|
39
|
+
let files = await getAllFiles(config.source, config.stylesMatch);
|
|
50
40
|
for (let file of files) {
|
|
51
41
|
await extractStyles(file);
|
|
52
42
|
}
|
|
@@ -57,12 +47,12 @@ export default function forgecss(options = { styles: {}, ui: {}, mapping: {}, ou
|
|
|
57
47
|
// fetching the declarations
|
|
58
48
|
try {
|
|
59
49
|
if (lookAtPath) {
|
|
60
|
-
if (config.
|
|
50
|
+
if (config.declarationsMatch.includes(lookAtPath.split('.').pop().toLowerCase())) {
|
|
61
51
|
deleteDeclarations(lookAtPath);
|
|
62
52
|
await extractDeclarations(lookAtPath);
|
|
63
53
|
}
|
|
64
54
|
} else {
|
|
65
|
-
let files = await getAllFiles(config.
|
|
55
|
+
let files = await getAllFiles(config.source, config.declarationsMatch);
|
|
66
56
|
for (let file of files) {
|
|
67
57
|
await extractDeclarations(file);
|
|
68
58
|
}
|