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

Function initCommand

cli/src/tasks/init.ts:16–70  ·  view source on GitHub ↗
(
  config: Config,
  name: string,
  id: string,
  webDirFromCLI?: string,
  skipAppIDValidation?: boolean,
)

Source from the content-addressed store, hash-verified

14import { checkInteractive, isInteractive } from '../util/term';
15
16export async function initCommand(
17 config: Config,
18 name: string,
19 id: string,
20 webDirFromCLI?: string,
21 skipAppIDValidation?: boolean,
22): Promise<void> {
23 try {
24 if (!checkInteractive(name, id)) {
25 return;
26 }
27
28 if (config.app.extConfigType !== 'json') {
29 fatal(
30 `Cannot run ${c.input('init')} for a project using a non-JSON configuration file.\n` +
31 `Delete ${c.strong(config.app.extConfigName)} and try again.`,
32 );
33 }
34
35 const isNewConfig = Object.keys(config.app.extConfig).length === 0;
36 const tsInstalled = !!resolveNode(config.app.rootDir, 'typescript');
37 const appName = await getName(config, name);
38 const appId = await getAppId(config, id);
39 const webDir = isInteractive()
40 ? await getWebDir(config, webDirFromCLI)
41 : (webDirFromCLI ?? config.app.extConfig.webDir ?? 'www');
42
43 if (skipAppIDValidation === true) {
44 await check([() => checkAppName(config, appName)]);
45 } else {
46 await check([() => checkAppName(config, appName), () => checkAppId(config, appId)]);
47 }
48
49 const cordova = await getCordovaPreferences(config);
50
51 await runMergeConfig(
52 config,
53 {
54 appId,
55 appName,
56 webDir,
57 cordova,
58 },
59 isNewConfig && tsInstalled ? 'ts' : 'json',
60 );
61 } catch (e: any) {
62 if (!isFatal(e)) {
63 output.write('Usage: npx cap init appName appId\n' + 'Example: npx cap init "My App" "com.example.myapp"\n\n');
64
65 fatal(e.stack ?? e);
66 }
67
68 throw e;
69 }
70}
71
72async function getName(config: Config, name: string) {
73 if (!name) {

Callers 1

runProgramFunction · 0.85

Calls 13

checkInteractiveFunction · 0.90
fatalFunction · 0.90
resolveNodeFunction · 0.90
isInteractiveFunction · 0.90
checkFunction · 0.90
checkAppNameFunction · 0.90
checkAppIdFunction · 0.90
getCordovaPreferencesFunction · 0.90
isFatalFunction · 0.90
getNameFunction · 0.85
getAppIdFunction · 0.85
runMergeConfigFunction · 0.85

Tested by

no test coverage detected