MCPcopy
hub / github.com/ionic-team/capacitor / loadConfig

Function loadConfig

cli/src/config.ts:34–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32export const CONFIG_FILE_NAME_JSON = 'capacitor.config.json';
33
34export async function loadConfig(): Promise<Config> {
35 const appRootDir = process.cwd();
36 const cliRootDir = dirname(__dirname);
37 const conf = await loadExtConfig(appRootDir);
38
39 const depsForNx = await (async (): Promise<{ devDependencies: any; dependencies: any } | object> => {
40 if (isNXMonorepo(appRootDir)) {
41 const rootOfNXMonorepo = findNXMonorepoRoot(appRootDir);
42 const pkgJSONOfMonorepoRoot: any = await tryFn(readJSON, resolve(rootOfNXMonorepo, 'package.json'));
43 const devDependencies = pkgJSONOfMonorepoRoot?.devDependencies ?? {};
44 const dependencies = pkgJSONOfMonorepoRoot?.dependencies ?? {};
45 return {
46 devDependencies,
47 dependencies,
48 };
49 }
50 return {};
51 })();
52
53 const appId = conf.extConfig.appId ?? '';
54 const appName = conf.extConfig.appName ?? '';
55 const webDir = conf.extConfig.webDir ?? 'www';
56 const cli = await loadCLIConfig(cliRootDir);
57
58 const config: Config = {
59 android: await loadAndroidConfig(appRootDir, conf.extConfig, cli),
60 ios: await loadIOSConfig(appRootDir, conf.extConfig),
61 web: await loadWebConfig(appRootDir, webDir),
62 cli,
63 app: {
64 rootDir: appRootDir,
65 appId,
66 appName,
67 webDir,
68 webDirAbs: resolve(appRootDir, webDir),
69 package: (await tryFn(readJSON, resolve(appRootDir, 'package.json'))) ?? {
70 name: appName,
71 version: '1.0.0',
72 ...depsForNx,
73 },
74 ...conf,
75 },
76 };
77
78 debug('config: %O', config);
79
80 return config;
81}
82
83export async function writeConfig(extConfig: ExternalConfig, extConfigFilePath: string): Promise<void> {
84 switch (extname(extConfigFilePath)) {

Callers 2

makeConfigFunction · 0.90
runFunction · 0.90

Calls 8

isNXMonorepoFunction · 0.90
findNXMonorepoRootFunction · 0.90
tryFnFunction · 0.90
loadExtConfigFunction · 0.85
loadCLIConfigFunction · 0.85
loadAndroidConfigFunction · 0.85
loadIOSConfigFunction · 0.85
loadWebConfigFunction · 0.85

Tested by

no test coverage detected