Skip to content

Commit f24fad5

Browse files
committed
improvements
1 parent 175d3dd commit f24fad5

7 files changed

Lines changed: 186 additions & 225 deletions

File tree

config.ts

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import {
1111
modify as modifyJSONC,
1212
parse as parseJSONC,
1313
} from "jsonc-parser";
14-
import {
15-
resolve_config,
16-
resolve_config_with_deploy_config,
17-
} from "./lib/rs_lib.js";
14+
import { resolve_config } from "./lib/rs_lib.js";
1815
import { ValidationError } from "@cliffy/command";
1916
import { createFlow } from "./deploy/create/flow.ts";
2017
import { createApp } from "./deploy/create/mod.ts";
@@ -136,7 +133,6 @@ export async function getApp(
136133
config,
137134
data,
138135
rootPath!,
139-
false,
140136
true,
141137
);
142138
config.org = data.org;
@@ -187,6 +183,7 @@ export function actionHandler<
187183
rootPath?.(...args) ?? Deno.cwd(),
188184
context.config,
189185
context.ignore ?? [],
186+
context.allowNodeModules ?? false,
190187
);
191188
const configContext: ConfigContext = {
192189
...getAppFromConfig(config),
@@ -233,46 +230,39 @@ export function actionHandler<
233230
}
234231

235232
interface Config {
236-
path: string;
237-
content: string;
233+
config?: {
234+
path: string;
235+
content: string;
236+
};
238237
files: string[];
239238
}
240239

241240
async function readConfig(
242241
rootPath: string,
243242
maybeConfigPath: string | undefined,
244243
ignorePaths: string[],
245-
): Promise<Config | null> {
246-
const discoveryPath = resolve(maybeConfigPath || rootPath);
247-
248-
// we prefer the configs with the deploy key. then we fallback to a general
249-
// config, so when we set the values, it uses existing config files instead
250-
// of trying to create a new one (which will still happen if no config file is found)
251-
252-
const config = resolve_config_with_deploy_config(discoveryPath, ignorePaths);
244+
allowNodeModules: boolean,
245+
): Promise<Config> {
246+
const config = resolve_config(
247+
resolve(maybeConfigPath || rootPath),
248+
ignorePaths,
249+
allowNodeModules,
250+
);
253251

254-
if (config) {
252+
if (config.path) {
255253
const path = fromFileUrl(config.config);
256254
const content = await Deno.readTextFile(path);
257-
return { path, content, files: config.files };
258-
}
259-
260-
const configWithoutDeployConfig = resolve_config(discoveryPath, ignorePaths);
261-
262-
if (configWithoutDeployConfig) {
263-
const path = fromFileUrl(configWithoutDeployConfig.config);
264-
const content = await Deno.readTextFile(path);
265-
return { path, content, files: configWithoutDeployConfig.files };
255+
return { config: { path, content }, files: config.files };
266256
}
267257

268-
return null;
258+
return { files: config.files };
269259
}
270260

271261
function getAppFromConfig(
272-
configContent: Config | null,
262+
configContent: Config,
273263
): { org: undefined | string; app: undefined | string; files: string[] } {
274-
if (configContent) {
275-
const config = parseJSONC(configContent.content);
264+
if (configContent.config) {
265+
const config = parseJSONC(configContent.config.content);
276266
if (
277267
typeof config === "object" && config !== null && "deploy" in config &&
278268
typeof config.deploy === "object" && config.deploy !== null &&
@@ -289,19 +279,19 @@ function getAppFromConfig(
289279
return {
290280
org: undefined,
291281
app: undefined,
292-
files: configContent?.files ?? [],
282+
files: configContent.files,
293283
};
294284
}
295285

296286
async function writeConfig(
297-
configContent: Config | null,
287+
configContent: Config,
298288
{ org, app }: { org: undefined | string; app: undefined | string },
299289
) {
300290
if (!org) {
301291
return;
302292
}
303293

304-
const content = configContent?.content ?? "{}\n";
294+
const content = configContent.config?.content ?? "{}\n";
305295

306296
const newConfig: Record<string, string> = { org };
307297

@@ -317,7 +307,7 @@ async function writeConfig(
317307
});
318308
const out = applyJSONCEdits(content, edits);
319309
await Deno.writeTextFile(
320-
configContent?.path ?? join(Deno.cwd(), "deno.jsonc"),
310+
configContent.config?.path ?? join(Deno.cwd(), "deno.jsonc"),
321311
out,
322312
);
323313

0 commit comments

Comments
 (0)