@cimplify/cli 0.10.2 → 0.11.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/dist/{add-6PVHGAJP.mjs → add-5ODVFWVR.mjs} +1 -1
- package/dist/{chunk-KKF32YXC.mjs → chunk-3NDTR4GA.mjs} +1 -1
- package/dist/{chunk-GPKW7DBG.mjs → chunk-OMAF2H6T.mjs} +1 -1
- package/dist/chunk-W3WLADJP.mjs +6455 -0
- package/dist/dev-B4YUYQ4I.mjs +782 -0
- package/dist/dispatcher.mjs +10 -10
- package/dist/{doctor-UUXIF36D.mjs → doctor-LAKJKBFU.mjs} +2 -2
- package/dist/{explain-7OIAZHWH.mjs → explain-EZ7DC4KE.mjs} +1 -1
- package/dist/{introspect-5O3J24CP.mjs → introspect-HVT3TMAM.mjs} +2 -2
- package/dist/{list-YYJJMYHM.mjs → list-27TS2L47.mjs} +1 -1
- package/dist/{update-BEGOQQG2.mjs → update-74UVN3R7.mjs} +1 -1
- package/package.json +1 -1
- package/dist/chunk-QDW6ND55.mjs +0 -6455
- package/dist/dev-ABN3HOO2.mjs +0 -150
package/dist/dev-ABN3HOO2.mjs
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { parseEnvFile, formatEnvFile } from './chunk-DBZ3UOQ2.mjs';
|
|
3
|
-
import { ENV_SCOPE, PUBLIC_ENV_PREFIX } from './chunk-MXYUAJEW.mjs';
|
|
4
|
-
import { parseArgs, flagBool } from './chunk-C4M3DXKC.mjs';
|
|
5
|
-
import { ApiClient } from './chunk-F4S5KETY.mjs';
|
|
6
|
-
import { readAuth, readProjectLink } from './chunk-UBAI443T.mjs';
|
|
7
|
-
import { info, CliError, CLI_ERROR_CODE, dim } from './chunk-E2T2SBP5.mjs';
|
|
8
|
-
import { spawn } from 'child_process';
|
|
9
|
-
import { promises } from 'fs';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
|
|
12
|
-
var FLAG_REMOTE = "remote";
|
|
13
|
-
var PACKAGE_JSON = "package.json";
|
|
14
|
-
var ENV_LOCAL_FILE = ".env.local";
|
|
15
|
-
var PUBLIC_API_URL_KEY = "NEXT_PUBLIC_CIMPLIFY_API_URL";
|
|
16
|
-
var SCRIPT_DEV = "dev";
|
|
17
|
-
var PREVIEW_ORIGIN_ENV = "CIMPLIFY_PREVIEW_ORIGIN";
|
|
18
|
-
async function applyPreviewOrigin(cwd, origin) {
|
|
19
|
-
const { ensurePreviewOrigin } = await import('./preview-config-CHDYYWUY.mjs');
|
|
20
|
-
try {
|
|
21
|
-
const result = await ensurePreviewOrigin(cwd, origin);
|
|
22
|
-
if (result.status === "unrecognized") {
|
|
23
|
-
info(
|
|
24
|
-
dim(
|
|
25
|
-
`(preview: could not resolve ${result.file} config shape; hot-reload may be limited)`
|
|
26
|
-
)
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
} catch (err) {
|
|
30
|
-
info(dim(`(preview: dev-origin setup skipped: ${err.message})`));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
var PM_BUN = "bun";
|
|
34
|
-
var PM_PNPM = "pnpm";
|
|
35
|
-
var PM_YARN = "yarn";
|
|
36
|
-
var PM_NPM = "npm";
|
|
37
|
-
var LOCKFILE_BUN = "bun.lock";
|
|
38
|
-
var LOCKFILE_BUN_BINARY = "bun.lockb";
|
|
39
|
-
var LOCKFILE_PNPM = "pnpm-lock.yaml";
|
|
40
|
-
var LOCKFILE_YARN = "yarn.lock";
|
|
41
|
-
var BUNFIG = "bunfig.toml";
|
|
42
|
-
function envEndpoint(businessId, projectId) {
|
|
43
|
-
return `/v1/businesses/${encodeURIComponent(businessId)}/projects/${encodeURIComponent(projectId)}/env-vars`;
|
|
44
|
-
}
|
|
45
|
-
async function detectPackageManager(cwd) {
|
|
46
|
-
if (await pathExists(path.join(cwd, LOCKFILE_BUN))) return PM_BUN;
|
|
47
|
-
if (await pathExists(path.join(cwd, LOCKFILE_BUN_BINARY))) return PM_BUN;
|
|
48
|
-
if (await pathExists(path.join(cwd, BUNFIG))) return PM_BUN;
|
|
49
|
-
if (await pathExists(path.join(cwd, LOCKFILE_PNPM))) return PM_PNPM;
|
|
50
|
-
if (await pathExists(path.join(cwd, LOCKFILE_YARN))) return PM_YARN;
|
|
51
|
-
return PM_NPM;
|
|
52
|
-
}
|
|
53
|
-
async function pathExists(target) {
|
|
54
|
-
try {
|
|
55
|
-
await promises.stat(target);
|
|
56
|
-
return true;
|
|
57
|
-
} catch (err) {
|
|
58
|
-
if (err.code === "ENOENT") return false;
|
|
59
|
-
throw err;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async function readPackageJson(cwd) {
|
|
63
|
-
const pkgPath = path.join(cwd, PACKAGE_JSON);
|
|
64
|
-
let raw;
|
|
65
|
-
try {
|
|
66
|
-
raw = await promises.readFile(pkgPath, "utf8");
|
|
67
|
-
} catch (err) {
|
|
68
|
-
if (err.code === "ENOENT") {
|
|
69
|
-
throw new CliError(
|
|
70
|
-
CLI_ERROR_CODE.INVALID_INPUT,
|
|
71
|
-
`No package.json in ${cwd}. \`cimplify dev\` runs your project's dev script.`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
throw err;
|
|
75
|
-
}
|
|
76
|
-
return JSON.parse(raw);
|
|
77
|
-
}
|
|
78
|
-
function mergeEnvEntries(existing, incoming) {
|
|
79
|
-
const seen = new Set(existing.map((e) => e.key));
|
|
80
|
-
const merged = [...existing];
|
|
81
|
-
for (const entry of incoming) {
|
|
82
|
-
if (seen.has(entry.key)) continue;
|
|
83
|
-
merged.push(entry);
|
|
84
|
-
seen.add(entry.key);
|
|
85
|
-
}
|
|
86
|
-
return merged;
|
|
87
|
-
}
|
|
88
|
-
async function applyRemoteEnv(client, businessId, projectId, apiBaseUrl, cwd) {
|
|
89
|
-
const records = await client.get(envEndpoint(businessId, projectId), {
|
|
90
|
-
query: { scope: ENV_SCOPE.PRODUCTION }
|
|
91
|
-
});
|
|
92
|
-
const incoming = records.filter((r) => r.value !== null && !r.is_secret).map((r) => ({ key: r.key, value: r.value }));
|
|
93
|
-
incoming.push({ key: PUBLIC_API_URL_KEY, value: apiBaseUrl });
|
|
94
|
-
const envPath = path.join(cwd, ENV_LOCAL_FILE);
|
|
95
|
-
let existing = [];
|
|
96
|
-
try {
|
|
97
|
-
const raw = await promises.readFile(envPath, "utf8");
|
|
98
|
-
existing = parseEnvFile(raw);
|
|
99
|
-
} catch (err) {
|
|
100
|
-
if (err.code !== "ENOENT") throw err;
|
|
101
|
-
}
|
|
102
|
-
const merged = mergeEnvEntries(existing, incoming);
|
|
103
|
-
await promises.writeFile(envPath, formatEnvFile(merged), "utf8");
|
|
104
|
-
const publicCount = incoming.filter((e) => e.key.startsWith(PUBLIC_ENV_PREFIX)).length;
|
|
105
|
-
return publicCount;
|
|
106
|
-
}
|
|
107
|
-
async function run(argv) {
|
|
108
|
-
const args = parseArgs(argv);
|
|
109
|
-
const remote = flagBool(args, FLAG_REMOTE);
|
|
110
|
-
const cwd = process.cwd();
|
|
111
|
-
const previewOrigin = process.env[PREVIEW_ORIGIN_ENV];
|
|
112
|
-
if (remote) {
|
|
113
|
-
const auth = await readAuth();
|
|
114
|
-
const link = await readProjectLink();
|
|
115
|
-
const client = ApiClient.fromAuth(auth);
|
|
116
|
-
const publicCount = await applyRemoteEnv(
|
|
117
|
-
client,
|
|
118
|
-
link.businessId,
|
|
119
|
-
link.projectId,
|
|
120
|
-
auth.apiBaseUrl,
|
|
121
|
-
cwd
|
|
122
|
-
);
|
|
123
|
-
const label = link.businessHandle ?? auth.businessHandle ?? auth.businessId;
|
|
124
|
-
info(`Dev mode: connected to ${label} production data (${publicCount} public var${publicCount === 1 ? "" : "s"} merged)`);
|
|
125
|
-
} else if (previewOrigin) {
|
|
126
|
-
info("Dev mode: hosted preview");
|
|
127
|
-
} else {
|
|
128
|
-
info("Dev mode: using local mock (`cimplify mock`)");
|
|
129
|
-
}
|
|
130
|
-
const pkg = await readPackageJson(cwd);
|
|
131
|
-
if (!pkg.scripts || !pkg.scripts[SCRIPT_DEV]) {
|
|
132
|
-
throw new CliError(
|
|
133
|
-
CLI_ERROR_CODE.INVALID_INPUT,
|
|
134
|
-
`No "${SCRIPT_DEV}" script in package.json. Add one (e.g. "next dev") and re-run.`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (previewOrigin) await applyPreviewOrigin(cwd, previewOrigin);
|
|
138
|
-
const pm = await detectPackageManager(cwd);
|
|
139
|
-
info(dim(`(running: ${pm} run ${SCRIPT_DEV})`));
|
|
140
|
-
const child = spawn(pm, ["run", SCRIPT_DEV], { cwd, stdio: "inherit" });
|
|
141
|
-
await new Promise((resolve, reject) => {
|
|
142
|
-
child.on("error", (err) => reject(new CliError(CLI_ERROR_CODE.INVALID_INPUT, `Failed to spawn ${pm}: ${err.message}`)));
|
|
143
|
-
child.on("close", (code) => {
|
|
144
|
-
process.exitCode = code ?? 0;
|
|
145
|
-
resolve();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { run as default, detectPackageManager, mergeEnvEntries };
|