-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathstart.ts
More file actions
1193 lines (1050 loc) · 32.6 KB
/
start.ts
File metadata and controls
1193 lines (1050 loc) · 32.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { MetadataGroup, validators } from '@ionic/cli-framework';
import { isValidURL, slugify } from '@ionic/cli-framework/utils/string';
import { mkdir, pathExists, remove, unlink } from '@ionic/utils-fs';
import { columnar, prettyPath } from '@ionic/utils-terminal';
import chalk from 'chalk';
import { debug as Debug } from 'debug';
import * as path from 'path';
import { COLUMNAR_OPTIONS, PROJECT_FILE, ANGULAR_STANDALONE } from '../constants';
import {
CommandInstanceInfo,
CommandLineInputs,
CommandLineOptions,
CommandMetadata,
CommandPreRun,
IProject,
IShellRunOptions,
ProjectType,
ResolvedStarterTemplate,
StarterManifest,
} from '../definitions';
import { failure, input, strong } from '../lib/color';
import { Command } from '../lib/command';
import { FatalException } from '../lib/errors';
import { runCommand } from '../lib/executor';
import {
createProjectFromDetails,
createProjectFromDirectory,
isValidProjectId,
} from '../lib/project';
import { promptToSignup } from '../lib/session';
import { prependNodeModulesBinToPath } from '../lib/shell';
import {
AppSchema,
STARTER_BASE_URL,
STARTER_TEMPLATES,
SUPPORTED_FRAMEWORKS,
getAdvertisement,
getStarterList,
getStarterProjectTypes,
readStarterManifest,
verifyOptions,
} from '../lib/start';
import { emoji } from '../lib/utils/emoji';
import { createRequest } from '../lib/utils/http';
const debug = Debug('ionic:commands:start');
interface StartWizardApp {
type: ProjectType;
name: string;
appId: string;
template: string;
'package-id': string;
tid: string;
email: string;
theme: string;
ip: string;
appIcon: string;
appSplash: string;
utm: { [key: string]: string };
}
export class StartCommand extends Command implements CommandPreRun {
private canRemoveExisting = false;
private schema?: AppSchema;
async getMetadata(): Promise<CommandMetadata> {
return {
name: 'start',
type: 'global',
summary: 'Create a new project',
description: `
This command creates a working Ionic app. It installs dependencies for you and sets up your project.
Running ${input(
'ionic start'
)} without any arguments will prompt you for information about your new project.
The first argument is your app's ${input(
'name'
)}. Don't worry--you can always change this later. The ${input(
'--project-id'
)} is generated from ${input('name')} unless explicitly specified.
The second argument is the ${input(
'template'
)} from which to generate your app. You can list all templates with the ${input(
'--list'
)} option. You can also specify a git repository URL for ${input(
'template'
)}, in which case the existing project will be cloned.
Use the ${input(
'--type'
)} option to start projects using a different JavaScript Framework. Use ${input(
'--list'
)} to see all project types and templates.
`,
exampleCommands: [
'',
'--list',
'myApp',
'myApp blank',
'myApp tabs --capacitor',
'myApp list --type=vue',
'"My App" blank',
'"Conference App" https://github.com/ionic-team/ionic-conference-app',
],
inputs: [
{
name: 'name',
summary: `The name of your new project (e.g. ${input(
'myApp'
)}, ${input('"My App"')})`,
validators: [validators.required],
},
{
name: 'template',
summary: `The starter template to use (e.g. ${['blank', 'tabs']
.map((t) => input(t))
.join(', ')}; use ${input('--list')} to see all)`,
validators: [validators.required],
},
],
options: [
{
name: 'list',
summary: 'List available starter templates',
type: Boolean,
aliases: ['l'],
},
{
name: 'type',
summary: `Type of project to start (e.g. ${getStarterProjectTypes()
.map((type) => input(type))
.join(', ')})`,
type: String,
},
{
name: 'cordova',
summary: 'Include Cordova integration',
type: Boolean,
groups: [MetadataGroup.DEPRECATED],
},
{
name: 'capacitor',
summary: 'Include Capacitor integration',
type: Boolean,
},
{
name: 'deps',
summary: 'Do not install npm/yarn dependencies',
type: Boolean,
default: true,
groups: [MetadataGroup.ADVANCED],
},
{
name: 'git',
summary: 'Do not initialize a git repo',
type: Boolean,
default: true,
groups: [MetadataGroup.ADVANCED],
},
{
name: 'link',
summary: 'Connect your new app to Ionic',
type: Boolean,
groups: [MetadataGroup.ADVANCED],
},
{
name: 'id',
summary: 'Specify an Ionic App ID to link',
},
{
name: 'project-id',
summary:
'Specify a slug for your app (used for the directory name and package name)',
groups: [MetadataGroup.ADVANCED],
spec: { value: 'slug' },
},
{
name: 'package-id',
summary:
'Specify the bundle ID/application ID for your app (reverse-DNS notation)',
groups: [MetadataGroup.ADVANCED],
spec: { value: 'id' },
},
{
name: 'start-id',
summary:
'Used by the Ionic app start experience to generate an associated app locally',
groups: [MetadataGroup.HIDDEN],
spec: { value: 'id' },
},
{
name: 'tag',
summary: `Specify a tag to use for the starters (e.g. ${[
'latest',
'testing',
'next',
]
.map((t) => input(t))
.join(', ')})`,
default: 'latest',
groups: [MetadataGroup.HIDDEN],
},
],
};
}
async startIdStart(inputs: CommandLineInputs, options: CommandLineOptions) {
const startId = options['start-id'];
const wizardApiUrl =
process.env.START_WIZARD_URL_BASE || `https://ionicframework.com`;
const { req } = await createRequest(
'GET',
`${wizardApiUrl}/api/v1/wizard/app/${startId}`,
this.env.config.getHTTPConfig()
);
const error = (e?: Error) => {
this.env.log.error(
`No such app ${chalk.bold(
startId
)}. This app configuration may have expired. Please retry at https://ionicframework.com/start`
);
if (e) {
throw e;
}
};
let data: StartWizardApp;
try {
const ret = await req;
if (ret.status !== 200) {
return error();
}
data = (await req).body as StartWizardApp;
if (!data) {
return error();
}
} catch (e: any) {
return error(e);
}
let projectDir = slugify(data.name);
if (inputs.length === 1) {
projectDir = inputs[0];
}
await this.checkForExisting(projectDir);
inputs.push(data.name);
inputs.push(data.template);
await this.startIdConvert(startId as string);
const appIconBuffer = data.appIcon
? Buffer.from(
data.appIcon.replace(/^data:image\/\w+;base64,/, ''),
'base64'
)
: undefined;
const splashBuffer = data.appSplash
? Buffer.from(
data.appSplash.replace(/^data:image\/\w+;base64,/, ''),
'base64'
)
: undefined;
this.schema = {
cloned: false,
name: data.name,
type: data.type,
template: data.template,
projectId: slugify(data.name),
projectDir,
packageId: data['package-id'],
appflowId: undefined,
appIcon: appIconBuffer,
splash: splashBuffer,
themeColor: data.theme,
};
}
async startIdConvert(id: string) {
const wizardApiUrl =
process.env.START_WIZARD_URL_BASE || `https://ionicframework.com`;
if (!wizardApiUrl) {
return;
}
const { req } = await createRequest(
'POST',
`${wizardApiUrl}/api/v1/wizard/app/${id}/start`,
this.env.config.getHTTPConfig()
);
try {
await req;
} catch (e: any) {
this.env.log.warn(`Unable to set app flag on server: ${e.message}`);
}
}
/**
* Check if we should use the wizard for the start command.
* We should use if they ran `ionic start` or `ionic start --capacitor`
* and they are in an interactive environment.
*/
async shouldUseStartWizard(
inputs: CommandLineInputs,
options: CommandLineOptions
) {
const flagsToTestFor = [
'list',
'l',
'cordova',
'link',
'help',
'h',
'type',
'id',
'project-id',
'package-id',
'start-id',
];
let didUseFlags = false;
for (const key of flagsToTestFor) {
if (options[key] !== null) {
didUseFlags = true;
break;
}
}
return (
inputs.length === 0 &&
options['interactive'] &&
options['deps'] &&
options['git'] &&
!didUseFlags
);
}
async preRun(
inputs: CommandLineInputs,
options: CommandLineOptions
): Promise<void> {
const { promptToLogin } = await import('../lib/session');
verifyOptions(options, this.env);
if (await this.shouldUseStartWizard(inputs, options)) {
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message: 'Use the app creation wizard?',
default: true,
});
if (confirm) {
const startId = await this.env.session.wizardLogin();
if (!startId) {
this.env.log.error(
'There was an issue using the web wizard. Falling back to CLI wizard.'
);
} else {
options['start-id'] = startId;
}
}
}
const appflowId = options['id'] ? String(options['id']) : undefined;
if (appflowId) {
if (!this.env.session.isLoggedIn()) {
await promptToLogin(this.env);
}
}
// The start wizard pre-populates all arguments for the CLI
if (options['start-id']) {
await this.startIdStart(inputs, options);
return;
}
let projectType = isValidURL(inputs[1])
? 'custom'
: options['type']
? String(options['type'])
: await this.getProjectType();
if (options['cordova']) {
const { checkForUnsupportedProject } = await import(
'../lib/integrations/cordova/utils'
);
try {
await checkForUnsupportedProject(projectType as ProjectType);
} catch (e: any) {
this.env.log.error(e.message);
options['cordova'] = false;
}
}
if (!inputs[0]) {
if (appflowId) {
const { AppClient } = await import('../lib/app');
const token = await this.env.session.getUserToken();
const appClient = new AppClient(token, this.env);
const tasks = this.createTaskChain();
tasks.next(`Looking up app ${input(appflowId)}`);
const app = await appClient.load(appflowId);
// TODO: can ask to clone via repo_url
tasks.end();
this.env.log.info(
`Using ${strong(app.name)} for ${input('name')} and ${strong(
app.slug
)} for ${input('--project-id')}.`
);
inputs[0] = app.name;
options['project-id'] = app.slug;
} else {
if (this.env.flags.interactive) {
this.env.log.nl();
this.env.log.msg(
`${strong(`Every great app needs a name! ${emoji('😍', '')}`)}\n` +
`Please enter the full name of your app. You can change this at any time. To bypass this prompt next time, supply ${input(
'name'
)}, the first argument to ${input('ionic start')}.\n\n`
);
}
const name = await this.env.prompt({
type: 'input',
name: 'name',
message: 'Project name:',
validate: (v) => validators.required(v),
});
inputs[0] = name;
}
}
if (!inputs[1]) {
if (this.env.flags.interactive) {
this.env.log.nl();
this.env.log.msg(
`${strong(
`Let's pick the perfect starter template! ${emoji('💪', '')}`
)}\n` +
`Starter templates are ready-to-go Ionic apps that come packed with everything you need to build your app. To bypass this prompt next time, supply ${input(
'template'
)}, the second argument to ${input('ionic start')}.\n\n`
);
}
const template = await this.env.prompt({
type: 'list',
name: 'template',
message: 'Starter template:',
choices: () => {
const starterTemplateList = STARTER_TEMPLATES.filter(
(st) => st.projectType === projectType
);
const cols = columnar(
starterTemplateList.map(({ name, description }) => [
input(name),
description || '',
]),
COLUMNAR_OPTIONS
).split('\n');
if (starterTemplateList.length === 0) {
throw new FatalException(
`No starter templates found for project type: ${input(
projectType
)}.`
);
}
return starterTemplateList.map((starter, i) => {
return {
name: cols[i],
short: starter.name,
value: starter.name,
};
});
},
});
inputs[1] = template;
}
let starterTemplate = STARTER_TEMPLATES.find(
(t) => t.name === inputs[1] && t.projectType === projectType
);
if (projectType === 'angular') {
const angularMode = await this.env.prompt({
type: 'list',
name: 'standalone',
message: 'Would you like to build your app with Standalone Components or NgModules? \n Standalone components are the default way to build with Angular that simplifies the way you build your app. \n To learn more, visit the Angular docs:\n https://angular.dev/guide/components\n\n',
choices: () => [
{
name: 'Standalone',
short: 'Standalone',
value: 'standalone',
},
{
name: 'NgModules',
short: 'NgModules',
value: 'ngModules',
}
],
});
/**
* If the developer wants to use standalone
* components then we need to get the correct starter.
*/
if (angularMode === 'standalone') {
/**
* Attempt to find the same type of starter
* but with standalone components.
*/
const standaloneStarter = STARTER_TEMPLATES.find((t) => t.name === inputs[1] && t.projectType === ANGULAR_STANDALONE);
/**
* If found, update the projectType and
* starterTemplate vars to use the new project.
* If no project is found it will continue
* to use the NgModule version.
*/
if (standaloneStarter !== undefined) {
projectType = ANGULAR_STANDALONE;
starterTemplate = standaloneStarter;
}
}
}
if (starterTemplate && starterTemplate.type === 'repo') {
inputs[1] = starterTemplate.repo;
}
const cloned = isValidURL(inputs[1]);
if (this.project && this.project.details.context === 'app') {
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message:
'You are already in an Ionic project directory. Do you really want to start another project here?',
default: false,
});
if (!confirm) {
this.env.log.info('Not starting project within existing project.');
throw new FatalException();
}
}
await this.validateProjectType(projectType);
if (cloned) {
if (!options['git']) {
this.env.log.warn(
`The ${input(
'--no-git'
)} option has no effect when cloning apps. Git must be used.`
);
}
options['git'] = true;
}
if (options['v1'] || options['v2']) {
throw new FatalException(
`The ${input('--v1')} and ${input('--v2')} flags have been removed.\n` +
`Use the ${input('--type')} option. (see ${input(
'ionic start --help'
)})`
);
}
if (options['app-name']) {
this.env.log.warn(
`The ${input('--app-name')} option has been removed. Use the ${input(
'name'
)} argument with double quotes: e.g. ${input('ionic start "My App"')}`
);
}
if (options['display-name']) {
this.env.log.warn(
`The ${input(
'--display-name'
)} option has been removed. Use the ${input(
'name'
)} argument with double quotes: e.g. ${input('ionic start "My App"')}`
);
}
if (options['bundle-id']) {
this.env.log.warn(
`The ${input(
'--bundle-id'
)} option has been deprecated. Please use ${input('--package-id')}.`
);
options['package-id'] = options['bundle-id'];
}
let projectId = options['project-id']
? String(options['project-id'])
: undefined;
if (projectId) {
await this.validateProjectId(projectId);
} else {
projectId = options['project-id'] = isValidProjectId(inputs[0])
? inputs[0]
: slugify(inputs[0]);
}
const projectDir = path.resolve(projectId);
const packageId = options['package-id']
? String(options['package-id'])
: undefined;
if (projectId) {
await this.checkForExisting(projectDir);
}
if (cloned) {
this.schema = {
cloned: true,
url: inputs[1],
projectId,
projectDir,
};
} else {
this.schema = {
cloned: false,
name: inputs[0],
type: projectType as ProjectType,
template: inputs[1],
projectId,
projectDir,
packageId,
appflowId,
themeColor: undefined,
};
}
}
async getProjectType() {
if (this.env.flags.interactive) {
this.env.log.nl();
this.env.log.msg(
`${strong(`Pick a framework! ${emoji('😁', '')}`)}\n\n` +
`Please select the JavaScript framework to use for your new app. To bypass this prompt next time, supply a value for the ${input(
'--type'
)} option.\n\n`
);
}
const frameworkChoice = await this.env.prompt({
type: 'list',
name: 'frameworks',
message: 'Framework:',
default: 'angular',
choices: () => {
const cols = columnar(
SUPPORTED_FRAMEWORKS.map(({ name, description }) => [
input(name),
description,
]),
COLUMNAR_OPTIONS
).split('\n');
return SUPPORTED_FRAMEWORKS.map((starterTemplate, i) => {
return {
name: cols[i],
short: starterTemplate.name,
value: starterTemplate.type,
};
});
},
});
return frameworkChoice;
}
async run(
inputs: CommandLineInputs,
options: CommandLineOptions,
runinfo: CommandInstanceInfo
): Promise<void> {
const { pkgManagerArgs } = await import('../lib/utils/npm');
const { getTopLevel, isGitInstalled } = await import('../lib/git');
if (!this.schema) {
throw new FatalException(`Invalid start schema: cannot start app.`);
}
const { projectId, projectDir, packageId, appflowId } = this.schema;
const tag = options['tag'] ? String(options['tag']) : 'latest';
let linkConfirmed = typeof appflowId === 'string';
const gitDesired = options['git'] ? true : false;
const gitInstalled = await isGitInstalled(this.env);
const gitTopLevel = await getTopLevel(this.env);
let gitIntegration =
gitDesired && gitInstalled && !gitTopLevel ? true : false;
if (!gitInstalled) {
const installationDocs = `See installation docs for git: ${strong(
'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git'
)}`;
if (appflowId) {
throw new FatalException(
`Git CLI not found on your PATH.\n` +
`Git must be installed to connect this app to Ionic. ${installationDocs}`
);
}
if (this.schema.cloned) {
throw new FatalException(
`Git CLI not found on your PATH.\n` +
`Git must be installed to clone apps with ${input(
'ionic start'
)}. ${installationDocs}`
);
}
}
if (gitTopLevel && !this.schema.cloned) {
this.env.log.info(
`Existing git project found (${strong(
gitTopLevel
)}). Git operations are disabled.`
);
}
const tasks = this.createTaskChain();
tasks.next(`Preparing directory ${input(prettyPath(projectDir))}`);
if (this.canRemoveExisting) {
await remove(projectDir);
}
await mkdir(projectDir);
tasks.end();
if (this.schema.cloned) {
await this.env.shell.run(
'git',
['clone', this.schema.url, projectDir, '--progress'],
{ stdio: 'inherit' }
);
} else {
const starterTemplate = await this.findStarterTemplate(
this.schema.template,
this.schema.type,
tag
);
await this.downloadStarterTemplate(projectDir, starterTemplate);
}
let project: IProject | undefined;
if (
this.project &&
this.project.details.context === 'multiapp' &&
!this.schema.cloned
) {
// We're in a multi-app setup, so the new config file isn't wanted.
await unlink(path.resolve(projectDir, PROJECT_FILE));
project = await createProjectFromDetails(
{
context: 'multiapp',
configPath: path.resolve(this.project.rootDirectory, PROJECT_FILE),
id: projectId,
type: this.schema.type,
errors: [],
},
this.env
);
project.config.set('type', this.schema.type);
project.config.set(
'root',
path.relative(this.project.rootDirectory, projectDir)
);
} else {
project = await createProjectFromDirectory(
projectDir,
{ _: [] },
this.env,
{ logErrors: false }
);
}
// start is weird, once the project directory is created, it becomes a
// "project" command and so we replace the `Project` instance that was
// autogenerated when the CLI booted up. This has worked thus far?
this.namespace.root.project = project;
if (!this.project) {
throw new FatalException('Error while loading project.');
}
this.env.shell.alterPath = (p) =>
prependNodeModulesBinToPath(projectDir, p);
if (!this.schema.cloned) {
if (this.schema.type === 'react' || this.schema.type === 'vue') {
options['capacitor'] = true;
}
if (
(this.schema.type === 'angular' || this.schema.type === 'angular-standalone')
&& options['cordova'] === null
) {
options['capacitor'] = true;
}
if (options['cordova']) {
const { confirmCordovaUsage } = await import(
'../lib/integrations/cordova/utils'
);
const confirm = await confirmCordovaUsage(this.env);
if (confirm) {
await runCommand(runinfo, [
'integrations',
'enable',
'cordova',
'--quiet',
]);
} else {
options['cordova'] = false;
}
}
if (options['capacitor'] === null && !options['cordova']) {
const confirm = await this.env.prompt({
type: 'confirm',
name: 'confirm',
message:
'Integrate your new app with Capacitor to target native iOS and Android?',
default: false,
});
if (confirm) {
options['capacitor'] = true;
}
}
if (options['capacitor']) {
await runCommand(runinfo, [
'integrations',
'enable',
'capacitor',
'--quiet',
'--',
this.schema.name,
packageId ? packageId : 'io.ionic.starter',
]);
}
await this.project.personalize({
name: this.schema.name,
projectId,
packageId,
appIcon: this.schema.appIcon,
splash: this.schema.splash,
themeColor: this.schema.themeColor,
});
this.env.log.nl();
}
const shellOptions: IShellRunOptions = {
cwd: projectDir,
stdio: 'inherit',
};
if (options['deps']) {
this.env.log.msg('Installing dependencies may take several minutes.');
this.env.log.rawmsg(getAdvertisement());
const [installer, ...installerArgs] = await pkgManagerArgs(
this.env.config.get('npmClient'),
{ command: 'install' }
);
await this.env.shell.run(installer, installerArgs, shellOptions);
if (options['cordova']) {
try {
await this.env.shell.run(
'ng',
['add', '@ionic/cordova-builders', '--skip-confirmation'],
{ cwd: this.project.rootDirectory }
);
} catch (e: any) {
debug('Error while adding @ionic/cordova-builders: %O', e);
}
}
} else {
// --no-deps flag was used so skip installing dependencies, this also results in the package.json being out sync with the package.json so warn the user
this.env.log.warn(
'Using the --no-deps flag results in an out of date package lock file. The lock file can be updated by performing an `install` with your package manager.'
);
if (options['cordova']) {
this.env.log.warn(
"@ionic/cordova-builders couldn't be added, make sure you run `ng add @ionic/cordova-builders` after performing an `install` with your package manager."
);
}
}
if (!this.schema.cloned) {
if (gitIntegration) {
try {
await this.env.shell.run('git', ['init'], shellOptions); // TODO: use initializeRepo()?
} catch (e: any) {
this.env.log.warn(
'Error encountered during repo initialization. Disabling further git operations.'
);
gitIntegration = false;
}
}
// Prompt to create account
if (!this.env.session.isLoggedIn()) {
await promptToSignup(this.env);
}
if (options['link']) {
const cmdArgs = ['link'];
if (appflowId) {
cmdArgs.push(appflowId);
}
cmdArgs.push('--name', this.schema.name);
await runCommand(runinfo, cmdArgs);
linkConfirmed = true;
}
const manifestPath = path.resolve(projectDir, 'ionic.starter.json');
const manifest = await this.loadManifest(manifestPath);
if (manifest) {
await unlink(manifestPath);
}
if (gitIntegration) {
try {
await this.env.shell.run('git', ['add', '-A'], shellOptions);
await this.env.shell.run(
'git',
['commit', '-m', 'Initial commit', '--no-gpg-sign'],
shellOptions
);
} catch (e: any) {
this.env.log.warn(
'Error encountered during commit. Disabling further git operations.'
);
gitIntegration = false;
}
}
if (manifest) {
await this.performManifestOps(manifest);
}
}
this.env.log.nl();
await this.showNextSteps(
projectDir,
this.schema.cloned,
linkConfirmed,