forgecss 0.9.0 → 0.11.0
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 +35 -9
- package/dist/forgecss.min.js +13 -13
- package/index.js +8 -8
- package/lib/helpers.js +66 -0
- package/lib/inventory.js +4 -3
- package/lib/usages.js +8 -68
- package/package.json +1 -1
- package/standalone/forgecss.js +4 -4
- package/standalone/lib/inventory.js +0 -59
- package/standalone/lib/usages.js +0 -30
package/cli.js
CHANGED
|
@@ -8,7 +8,13 @@ import chokidar from "chokidar";
|
|
|
8
8
|
|
|
9
9
|
import ForgeCSS from './index.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const POSSIBLE_CONFIG_FILES = [
|
|
12
|
+
process.cwd() + "/forgecss.config.json",
|
|
13
|
+
process.cwd() + "/forgecss.config.js",
|
|
14
|
+
process.cwd() + "/forgecss.config.mjs"
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
program.option("-c, --config <string>,", "Path to forgecss config file", POSSIBLE_CONFIG_FILES[0]);
|
|
12
18
|
program.option("-w, --watch", "Enable watch mode", false);
|
|
13
19
|
program.option("-v, --verbose", "Enable watch mode", false);
|
|
14
20
|
program.parse();
|
|
@@ -17,15 +23,38 @@ const options = program.opts();
|
|
|
17
23
|
let config = null, instance = null;
|
|
18
24
|
|
|
19
25
|
if (!fs.existsSync(options.config)) {
|
|
20
|
-
|
|
26
|
+
let found = false;
|
|
27
|
+
for (let possibleConfigFile of POSSIBLE_CONFIG_FILES) {
|
|
28
|
+
if (fs.existsSync(possibleConfigFile)) {
|
|
29
|
+
options.config = possibleConfigFile;
|
|
30
|
+
found = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!found) {
|
|
35
|
+
throw new Error(`forgecss: config file not found at ${options.config} or any of the default locations.`);
|
|
36
|
+
}
|
|
21
37
|
}
|
|
22
38
|
|
|
23
39
|
async function loadConfig(configPath) {
|
|
24
40
|
const abs = path.resolve(configPath);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
if (abs.toLowerCase().endsWith('.json')) {
|
|
42
|
+
const jsonStr = fs.readFileSync(abs, "utf-8");
|
|
43
|
+
if (options.verbose) {
|
|
44
|
+
console.log(`forgecss: Loaded config file from ${abs.replace(process.cwd(), '')}`);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(jsonStr);
|
|
48
|
+
} catch(err) {
|
|
49
|
+
throw new Error(`forgecss: error parsing config file at ${configPath}: ${err}`);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
const module = await import(pathToFileURL(abs).href);
|
|
53
|
+
if (options.verbose) {
|
|
54
|
+
console.log(`forgecss: Loaded config file from ${abs.replace(process.cwd(), '')}`);
|
|
55
|
+
}
|
|
56
|
+
return module.default || module;
|
|
57
|
+
}
|
|
29
58
|
}
|
|
30
59
|
async function runForgeCSS(lookAtPath = null) {
|
|
31
60
|
if (!config) {
|
|
@@ -60,9 +89,6 @@ async function runForgeCSS(lookAtPath = null) {
|
|
|
60
89
|
} else {
|
|
61
90
|
instance.parseDirectory({ dir: config.dir, output: config.output });
|
|
62
91
|
}
|
|
63
|
-
if (options.verbose) {
|
|
64
|
-
console.log(`forgecss: ${config.output} generated successfully.`);
|
|
65
|
-
}
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
runForgeCSS();
|