@danielx/civet 0.6.8 → 0.6.10
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/dist/browser.js +560 -438
- package/dist/civet +17 -0
- package/dist/config.js +91 -0
- package/dist/main.js +560 -438
- package/dist/main.mjs +560 -438
- package/dist/types.d.ts +39 -0
- package/package.json +2 -1
- package/dist/babel-plugin.mjs +0 -25
- package/dist/browser.js.gzip +0 -0
package/dist/civet
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
var import_main = require("./main");
|
|
4
|
+
var import_config = require("./config");
|
|
4
5
|
var cli, encoding, fs, parseArgs, path, prune, readFiles, repl, version, splice = [].splice;
|
|
5
6
|
({ prune } = import_main.generate);
|
|
6
7
|
version = function() {
|
|
@@ -36,6 +37,8 @@ Options:
|
|
|
36
37
|
--version Show the version number
|
|
37
38
|
-o / --output XX Specify output directory and/or extension, or filename
|
|
38
39
|
-c / --compile Compile input files to TypeScript (or JavaScript)
|
|
40
|
+
--config XX Specify a config file (default scans for a config.civet, civet.json, civetconfig.civet or civetconfig.json file, optionally in a .config directory, or starting with a .)
|
|
41
|
+
--no-config Don't scan for a config file
|
|
39
42
|
--js Strip out all type annotations; default to .jsx extension
|
|
40
43
|
--ast Print the AST instead of the compiled code
|
|
41
44
|
--inline-map Generate a sourcemap
|
|
@@ -96,6 +99,12 @@ parseArgs = function(args) {
|
|
|
96
99
|
case "--output":
|
|
97
100
|
options.output = args[++i];
|
|
98
101
|
break;
|
|
102
|
+
case "--config":
|
|
103
|
+
options.config = args[++i];
|
|
104
|
+
break;
|
|
105
|
+
case "--no-config":
|
|
106
|
+
options.config = false;
|
|
107
|
+
break;
|
|
99
108
|
case "--ast":
|
|
100
109
|
options.ast = true;
|
|
101
110
|
break;
|
|
@@ -254,6 +263,14 @@ cli = async function() {
|
|
|
254
263
|
var argv, child, content, e, error, esm, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
255
264
|
argv = process.argv;
|
|
256
265
|
({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
|
|
266
|
+
if (options.config !== false) {
|
|
267
|
+
if (options.config == null) {
|
|
268
|
+
options.config = await (0, import_config.findConfig)(process.cwd());
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (options.config) {
|
|
272
|
+
options = { ...await (0, import_config.loadConfig)(options.config), ...options };
|
|
273
|
+
}
|
|
257
274
|
if (!filenames.length) {
|
|
258
275
|
if (process.stdin.isTTY) {
|
|
259
276
|
options.repl = true;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var config_exports = {};
|
|
26
|
+
__export(config_exports, {
|
|
27
|
+
findConfig: () => findConfig,
|
|
28
|
+
loadConfig: () => loadConfig
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(config_exports);
|
|
31
|
+
var import_path = __toESM(require("path"));
|
|
32
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
33
|
+
var import_main = require("./main");
|
|
34
|
+
var import_url = require("url");
|
|
35
|
+
var findInDir;
|
|
36
|
+
findInDir = async function(dirPath) {
|
|
37
|
+
var dir, entry, name;
|
|
38
|
+
dir = await import_promises.default.opendir(dirPath);
|
|
39
|
+
for await (entry of dir) {
|
|
40
|
+
if (entry.isDirectory() && entry.name === ".config") {
|
|
41
|
+
return findInDir(import_path.default.join(dirPath, entry.name));
|
|
42
|
+
}
|
|
43
|
+
if (entry.isFile()) {
|
|
44
|
+
name = entry.name.replace(/^\./, "");
|
|
45
|
+
if (name === "config.civet" || name === "civet.json" || name === "civetconfig.civet" || name === "civetconfig.json") {
|
|
46
|
+
return import_path.default.join(dirPath, entry.name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
var findConfig = async function(startDir) {
|
|
53
|
+
var configPath, curr, parent;
|
|
54
|
+
curr = startDir;
|
|
55
|
+
parent = import_path.default.dirname(curr);
|
|
56
|
+
while (curr !== parent) {
|
|
57
|
+
if (configPath = await findInDir(curr)) {
|
|
58
|
+
return configPath;
|
|
59
|
+
}
|
|
60
|
+
curr = parent;
|
|
61
|
+
parent = import_path.default.dirname(curr);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
var loadConfig = async function(path2) {
|
|
66
|
+
var config, exports, js, tmpPath;
|
|
67
|
+
config = await import_promises.default.readFile(path2, "utf8");
|
|
68
|
+
if (path2.endsWith(".json")) {
|
|
69
|
+
return JSON.parse(config);
|
|
70
|
+
} else {
|
|
71
|
+
js = (0, import_main.compile)(config, {
|
|
72
|
+
js: true
|
|
73
|
+
});
|
|
74
|
+
tmpPath = path2 + `.civet-tmp-${Date.now()}.mjs`;
|
|
75
|
+
await import_promises.default.writeFile(tmpPath, js);
|
|
76
|
+
try {
|
|
77
|
+
exports = await import((0, import_url.pathToFileURL)(tmpPath));
|
|
78
|
+
} finally {
|
|
79
|
+
await import_promises.default.unlink(tmpPath);
|
|
80
|
+
}
|
|
81
|
+
if (typeof exports.default !== "object" || exports.default === null) {
|
|
82
|
+
throw new Error("civet config file must export an object");
|
|
83
|
+
}
|
|
84
|
+
return exports.default;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
findConfig,
|
|
90
|
+
loadConfig
|
|
91
|
+
});
|