@take-out/cli 0.4.3 → 0.4.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/dist/cjs/cli.cjs +53 -35
- package/dist/cjs/commands/changed.cjs +133 -95
- package/dist/cjs/commands/docs.cjs +276 -203
- package/dist/cjs/commands/env-setup.cjs +45 -33
- package/dist/cjs/commands/onboard.cjs +668 -224
- package/dist/cjs/commands/run-all.cjs +54 -45
- package/dist/cjs/commands/run.cjs +80 -65
- package/dist/cjs/commands/script.cjs +263 -187
- package/dist/cjs/commands/skills.cjs +174 -118
- package/dist/cjs/commands/sync.cjs +193 -93
- package/dist/cjs/constants/ascii.cjs +14 -12
- package/dist/cjs/index.cjs +12 -10
- package/dist/cjs/types.cjs +7 -5
- package/dist/cjs/utils/env-categories.cjs +53 -48
- package/dist/cjs/utils/env-setup.cjs +214 -106
- package/dist/cjs/utils/env.cjs +65 -44
- package/dist/cjs/utils/files.cjs +186 -113
- package/dist/cjs/utils/parallel-runner.cjs +125 -75
- package/dist/cjs/utils/ports.cjs +21 -21
- package/dist/cjs/utils/prerequisites.cjs +42 -34
- package/dist/cjs/utils/prompts.cjs +66 -41
- package/dist/cjs/utils/script-listing.cjs +130 -60
- package/dist/cjs/utils/script-utils.cjs +29 -19
- package/dist/cjs/utils/sync.cjs +67 -45
- package/dist/esm/cli.mjs +40 -24
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/commands/changed.mjs +104 -68
- package/dist/esm/commands/changed.mjs.map +1 -1
- package/dist/esm/commands/docs.mjs +245 -174
- package/dist/esm/commands/docs.mjs.map +1 -1
- package/dist/esm/commands/env-setup.mjs +18 -8
- package/dist/esm/commands/env-setup.mjs.map +1 -1
- package/dist/esm/commands/onboard.mjs +631 -189
- package/dist/esm/commands/onboard.mjs.map +1 -1
- package/dist/esm/commands/run-all.mjs +26 -19
- package/dist/esm/commands/run-all.mjs.map +1 -1
- package/dist/esm/commands/run.mjs +52 -39
- package/dist/esm/commands/run.mjs.map +1 -1
- package/dist/esm/commands/script.mjs +230 -156
- package/dist/esm/commands/script.mjs.map +1 -1
- package/dist/esm/commands/skills.mjs +143 -89
- package/dist/esm/commands/skills.mjs.map +1 -1
- package/dist/esm/commands/sync.mjs +160 -62
- package/dist/esm/commands/sync.mjs.map +1 -1
- package/dist/esm/constants/ascii.mjs +2 -2
- package/dist/esm/constants/ascii.mjs.map +1 -1
- package/dist/esm/utils/env-categories.mjs +29 -26
- package/dist/esm/utils/env-categories.mjs.map +1 -1
- package/dist/esm/utils/env-setup.mjs +184 -78
- package/dist/esm/utils/env-setup.mjs.map +1 -1
- package/dist/esm/utils/env.mjs +50 -31
- package/dist/esm/utils/env.mjs.map +1 -1
- package/dist/esm/utils/files.mjs +171 -100
- package/dist/esm/utils/files.mjs.map +1 -1
- package/dist/esm/utils/parallel-runner.mjs +111 -63
- package/dist/esm/utils/parallel-runner.mjs.map +1 -1
- package/dist/esm/utils/ports.mjs +9 -11
- package/dist/esm/utils/ports.mjs.map +1 -1
- package/dist/esm/utils/prerequisites.mjs +30 -24
- package/dist/esm/utils/prerequisites.mjs.map +1 -1
- package/dist/esm/utils/prompts.mjs +40 -17
- package/dist/esm/utils/prompts.mjs.map +1 -1
- package/dist/esm/utils/script-listing.mjs +101 -33
- package/dist/esm/utils/script-listing.mjs.map +1 -1
- package/dist/esm/utils/script-utils.mjs +14 -6
- package/dist/esm/utils/script-utils.mjs.map +1 -1
- package/dist/esm/utils/sync.mjs +38 -18
- package/dist/esm/utils/sync.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -2,151 +2,248 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var env_setup_exports = {};
|
|
33
35
|
__export(env_setup_exports, {
|
|
34
36
|
listCategories: () => listCategories,
|
|
35
37
|
setupProductionEnv: () => setupProductionEnv
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(env_setup_exports);
|
|
38
|
-
var import_node_fs = require("node:fs")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
var import_node_fs = require("node:fs");
|
|
41
|
+
var import_node_path = require("node:path");
|
|
42
|
+
var clack = __toESM(require("@clack/prompts"), 1);
|
|
43
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
44
|
+
var import_env = require("./env.cjs");
|
|
45
|
+
var import_env_categories = require("./env-categories.cjs");
|
|
44
46
|
async function setupProductionEnv(cwd, options = {}) {
|
|
45
|
-
const envFile = options.envFile || ".env.production"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const envFile = options.envFile || ".env.production";
|
|
48
|
+
const fullPath = (0, import_node_path.resolve)(cwd, envFile);
|
|
49
|
+
const cleanup = () => {
|
|
50
|
+
console.info("\n" + import_picocolors.default.yellow("Setup interrupted. You can resume anytime with:"));
|
|
51
|
+
console.info(import_picocolors.default.cyan(" bun takeout env:setup"));
|
|
52
|
+
console.info(import_picocolors.default.gray("\nNote: All environment variables are optional for local development."));
|
|
53
|
+
process.exit(0);
|
|
54
|
+
};
|
|
55
|
+
process.on("SIGINT", cleanup);
|
|
56
|
+
process.on("SIGTERM", cleanup);
|
|
53
57
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
clack.intro(import_picocolors.default.bgCyan(import_picocolors.default.black(" Production Environment Setup ")));
|
|
59
|
+
console.info(import_picocolors.default.gray("All environment variables are optional."));
|
|
60
|
+
console.info(import_picocolors.default.gray("You can skip any section or re-run this setup anytime.\n"));
|
|
61
|
+
if (!(0, import_env.envFileExists)(cwd, envFile)) {
|
|
56
62
|
const createFile = await clack.confirm({
|
|
57
63
|
message: `${envFile} doesn't exist. Create it from example?`,
|
|
58
|
-
initialValue:
|
|
64
|
+
initialValue: true
|
|
59
65
|
});
|
|
60
|
-
if (clack.isCancel(createFile) || !createFile)
|
|
66
|
+
if (clack.isCancel(createFile) || !createFile) {
|
|
67
|
+
clack.cancel("Setup cancelled");
|
|
68
|
+
process.removeListener("SIGINT", cleanup);
|
|
69
|
+
process.removeListener("SIGTERM", cleanup);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
61
72
|
const exampleFile = ".env.production.example";
|
|
62
|
-
(0, import_env.envFileExists)(cwd, exampleFile)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
`))
|
|
73
|
+
if ((0, import_env.envFileExists)(cwd, exampleFile)) {
|
|
74
|
+
(0, import_env.copyEnvFile)(cwd, exampleFile, envFile);
|
|
75
|
+
console.info(import_picocolors.default.green(`\u2713 Created ${envFile} from example
|
|
76
|
+
`));
|
|
77
|
+
} else {
|
|
78
|
+
(0, import_node_fs.writeFileSync)(fullPath, "# Production Environment Variables\n");
|
|
79
|
+
console.info(import_picocolors.default.green(`\u2713 Created empty ${envFile}
|
|
80
|
+
`));
|
|
81
|
+
}
|
|
66
82
|
}
|
|
67
83
|
let categoriesToSetup = options.onlyCategory ? import_env_categories.envCategories.filter(cat => cat.id === options.onlyCategory) : import_env_categories.envCategories;
|
|
68
|
-
if (categoriesToSetup.length === 0)
|
|
69
|
-
|
|
84
|
+
if (categoriesToSetup.length === 0) {
|
|
85
|
+
clack.cancel(`Category "${options.onlyCategory}" not found`);
|
|
86
|
+
process.removeListener("SIGINT", cleanup);
|
|
87
|
+
process.removeListener("SIGTERM", cleanup);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (options.interactive !== false && !options.onlyCategory) {
|
|
70
91
|
const setupProd = await clack.confirm({
|
|
71
92
|
message: "Do you want to set up production environment variables?",
|
|
72
|
-
initialValue:
|
|
93
|
+
initialValue: false
|
|
73
94
|
});
|
|
74
|
-
if (clack.isCancel(setupProd) || !setupProd)
|
|
75
|
-
|
|
95
|
+
if (clack.isCancel(setupProd) || !setupProd) {
|
|
96
|
+
clack.note(`You can set up production environment later with:
|
|
97
|
+
${import_picocolors.default.cyan("bun takeout env:setup")}`, import_picocolors.default.yellow("Skipping production setup"));
|
|
98
|
+
process.removeListener("SIGINT", cleanup);
|
|
99
|
+
process.removeListener("SIGTERM", cleanup);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const category of categoriesToSetup) {
|
|
104
|
+
const shouldSetup = await setupCategory(category, envFile, cwd, options);
|
|
105
|
+
if (!shouldSetup) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const configuredVars = [];
|
|
110
|
+
const skippedVars = [];
|
|
111
|
+
for (const category of categoriesToSetup) {
|
|
112
|
+
for (const variable of category.variables) {
|
|
113
|
+
const value = (0, import_env.readEnvVariable)(cwd, variable.key, envFile);
|
|
114
|
+
if (value && value !== "" && !value.includes("your-")) {
|
|
115
|
+
configuredVars.push(variable.key);
|
|
116
|
+
} else if (variable.required) {
|
|
117
|
+
skippedVars.push(variable.key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
76
120
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
121
|
+
if (configuredVars.length > 0) {
|
|
122
|
+
clack.outro(import_picocolors.default.green("\u2713 Environment setup complete!"));
|
|
123
|
+
console.info(import_picocolors.default.gray(`
|
|
124
|
+
Configured ${configuredVars.length} variables in ${envFile}`));
|
|
125
|
+
if (skippedVars.length > 0) {
|
|
126
|
+
console.info(import_picocolors.default.yellow(`
|
|
127
|
+
Note: Some required variables were skipped. You'll need to configure these before deploying:`));
|
|
128
|
+
skippedVars.forEach(v => console.info(import_picocolors.default.gray(` - ${v}`)));
|
|
129
|
+
}
|
|
130
|
+
console.info(import_picocolors.default.cyan("\nYou can re-run this setup anytime with:"));
|
|
131
|
+
console.info(import_picocolors.default.gray(" bun takeout env:setup"));
|
|
132
|
+
console.info(import_picocolors.default.cyan("\nOr set up specific categories:"));
|
|
133
|
+
console.info(import_picocolors.default.gray(" bun takeout env:setup --category aws"));
|
|
134
|
+
console.info(import_picocolors.default.gray(" bun takeout env:setup --category apple"));
|
|
135
|
+
} else {
|
|
136
|
+
clack.outro(import_picocolors.default.yellow("No variables configured"));
|
|
137
|
+
console.info(import_picocolors.default.gray("\nYou can re-run this setup anytime with:"));
|
|
138
|
+
console.info(import_picocolors.default.gray(" bun takeout env:setup"));
|
|
83
139
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
You can re-run this setup anytime with:`)), console.info(import_picocolors.default.gray(" bun takeout env:setup")), console.info(import_picocolors.default.cyan(`
|
|
88
|
-
Or set up specific categories:`)), console.info(import_picocolors.default.gray(" bun takeout env:setup --category aws")), console.info(import_picocolors.default.gray(" bun takeout env:setup --category apple"))) : (clack.outro(import_picocolors.default.yellow("No variables configured")), console.info(import_picocolors.default.gray(`
|
|
89
|
-
You can re-run this setup anytime with:`)), console.info(import_picocolors.default.gray(" bun takeout env:setup"))), process.removeListener("SIGINT", cleanup), process.removeListener("SIGTERM", cleanup), !0;
|
|
140
|
+
process.removeListener("SIGINT", cleanup);
|
|
141
|
+
process.removeListener("SIGTERM", cleanup);
|
|
142
|
+
return true;
|
|
90
143
|
} catch (error) {
|
|
91
|
-
|
|
144
|
+
process.removeListener("SIGINT", cleanup);
|
|
145
|
+
process.removeListener("SIGTERM", cleanup);
|
|
146
|
+
if (error instanceof Error && error.message.includes("cancelled")) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
92
149
|
throw error;
|
|
93
150
|
}
|
|
94
151
|
}
|
|
95
152
|
async function setupCategory(category, envFile, cwd, options) {
|
|
96
153
|
const spinner = clack.spinner();
|
|
97
154
|
let message = `Set up ${import_picocolors.default.bold(category.name)}?`;
|
|
98
|
-
category.required
|
|
155
|
+
if (!category.required) {
|
|
156
|
+
message += import_picocolors.default.gray(" (optional)");
|
|
157
|
+
}
|
|
158
|
+
if (category.setupTime) {
|
|
159
|
+
message += import_picocolors.default.yellow(` ${category.setupTime}`);
|
|
160
|
+
}
|
|
161
|
+
console.info("");
|
|
99
162
|
const setupCategory2 = await clack.confirm({
|
|
100
163
|
message,
|
|
101
164
|
initialValue: category.required
|
|
102
165
|
});
|
|
103
|
-
if (clack.isCancel(setupCategory2) || !setupCategory2)
|
|
166
|
+
if (clack.isCancel(setupCategory2) || !setupCategory2) {
|
|
167
|
+
console.info(import_picocolors.default.gray(` Skipping ${category.name}`));
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
104
170
|
console.info(import_picocolors.default.gray(`
|
|
105
171
|
${category.description}
|
|
106
172
|
`));
|
|
107
|
-
for (const variable of category.variables)
|
|
108
|
-
|
|
173
|
+
for (const variable of category.variables) {
|
|
174
|
+
await setupVariable(variable, envFile, cwd);
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
109
177
|
}
|
|
110
178
|
async function setupVariable(variable, envFile, cwd) {
|
|
111
|
-
const existingValue = (0, import_env.readEnvVariable)(cwd, variable.key, envFile)
|
|
112
|
-
|
|
113
|
-
|
|
179
|
+
const existingValue = (0, import_env.readEnvVariable)(cwd, variable.key, envFile);
|
|
180
|
+
const hasValue = existingValue && existingValue !== "" && !existingValue.includes("your-");
|
|
181
|
+
console.info("");
|
|
182
|
+
console.info(import_picocolors.default.bold(variable.label));
|
|
183
|
+
console.info(import_picocolors.default.gray(variable.description));
|
|
184
|
+
if (hasValue) {
|
|
114
185
|
const update = await clack.confirm({
|
|
115
186
|
message: `${import_picocolors.default.green("\u2713")} Already configured. Update?`,
|
|
116
|
-
initialValue:
|
|
187
|
+
initialValue: false
|
|
117
188
|
});
|
|
118
|
-
if (clack.isCancel(update) || !update)
|
|
189
|
+
if (clack.isCancel(update) || !update) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
119
192
|
}
|
|
120
|
-
console.info("")
|
|
121
|
-
|
|
193
|
+
console.info("");
|
|
194
|
+
console.info(import_picocolors.default.cyan("Instructions:"));
|
|
195
|
+
variable.instructions.split("\n").forEach(line => {
|
|
122
196
|
console.info(import_picocolors.default.gray(` ${line}`));
|
|
123
|
-
})
|
|
197
|
+
});
|
|
198
|
+
console.info("");
|
|
124
199
|
let value;
|
|
125
200
|
if (variable.generator) {
|
|
126
201
|
const generate = await clack.confirm({
|
|
127
202
|
message: `Generate ${variable.label} automatically?`,
|
|
128
|
-
initialValue:
|
|
203
|
+
initialValue: true
|
|
129
204
|
});
|
|
130
|
-
!clack.isCancel(generate) && generate
|
|
205
|
+
if (!clack.isCancel(generate) && generate) {
|
|
206
|
+
value = variable.generator();
|
|
207
|
+
console.info(import_picocolors.default.green(`\u2713 Generated ${variable.label}`));
|
|
208
|
+
}
|
|
131
209
|
}
|
|
132
|
-
if (!value)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
validate: val => {
|
|
144
|
-
if (variable.required && !val) return "This field is required";
|
|
210
|
+
if (!value) {
|
|
211
|
+
if (variable.type === "multiline") {
|
|
212
|
+
console.info(import_picocolors.default.gray("Paste content (press Enter twice when done):"));
|
|
213
|
+
value = await readMultilineInput();
|
|
214
|
+
} else if (variable.type === "secret") {
|
|
215
|
+
const result = await clack.password({
|
|
216
|
+
message: `Enter ${variable.label}:`,
|
|
217
|
+
mask: "*"
|
|
218
|
+
});
|
|
219
|
+
if (!clack.isCancel(result)) {
|
|
220
|
+
value = result;
|
|
145
221
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
222
|
+
} else {
|
|
223
|
+
const result = await clack.text({
|
|
224
|
+
message: `Enter ${variable.label}:`,
|
|
225
|
+
placeholder: variable.placeholder,
|
|
226
|
+
defaultValue: variable.default,
|
|
227
|
+
validate: val => {
|
|
228
|
+
if (variable.required && !val) {
|
|
229
|
+
return "This field is required";
|
|
230
|
+
}
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
if (!clack.isCancel(result)) {
|
|
235
|
+
value = result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (value && !clack.isCancel(value)) {
|
|
240
|
+
(0, import_env.updateEnvVariable)(cwd, variable.key, value, envFile);
|
|
241
|
+
console.info(import_picocolors.default.green(`\u2713 Saved ${variable.key}`));
|
|
242
|
+
} else if (variable.required) {
|
|
243
|
+
console.info(import_picocolors.default.yellow(`\u26A0 Skipped required variable: ${variable.key}`));
|
|
244
|
+
} else {
|
|
245
|
+
console.info(import_picocolors.default.gray(` Skipped ${variable.key}`));
|
|
148
246
|
}
|
|
149
|
-
value && !clack.isCancel(value) ? ((0, import_env.updateEnvVariable)(cwd, variable.key, value, envFile), console.info(import_picocolors.default.green(`\u2713 Saved ${variable.key}`))) : variable.required ? console.info(import_picocolors.default.yellow(`\u26A0 Skipped required variable: ${variable.key}`)) : console.info(import_picocolors.default.gray(` Skipped ${variable.key}`));
|
|
150
247
|
}
|
|
151
248
|
async function readMultilineInput() {
|
|
152
249
|
return new Promise(resolve2 => {
|
|
@@ -155,27 +252,38 @@ async function readMultilineInput() {
|
|
|
155
252
|
const reader = process.stdin;
|
|
156
253
|
reader.setEncoding("utf8");
|
|
157
254
|
const onData = chunk => {
|
|
158
|
-
const chunkLines = chunk.split(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
255
|
+
const chunkLines = chunk.split("\n");
|
|
256
|
+
for (const line of chunkLines) {
|
|
257
|
+
if (line === "") {
|
|
258
|
+
emptyLineCount++;
|
|
259
|
+
if (emptyLineCount >= 2) {
|
|
260
|
+
reader.removeListener("data", onData);
|
|
261
|
+
resolve2(lines.join("\n"));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
if (emptyLineCount === 1) {
|
|
266
|
+
lines.push("");
|
|
267
|
+
}
|
|
268
|
+
emptyLineCount = 0;
|
|
269
|
+
lines.push(line);
|
|
165
270
|
}
|
|
166
|
-
}
|
|
271
|
+
}
|
|
167
272
|
};
|
|
168
273
|
reader.on("data", onData);
|
|
169
274
|
});
|
|
170
275
|
}
|
|
171
276
|
function listCategories() {
|
|
172
|
-
console.info(import_picocolors.default.bold(
|
|
173
|
-
Available environment categories:
|
|
174
|
-
`));
|
|
277
|
+
console.info(import_picocolors.default.bold("\nAvailable environment categories:\n"));
|
|
175
278
|
for (const category of import_env_categories.envCategories) {
|
|
176
279
|
const status = category.required ? import_picocolors.default.red("required") : import_picocolors.default.gray("optional");
|
|
177
|
-
console.info(` ${import_picocolors.default.cyan(category.id.padEnd(12))} - ${category.name} ${status}`)
|
|
280
|
+
console.info(` ${import_picocolors.default.cyan(category.id.padEnd(12))} - ${category.name} ${status}`);
|
|
281
|
+
console.info(` ${import_picocolors.default.gray(category.description)}`);
|
|
282
|
+
if (category.setupTime) {
|
|
283
|
+
console.info(` ${import_picocolors.default.yellow(category.setupTime)}`);
|
|
284
|
+
}
|
|
285
|
+
console.info("");
|
|
178
286
|
}
|
|
179
|
-
console.info(import_picocolors.default.gray("Run setup for a specific category:"))
|
|
180
|
-
|
|
287
|
+
console.info(import_picocolors.default.gray("Run setup for a specific category:"));
|
|
288
|
+
console.info(import_picocolors.default.cyan(" bun takeout env:setup --category <id>\n"));
|
|
181
289
|
}
|
package/dist/cjs/utils/env.cjs
CHANGED
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var env_exports = {};
|
|
22
24
|
__export(env_exports, {
|
|
@@ -28,9 +30,9 @@ __export(env_exports, {
|
|
|
28
30
|
updateEnvVariable: () => updateEnvVariable
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(env_exports);
|
|
31
|
-
var import_node_crypto = require("node:crypto")
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
var import_node_crypto = require("node:crypto");
|
|
34
|
+
var import_node_fs = require("node:fs");
|
|
35
|
+
var import_node_path = require("node:path");
|
|
34
36
|
function generateSecret(length = 32) {
|
|
35
37
|
return (0, import_node_crypto.randomBytes)(length).toString("hex");
|
|
36
38
|
}
|
|
@@ -38,53 +40,68 @@ function envFileExists(cwd, filename = ".env") {
|
|
|
38
40
|
return (0, import_node_fs.existsSync)((0, import_node_path.join)(cwd, filename));
|
|
39
41
|
}
|
|
40
42
|
function copyEnvFile(cwd, source, target) {
|
|
41
|
-
const sourcePath = (0, import_node_path.join)(cwd, source)
|
|
42
|
-
|
|
43
|
-
if (!(0, import_node_fs.existsSync)(sourcePath))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const sourcePath = (0, import_node_path.join)(cwd, source);
|
|
44
|
+
const targetPath = (0, import_node_path.join)(cwd, target);
|
|
45
|
+
if (!(0, import_node_fs.existsSync)(sourcePath)) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: `Source file ${source} not found`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if ((0, import_node_fs.existsSync)(targetPath)) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: `Target file ${target} already exists`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
51
57
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
(0, import_node_fs.copyFileSync)(sourcePath, targetPath);
|
|
59
|
+
return {
|
|
60
|
+
success: true
|
|
54
61
|
};
|
|
55
62
|
} catch (error) {
|
|
56
63
|
return {
|
|
57
|
-
success:
|
|
64
|
+
success: false,
|
|
58
65
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
59
66
|
};
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
function updateEnvVariable(cwd, key, value, filename = ".env") {
|
|
63
70
|
const envPath = (0, import_node_path.join)(cwd, filename);
|
|
64
|
-
if (!(0, import_node_fs.existsSync)(envPath))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
if (!(0, import_node_fs.existsSync)(envPath)) {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
error: `${filename} not found`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
68
77
|
try {
|
|
69
78
|
let content = (0, import_node_fs.readFileSync)(envPath, "utf-8");
|
|
70
79
|
const keyRegex = new RegExp(`^${key}=.*$`, "m");
|
|
71
|
-
|
|
80
|
+
if (keyRegex.test(content)) {
|
|
81
|
+
content = content.replace(keyRegex, `${key}=${value}`);
|
|
82
|
+
} else {
|
|
83
|
+
content = content.trimEnd() + `
|
|
72
84
|
${key}=${value}
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
(0, import_node_fs.writeFileSync)(envPath, content, "utf-8");
|
|
88
|
+
return {
|
|
89
|
+
success: true
|
|
75
90
|
};
|
|
76
91
|
} catch (error) {
|
|
77
92
|
return {
|
|
78
|
-
success:
|
|
93
|
+
success: false,
|
|
79
94
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
80
95
|
};
|
|
81
96
|
}
|
|
82
97
|
}
|
|
83
98
|
function createEnvLocal(cwd) {
|
|
84
99
|
const envLocalPath = (0, import_node_path.join)(cwd, ".env.local");
|
|
85
|
-
if ((0, import_node_fs.existsSync)(envLocalPath))
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
if ((0, import_node_fs.existsSync)(envLocalPath)) {
|
|
101
|
+
return {
|
|
102
|
+
success: true
|
|
103
|
+
};
|
|
104
|
+
}
|
|
88
105
|
const template = `# Local environment overrides
|
|
89
106
|
# This file is gitignored and never committed
|
|
90
107
|
# Add your personal secrets and local configuration here
|
|
@@ -95,23 +112,27 @@ function createEnvLocal(cwd) {
|
|
|
95
112
|
# AWS_ACCESS_KEY_ID=your-key-here
|
|
96
113
|
`;
|
|
97
114
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
(0, import_node_fs.writeFileSync)(envLocalPath, template, "utf-8");
|
|
116
|
+
return {
|
|
117
|
+
success: true
|
|
100
118
|
};
|
|
101
119
|
} catch (error) {
|
|
102
120
|
return {
|
|
103
|
-
success:
|
|
121
|
+
success: false,
|
|
104
122
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
105
123
|
};
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
function readEnvVariable(cwd, key, filename = ".env") {
|
|
109
127
|
const envPath = (0, import_node_path.join)(cwd, filename);
|
|
110
|
-
if (!(0, import_node_fs.existsSync)(envPath))
|
|
128
|
+
if (!(0, import_node_fs.existsSync)(envPath)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
111
131
|
try {
|
|
112
|
-
const content = (0, import_node_fs.readFileSync)(envPath, "utf-8")
|
|
113
|
-
|
|
114
|
-
|
|
132
|
+
const content = (0, import_node_fs.readFileSync)(envPath, "utf-8");
|
|
133
|
+
const keyRegex = new RegExp(`^${key}=(.*)$`, "m");
|
|
134
|
+
const match = content.match(keyRegex);
|
|
135
|
+
return match?.[1]?.trim().replace(/^["']|["']$/g, "") || null;
|
|
115
136
|
} catch {
|
|
116
137
|
return null;
|
|
117
138
|
}
|