-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathstart.ts
More file actions
349 lines (300 loc) · 10.9 KB
/
start.ts
File metadata and controls
349 lines (300 loc) · 10.9 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
import { readJson } from '@ionic/utils-fs';
import { columnar } from '@ionic/utils-terminal';
import * as lodash from 'lodash';
import { COLUMNAR_OPTIONS, PROJECT_TYPES, ANGULAR_STANDALONE } from '../constants';
import { CommandLineOptions, IConfig, ILogger, ProjectType, StarterList, StarterManifest, StarterTemplate } from '../definitions';
import { isStarterManifest } from '../guards';
import { input, strong, title } from './color';
import { FatalException } from './errors';
import { prettyProjectName } from './project';
import { emoji } from './utils/emoji';
import { createRequest } from './utils/http';
export const STARTER_BASE_URL = 'https://d2ql0qc7j8u4b2.cloudfront.net';
export interface BaseAppSchema {
projectId: string;
projectDir: string;
packageId?: string;
appflowId?: string;
}
export interface NewAppSchema extends BaseAppSchema {
cloned: false;
name: string;
type: ProjectType;
template: string;
themeColor?: string;
appIcon?: Buffer;
splash?: Buffer;
}
export interface ClonedAppSchema extends BaseAppSchema {
cloned: true;
url: string;
}
export type AppSchema = NewAppSchema | ClonedAppSchema;
export function verifyOptions(options: CommandLineOptions, { log }: { log: ILogger; }): void {
// If the action is list then lets just end here.
if (options['list']) {
const typeOption = options['type'] ? String(options['type']) : undefined;
if (typeOption && !PROJECT_TYPES.includes(typeOption as ProjectType)) {
throw new FatalException(
`${input(typeOption)} is not a valid project type.\n` +
`Valid project types are: ${getStarterProjectTypes().map(type => input(type)).join(', ')}`
);
}
const headers = ['name', 'description'].map(h => strong(h));
const starterTypes = typeOption ? [typeOption] : getStarterProjectTypes();
for (const starterType of starterTypes) {
const starters = STARTER_TEMPLATES.filter(template => template.projectType === starterType);
log.rawmsg(`\n${strong(`Starters for ${prettyProjectName(starterType)}`)} (${input(`--type=${starterType}`)})\n\n`);
log.rawmsg(columnar(starters.map(({ name, description }) => [input(name), description || '']), { ...COLUMNAR_OPTIONS, headers }));
log.rawmsg('\n');
}
throw new FatalException('', 0);
}
if (options['skip-deps']) {
log.warn(`The ${input('--skip-deps')} option has been deprecated. Please use ${input('--no-deps')}.`);
options['deps'] = false;
}
if (options['skip-link']) {
log.warn(`The ${input('--skip-link')} option has been deprecated. Please use ${input('--no-link')}.`);
options['link'] = false;
}
if (options['pro-id']) {
log.warn(`The ${input('--pro-id')} option has been deprecated. Please use ${input('--id')}.`);
options['id'] = options['pro-id'];
}
if (options['id']) {
if (options['link'] === false) {
log.warn(`The ${input('--no-link')} option has no effect with ${input('--id')}. App must be linked.`);
}
options['link'] = true;
if (!options['git']) {
log.warn(`The ${input('--no-git')} option has no effect with ${input('--id')}. Git must be used.`);
}
options['git'] = true;
}
}
export async function readStarterManifest(p: string): Promise<StarterManifest> {
try {
const manifest = await readJson(p);
if (!isStarterManifest(manifest)) {
throw new Error(`${p} is not a valid starter manifest.`);
}
return manifest;
} catch (e: any) {
if (e.code === 'ENOENT') {
throw new Error(`${p} not found`);
} else if (e instanceof SyntaxError) {
throw new Error(`${p} is not valid JSON.`);
}
throw e;
}
}
export function getAdvertisement(): string {
const choices = [getAppflowAdvertisement, getAdvisoryAdvertisement, getEnterpriseAdvertisement];
const idx = Math.floor(Math.random() * choices.length);
return `${choices[idx]()}\n\n`;
}
function getAppflowAdvertisement(): string {
return `
──────────────────────────────────────────────────────────────
${title('Ionic Appflow')}, the mobile DevOps solution by Ionic
Continuously build, deploy, and ship apps ${emoji('🚀', '')}
Focus on building apps while we automate the rest ${emoji('🎁', '')}
${emoji(' 👉 ', 'Learn more:')} ${strong('https://ion.link/appflow')} ${emoji(' 👈', '')}
──────────────────────────────────────────────────────────────
`;
}
function getAdvisoryAdvertisement(): string {
return `
──────────────────────────────────────────────────────────────────────────────
${title('Ionic Advisory')}, tailored solutions and expert services by Ionic
Go to market faster ${emoji('🏆', '')}
Real-time troubleshooting and guidance ${emoji('💁', '')}
Custom training, best practices, code and architecture reviews ${emoji('🔎', '')}
Customized strategies for every phase of the development lifecycle ${emoji('🔮', '')}
${emoji(' 👉 ', 'Learn more:')} ${strong('https://ion.link/advisory')} ${emoji(' 👈', '')}
──────────────────────────────────────────────────────────────────────────────
`;
}
function getEnterpriseAdvertisement(): string {
return `
──────────────────────────────────────────────────────────────────────
${title('Ionic Enterprise')}, platform and solutions for teams by Ionic
Powerful library of native APIs ${emoji('⚡️', '')}
A supercharged platform for teams ${emoji('💪', '')}
${emoji(' 👉 ', 'Learn more:')} ${strong('https://ion.link/enterprise')} ${emoji(' 👈', '')}
──────────────────────────────────────────────────────────────────────
`;
}
export async function getStarterList(config: IConfig, tag = 'latest'): Promise<StarterList> {
const { req } = await createRequest('GET', `${STARTER_BASE_URL}/${tag === 'latest' ? '' : `${tag}/`}starters.json`, config.getHTTPConfig());
const res = await req;
// TODO: typecheck
return res.body;
}
export function getStarterProjectTypes(): string[] {
return lodash.uniq([
...STARTER_TEMPLATES.map(t => t.projectType),
'angular-standalone'
]);
}
export interface SupportedFramework {
name: string;
type: ProjectType;
description: string;
}
export const SUPPORTED_FRAMEWORKS: readonly SupportedFramework[] = [
{
name: 'Angular',
type: 'angular',
description: 'https://angular.io',
},
{
name: 'React',
type: 'react',
description: 'https://reactjs.org',
},
{
name: 'Vue',
type: 'vue',
description: 'https://vuejs.org',
},
];
export const STARTER_TEMPLATES: StarterTemplate[] = [
// Vue
{
name: 'tabs',
projectType: 'vue',
type: 'managed',
description: 'A starting project with a simple tabbed interface',
id: 'vue-vite-official-tabs',
},
{
name: 'sidemenu',
projectType: 'vue',
type: 'managed',
description: 'A starting project with a side menu with navigation in the content area',
id: 'vue-vite-official-sidemenu',
},
{
name: 'blank',
projectType: 'vue',
type: 'managed',
description: 'A blank starter project',
id: 'vue-vite-official-blank',
},
{
name: 'list',
projectType: 'vue',
type: 'managed',
description: 'A starting project with a list',
id: 'vue-vite-official-list',
},
// Angular
{
name: 'tabs',
projectType: 'angular',
type: 'managed',
description: 'A starting project with a simple tabbed interface',
id: 'angular-official-tabs',
},
{
name: 'sidemenu',
projectType: 'angular',
type: 'managed',
description: 'A starting project with a side menu with navigation in the content area',
id: 'angular-official-sidemenu',
},
{
name: 'blank',
projectType: 'angular',
type: 'managed',
description: 'A blank starter project',
id: 'angular-official-blank',
},
{
name: 'list',
projectType: 'angular',
type: 'managed',
description: 'A starting project with a list',
id: 'angular-official-list',
},
{
name: 'my-first-app',
projectType: 'angular',
type: 'repo',
description: 'A template for the "Build Your First App" tutorial',
repo: 'https://github.com/ionic-team/photo-gallery-capacitor-ng',
},
{
name: 'tabs',
projectType: ANGULAR_STANDALONE,
type: 'managed',
description: 'A starting project with a simple tabbed interface',
id: 'angular-standalone-official-tabs',
},
{
name: 'sidemenu',
projectType: ANGULAR_STANDALONE,
type: 'managed',
description: 'A starting project with a side menu with navigation in the content area',
id: 'angular-standalone-official-sidemenu',
},
{
name: 'blank',
projectType: ANGULAR_STANDALONE,
type: 'managed',
description: 'A blank starter project',
id: 'angular-standalone-official-blank',
},
{
name: 'list',
projectType: ANGULAR_STANDALONE,
type: 'managed',
description: 'A starting project with a list',
id: 'angular-standalone-official-list',
},
{
name: 'my-first-app',
projectType: ANGULAR_STANDALONE,
type: 'repo',
description: 'A template for the "Build Your First App" tutorial',
repo: 'https://github.com/ionic-team/photo-gallery-capacitor-ng',
},
// React
{
name: 'blank',
projectType: 'react',
type: 'managed',
description: 'A blank starter project',
id: 'react-vite-official-blank',
},
{
name: 'list',
projectType: 'react',
type: 'managed',
description: 'A starting project with a list',
id: 'react-vite-official-list',
},
{
name: 'my-first-app',
projectType: 'react',
type: 'repo',
description: 'A template for the "Build Your First App" tutorial',
repo: 'https://github.com/ionic-team/photo-gallery-capacitor-react',
},
{
name: 'sidemenu',
projectType: 'react',
type: 'managed',
description: 'A starting project with a side menu with navigation in the content area',
id: 'react-vite-official-sidemenu',
},
{
name: 'tabs',
projectType: 'react',
type: 'managed',
description: 'A starting project with a simple tabbed interface',
id: 'react-vite-official-tabs',
},
];