@e-n-v/env 0.0.1
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/README.md +72 -0
- package/assets/demo.gif +0 -0
- package/assets/env-logo.png +0 -0
- package/dist/bundle.cjs +1290 -0
- package/dist/bundle.d.cts +1057 -0
- package/dist/bundle.d.ts +1055 -0
- package/dist/bundle.js +1244 -0
- package/dist/chunk-Bp6m_JJh.js +13 -0
- package/dist/cli.cjs +141 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +136 -0
- package/dist/src-RlCvrI0s.js +3860 -0
- package/dist/src-oetJm-nZ.cjs +4098 -0
- package/package.json +31 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __export as t };
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_src = require('./src-oetJm-nZ.cjs');
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_src.__toESM(node_path);
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
node_fs_promises = require_src.__toESM(node_fs_promises);
|
|
7
|
+
let node_url = require("node:url");
|
|
8
|
+
node_url = require_src.__toESM(node_url);
|
|
9
|
+
let commander = require("commander");
|
|
10
|
+
commander = require_src.__toESM(commander);
|
|
11
|
+
let node_os = require("node:os");
|
|
12
|
+
node_os = require_src.__toESM(node_os);
|
|
13
|
+
let tsx_esm_api = require("tsx/esm/api");
|
|
14
|
+
tsx_esm_api = require_src.__toESM(tsx_esm_api);
|
|
15
|
+
|
|
16
|
+
//#region ../cli/src/index.ts
|
|
17
|
+
let tsxRegistered = false;
|
|
18
|
+
const DEFAULT_MODEL_BASENAME = "env.model";
|
|
19
|
+
const MODEL_EXTENSIONS = [
|
|
20
|
+
".ts",
|
|
21
|
+
".mts",
|
|
22
|
+
".cts",
|
|
23
|
+
".tsx",
|
|
24
|
+
".js",
|
|
25
|
+
".mjs",
|
|
26
|
+
".cjs"
|
|
27
|
+
];
|
|
28
|
+
const IGNORED_DIRECTORIES = new Set([
|
|
29
|
+
"node_modules",
|
|
30
|
+
".git",
|
|
31
|
+
"dist",
|
|
32
|
+
"build",
|
|
33
|
+
".next",
|
|
34
|
+
"out"
|
|
35
|
+
]);
|
|
36
|
+
const MAX_MODEL_SEARCH_DEPTH = 6;
|
|
37
|
+
function ensureTsxRegistered() {
|
|
38
|
+
if (tsxRegistered) return;
|
|
39
|
+
(0, tsx_esm_api.register)({ cwd: process.cwd() });
|
|
40
|
+
tsxRegistered = true;
|
|
41
|
+
}
|
|
42
|
+
function expandHomePath(input) {
|
|
43
|
+
if (input === "~") return (0, node_os.homedir)();
|
|
44
|
+
if (input.startsWith("~/")) return (0, node_path.join)((0, node_os.homedir)(), input.slice(2));
|
|
45
|
+
return input;
|
|
46
|
+
}
|
|
47
|
+
function toAbsolutePath(userInput) {
|
|
48
|
+
const expanded = expandHomePath(userInput);
|
|
49
|
+
return (0, node_path.isAbsolute)(expanded) ? expanded : (0, node_path.resolve)(process.cwd(), expanded);
|
|
50
|
+
}
|
|
51
|
+
function isModelFilename(filename) {
|
|
52
|
+
return MODEL_EXTENSIONS.some((extension) => filename === `${DEFAULT_MODEL_BASENAME}${extension}`);
|
|
53
|
+
}
|
|
54
|
+
async function findDefaultModelPath(root) {
|
|
55
|
+
const queue = [{
|
|
56
|
+
directory: root,
|
|
57
|
+
depth: 0
|
|
58
|
+
}];
|
|
59
|
+
while (queue.length > 0) {
|
|
60
|
+
const current = queue.shift();
|
|
61
|
+
if (!current) continue;
|
|
62
|
+
let entries;
|
|
63
|
+
try {
|
|
64
|
+
entries = await (0, node_fs_promises.readdir)(current.directory, { withFileTypes: true });
|
|
65
|
+
} catch {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (entry.isFile() && isModelFilename(entry.name)) return (0, node_path.join)(current.directory, entry.name);
|
|
70
|
+
if (entry.isDirectory() && current.depth < MAX_MODEL_SEARCH_DEPTH && !IGNORED_DIRECTORIES.has(entry.name)) queue.push({
|
|
71
|
+
directory: (0, node_path.join)(current.directory, entry.name),
|
|
72
|
+
depth: current.depth + 1
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function importUserModule(modulePath) {
|
|
78
|
+
ensureTsxRegistered();
|
|
79
|
+
return import((0, node_url.pathToFileURL)(modulePath).href);
|
|
80
|
+
}
|
|
81
|
+
function resolveModel(moduleExports, origin) {
|
|
82
|
+
const candidates = [
|
|
83
|
+
moduleExports.default,
|
|
84
|
+
moduleExports.model,
|
|
85
|
+
moduleExports.EnvModel
|
|
86
|
+
].concat(Object.values(moduleExports));
|
|
87
|
+
for (const candidate of candidates) if (candidate instanceof require_src.EnvModel) return candidate;
|
|
88
|
+
throw new Error(`Unable to locate an EnvModel export in ${origin}`);
|
|
89
|
+
}
|
|
90
|
+
function resolvePromptOptions(moduleExports, origin) {
|
|
91
|
+
const candidates = [
|
|
92
|
+
moduleExports.default,
|
|
93
|
+
moduleExports.config,
|
|
94
|
+
moduleExports.options
|
|
95
|
+
];
|
|
96
|
+
for (const candidate of candidates) if (candidate && typeof candidate === "object") return candidate;
|
|
97
|
+
for (const value of Object.values(moduleExports)) {
|
|
98
|
+
if (value instanceof require_src.EnvModel) continue;
|
|
99
|
+
if (value && typeof value === "object") return value;
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`Unable to locate prompt configuration exports in ${origin}`);
|
|
102
|
+
}
|
|
103
|
+
async function handleSetupCommand(modelPathInput, configPathInput) {
|
|
104
|
+
const modelPath = modelPathInput ? toAbsolutePath(modelPathInput) : await findDefaultModelPath(process.cwd());
|
|
105
|
+
if (!modelPath) throw new Error("Unable to locate an EnvModel file. Provide a path or create a file named \"env.model.*\".");
|
|
106
|
+
const model = resolveModel(await importUserModule(modelPath), modelPath);
|
|
107
|
+
if (!configPathInput) {
|
|
108
|
+
await require_src.prompt(model);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const configPath = toAbsolutePath(configPathInput);
|
|
112
|
+
await require_src.prompt(model, resolvePromptOptions(await importUserModule(configPath), configPath));
|
|
113
|
+
}
|
|
114
|
+
async function run(argv = process.argv) {
|
|
115
|
+
const program = new commander.Command();
|
|
116
|
+
program.name("e-n-v").description("Interactive environment setup utilities");
|
|
117
|
+
program.command("setup").description("Run the interactive prompt for an EnvModel").argument("[model]", "Path to the module exporting an EnvModel instance").option("--config <path>", "Path to prompt configuration options").action(async (modelPath, options) => {
|
|
118
|
+
try {
|
|
119
|
+
await handleSetupCommand(modelPath, options?.config);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error instanceof Error) {
|
|
122
|
+
program.error(error.message);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
program.error(String(error));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
program.showSuggestionAfterError();
|
|
130
|
+
await program.parseAsync(argv);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/cli.ts
|
|
135
|
+
run(process.argv).catch((error) => {
|
|
136
|
+
if (error instanceof Error) console.error(error.message);
|
|
137
|
+
else console.error(error);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { i as EnvModel, t as prompt } from "./src-RlCvrI0s.js";
|
|
3
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { readdir } from "node:fs/promises";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { register } from "tsx/esm/api";
|
|
9
|
+
|
|
10
|
+
//#region ../cli/src/index.ts
|
|
11
|
+
let tsxRegistered = false;
|
|
12
|
+
const DEFAULT_MODEL_BASENAME = "env.model";
|
|
13
|
+
const MODEL_EXTENSIONS = [
|
|
14
|
+
".ts",
|
|
15
|
+
".mts",
|
|
16
|
+
".cts",
|
|
17
|
+
".tsx",
|
|
18
|
+
".js",
|
|
19
|
+
".mjs",
|
|
20
|
+
".cjs"
|
|
21
|
+
];
|
|
22
|
+
const IGNORED_DIRECTORIES = new Set([
|
|
23
|
+
"node_modules",
|
|
24
|
+
".git",
|
|
25
|
+
"dist",
|
|
26
|
+
"build",
|
|
27
|
+
".next",
|
|
28
|
+
"out"
|
|
29
|
+
]);
|
|
30
|
+
const MAX_MODEL_SEARCH_DEPTH = 6;
|
|
31
|
+
function ensureTsxRegistered() {
|
|
32
|
+
if (tsxRegistered) return;
|
|
33
|
+
register({ cwd: process.cwd() });
|
|
34
|
+
tsxRegistered = true;
|
|
35
|
+
}
|
|
36
|
+
function expandHomePath(input) {
|
|
37
|
+
if (input === "~") return homedir();
|
|
38
|
+
if (input.startsWith("~/")) return join(homedir(), input.slice(2));
|
|
39
|
+
return input;
|
|
40
|
+
}
|
|
41
|
+
function toAbsolutePath(userInput) {
|
|
42
|
+
const expanded = expandHomePath(userInput);
|
|
43
|
+
return isAbsolute(expanded) ? expanded : resolve(process.cwd(), expanded);
|
|
44
|
+
}
|
|
45
|
+
function isModelFilename(filename) {
|
|
46
|
+
return MODEL_EXTENSIONS.some((extension) => filename === `${DEFAULT_MODEL_BASENAME}${extension}`);
|
|
47
|
+
}
|
|
48
|
+
async function findDefaultModelPath(root) {
|
|
49
|
+
const queue = [{
|
|
50
|
+
directory: root,
|
|
51
|
+
depth: 0
|
|
52
|
+
}];
|
|
53
|
+
while (queue.length > 0) {
|
|
54
|
+
const current = queue.shift();
|
|
55
|
+
if (!current) continue;
|
|
56
|
+
let entries;
|
|
57
|
+
try {
|
|
58
|
+
entries = await readdir(current.directory, { withFileTypes: true });
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
if (entry.isFile() && isModelFilename(entry.name)) return join(current.directory, entry.name);
|
|
64
|
+
if (entry.isDirectory() && current.depth < MAX_MODEL_SEARCH_DEPTH && !IGNORED_DIRECTORIES.has(entry.name)) queue.push({
|
|
65
|
+
directory: join(current.directory, entry.name),
|
|
66
|
+
depth: current.depth + 1
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function importUserModule(modulePath) {
|
|
72
|
+
ensureTsxRegistered();
|
|
73
|
+
return import(pathToFileURL(modulePath).href);
|
|
74
|
+
}
|
|
75
|
+
function resolveModel(moduleExports, origin) {
|
|
76
|
+
const candidates = [
|
|
77
|
+
moduleExports.default,
|
|
78
|
+
moduleExports.model,
|
|
79
|
+
moduleExports.EnvModel
|
|
80
|
+
].concat(Object.values(moduleExports));
|
|
81
|
+
for (const candidate of candidates) if (candidate instanceof EnvModel) return candidate;
|
|
82
|
+
throw new Error(`Unable to locate an EnvModel export in ${origin}`);
|
|
83
|
+
}
|
|
84
|
+
function resolvePromptOptions(moduleExports, origin) {
|
|
85
|
+
const candidates = [
|
|
86
|
+
moduleExports.default,
|
|
87
|
+
moduleExports.config,
|
|
88
|
+
moduleExports.options
|
|
89
|
+
];
|
|
90
|
+
for (const candidate of candidates) if (candidate && typeof candidate === "object") return candidate;
|
|
91
|
+
for (const value of Object.values(moduleExports)) {
|
|
92
|
+
if (value instanceof EnvModel) continue;
|
|
93
|
+
if (value && typeof value === "object") return value;
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`Unable to locate prompt configuration exports in ${origin}`);
|
|
96
|
+
}
|
|
97
|
+
async function handleSetupCommand(modelPathInput, configPathInput) {
|
|
98
|
+
const modelPath = modelPathInput ? toAbsolutePath(modelPathInput) : await findDefaultModelPath(process.cwd());
|
|
99
|
+
if (!modelPath) throw new Error("Unable to locate an EnvModel file. Provide a path or create a file named \"env.model.*\".");
|
|
100
|
+
const model = resolveModel(await importUserModule(modelPath), modelPath);
|
|
101
|
+
if (!configPathInput) {
|
|
102
|
+
await prompt(model);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const configPath = toAbsolutePath(configPathInput);
|
|
106
|
+
await prompt(model, resolvePromptOptions(await importUserModule(configPath), configPath));
|
|
107
|
+
}
|
|
108
|
+
async function run(argv = process.argv) {
|
|
109
|
+
const program = new Command();
|
|
110
|
+
program.name("e-n-v").description("Interactive environment setup utilities");
|
|
111
|
+
program.command("setup").description("Run the interactive prompt for an EnvModel").argument("[model]", "Path to the module exporting an EnvModel instance").option("--config <path>", "Path to prompt configuration options").action(async (modelPath, options) => {
|
|
112
|
+
try {
|
|
113
|
+
await handleSetupCommand(modelPath, options?.config);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error instanceof Error) {
|
|
116
|
+
program.error(error.message);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
program.error(String(error));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
program.showSuggestionAfterError();
|
|
124
|
+
await program.parseAsync(argv);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/cli.ts
|
|
129
|
+
run(process.argv).catch((error) => {
|
|
130
|
+
if (error instanceof Error) console.error(error.message);
|
|
131
|
+
else console.error(error);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { };
|