UNPKG

12.4 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.STARTER_TEMPLATES = exports.SUPPORTED_FRAMEWORKS = exports.getStarterProjectTypes = exports.getStarterList = exports.getAdvertisement = exports.readStarterManifest = exports.verifyOptions = exports.STARTER_BASE_URL = void 0;
4const utils_fs_1 = require("@ionic/utils-fs");
5const utils_terminal_1 = require("@ionic/utils-terminal");
6const lodash = require("lodash");
7const constants_1 = require("../constants");
8const guards_1 = require("../guards");
9const color_1 = require("./color");
10const errors_1 = require("./errors");
11const project_1 = require("./project");
12const emoji_1 = require("./utils/emoji");
13const http_1 = require("./utils/http");
14exports.STARTER_BASE_URL = 'https://d2ql0qc7j8u4b2.cloudfront.net';
15function verifyOptions(options, { log }) {
16 // If the action is list then lets just end here.
17 if (options['list']) {
18 const typeOption = options['type'] ? String(options['type']) : undefined;
19 if (typeOption && !constants_1.PROJECT_TYPES.includes(typeOption)) {
20 throw new errors_1.FatalException(`${color_1.input(typeOption)} is not a valid project type.\n` +
21 `Valid project types are: ${getStarterProjectTypes().map(type => color_1.input(type)).join(', ')}`);
22 }
23 const headers = ['name', 'description'].map(h => color_1.strong(h));
24 const starterTypes = typeOption ? [typeOption] : getStarterProjectTypes();
25 for (const starterType of starterTypes) {
26 const starters = exports.STARTER_TEMPLATES.filter(template => template.projectType === starterType);
27 log.rawmsg(`\n${color_1.strong(`Starters for ${project_1.prettyProjectName(starterType)}`)} (${color_1.input(`--type=${starterType}`)})\n\n`);
28 log.rawmsg(utils_terminal_1.columnar(starters.map(({ name, description }) => [color_1.input(name), description || '']), { ...constants_1.COLUMNAR_OPTIONS, headers }));
29 log.rawmsg('\n');
30 }
31 throw new errors_1.FatalException('', 0);
32 }
33 if (options['skip-deps']) {
34 log.warn(`The ${color_1.input('--skip-deps')} option has been deprecated. Please use ${color_1.input('--no-deps')}.`);
35 options['deps'] = false;
36 }
37 if (options['skip-link']) {
38 log.warn(`The ${color_1.input('--skip-link')} option has been deprecated. Please use ${color_1.input('--no-link')}.`);
39 options['link'] = false;
40 }
41 if (options['pro-id']) {
42 log.warn(`The ${color_1.input('--pro-id')} option has been deprecated. Please use ${color_1.input('--id')}.`);
43 options['id'] = options['pro-id'];
44 }
45 if (options['id']) {
46 if (options['link'] === false) {
47 log.warn(`The ${color_1.input('--no-link')} option has no effect with ${color_1.input('--id')}. App must be linked.`);
48 }
49 options['link'] = true;
50 if (!options['git']) {
51 log.warn(`The ${color_1.input('--no-git')} option has no effect with ${color_1.input('--id')}. Git must be used.`);
52 }
53 options['git'] = true;
54 }
55}
56exports.verifyOptions = verifyOptions;
57async function readStarterManifest(p) {
58 try {
59 const manifest = await utils_fs_1.readJson(p);
60 if (!guards_1.isStarterManifest(manifest)) {
61 throw new Error(`${p} is not a valid starter manifest.`);
62 }
63 return manifest;
64 }
65 catch (e) {
66 if (e.code === 'ENOENT') {
67 throw new Error(`${p} not found`);
68 }
69 else if (e instanceof SyntaxError) {
70 throw new Error(`${p} is not valid JSON.`);
71 }
72 throw e;
73 }
74}
75exports.readStarterManifest = readStarterManifest;
76function getAdvertisement() {
77 const choices = [getAppflowAdvertisement, getAdvisoryAdvertisement, getEnterpriseAdvertisement];
78 const idx = Math.floor(Math.random() * choices.length);
79 return `${choices[idx]()}\n\n`;
80}
81exports.getAdvertisement = getAdvertisement;
82function getAppflowAdvertisement() {
83 return `
84 ──────────────────────────────────────────────────────────────
85
86 ${color_1.title('Ionic Appflow')}, the mobile DevOps solution by Ionic
87
88 Continuously build, deploy, and ship apps ${emoji_1.emoji('🚀', '')}
89 Focus on building apps while we automate the rest ${emoji_1.emoji('🎁', '')}
90
91 ${emoji_1.emoji(' 👉 ', 'Learn more:')} ${color_1.strong('https://ion.link/appflow')} ${emoji_1.emoji(' 👈', '')}
92
93 ──────────────────────────────────────────────────────────────
94`;
95}
96function getAdvisoryAdvertisement() {
97 return `
98 ──────────────────────────────────────────────────────────────────────────────
99
100 ${color_1.title('Ionic Advisory')}, tailored solutions and expert services by Ionic
101
102 Go to market faster ${emoji_1.emoji('🏆', '')}
103 Real-time troubleshooting and guidance ${emoji_1.emoji('💁', '')}
104 Custom training, best practices, code and architecture reviews ${emoji_1.emoji('🔎', '')}
105 Customized strategies for every phase of the development lifecycle ${emoji_1.emoji('🔮', '')}
106
107 ${emoji_1.emoji(' 👉 ', 'Learn more:')} ${color_1.strong('https://ion.link/advisory')} ${emoji_1.emoji(' 👈', '')}
108
109 ──────────────────────────────────────────────────────────────────────────────
110`;
111}
112function getEnterpriseAdvertisement() {
113 return `
114 ──────────────────────────────────────────────────────────────────────
115
116 ${color_1.title('Ionic Enterprise')}, platform and solutions for teams by Ionic
117
118 Powerful library of native APIs ${emoji_1.emoji('⚡️', '')}
119 A supercharged platform for teams ${emoji_1.emoji('💪', '')}
120
121 ${emoji_1.emoji(' 👉 ', 'Learn more:')} ${color_1.strong('https://ion.link/enterprise')} ${emoji_1.emoji(' 👈', '')}
122
123 ──────────────────────────────────────────────────────────────────────
124`;
125}
126async function getStarterList(config, tag = 'latest') {
127 const { req } = await http_1.createRequest('GET', `${exports.STARTER_BASE_URL}/${tag === 'latest' ? '' : `${tag}/`}starters.json`, config.getHTTPConfig());
128 const res = await req;
129 // TODO: typecheck
130 return res.body;
131}
132exports.getStarterList = getStarterList;
133function getStarterProjectTypes() {
134 return lodash.uniq(exports.STARTER_TEMPLATES.map(t => t.projectType));
135}
136exports.getStarterProjectTypes = getStarterProjectTypes;
137exports.SUPPORTED_FRAMEWORKS = [
138 {
139 name: 'Angular',
140 type: 'angular',
141 description: 'https://angular.io',
142 },
143 {
144 name: 'React',
145 type: 'react',
146 description: 'https://reactjs.org',
147 },
148];
149exports.STARTER_TEMPLATES = [
150 {
151 name: 'tabs',
152 projectType: 'angular',
153 type: 'managed',
154 description: 'A starting project with a simple tabbed interface',
155 id: 'angular-official-tabs',
156 },
157 {
158 name: 'sidemenu',
159 projectType: 'angular',
160 type: 'managed',
161 description: 'A starting project with a side menu with navigation in the content area',
162 id: 'angular-official-sidemenu',
163 },
164 {
165 name: 'blank',
166 projectType: 'angular',
167 type: 'managed',
168 description: 'A blank starter project',
169 id: 'angular-official-blank',
170 },
171 {
172 name: 'list',
173 projectType: 'angular',
174 type: 'managed',
175 description: 'A starting project with a list',
176 id: 'angular-official-list',
177 },
178 {
179 name: 'my-first-app',
180 projectType: 'angular',
181 type: 'repo',
182 description: 'An example application that builds a camera with gallery',
183 repo: 'https://github.com/ionic-team/photo-gallery-capacitor-ng',
184 },
185 {
186 name: 'conference',
187 projectType: 'angular',
188 type: 'repo',
189 description: 'A kitchen-sink application that shows off all Ionic has to offer',
190 repo: 'https://github.com/ionic-team/ionic-conference-app',
191 },
192 {
193 name: 'blank',
194 projectType: 'react',
195 type: 'managed',
196 description: 'A blank starter project',
197 id: 'react-official-blank',
198 },
199 {
200 name: 'list',
201 projectType: 'react',
202 type: 'managed',
203 description: 'A starting project with a list',
204 id: 'react-official-list',
205 },
206 {
207 name: 'my-first-app',
208 projectType: 'react',
209 type: 'repo',
210 description: 'An example application that builds a camera with gallery',
211 repo: 'https://github.com/ionic-team/photo-gallery-capacitor-react',
212 },
213 {
214 name: 'sidemenu',
215 projectType: 'react',
216 type: 'managed',
217 description: 'A starting project with a side menu with navigation in the content area',
218 id: 'react-official-sidemenu',
219 },
220 {
221 name: 'tabs',
222 projectType: 'react',
223 type: 'managed',
224 description: 'A starting project with a simple tabbed interface',
225 id: 'react-official-tabs',
226 },
227 {
228 name: 'conference',
229 projectType: 'react',
230 type: 'repo',
231 description: 'A kitchen-sink application that shows off all Ionic has to offer',
232 repo: 'https://github.com/ionic-team/ionic-react-conference-app',
233 },
234 {
235 name: 'tabs',
236 projectType: 'ionic-angular',
237 type: 'managed',
238 description: 'A starting project with a simple tabbed interface',
239 id: 'ionic-angular-official-tabs',
240 },
241 {
242 name: 'sidemenu',
243 projectType: 'ionic-angular',
244 type: 'managed',
245 description: 'A starting project with a side menu with navigation in the content area',
246 id: 'ionic-angular-official-sidemenu',
247 },
248 {
249 name: 'blank',
250 projectType: 'ionic-angular',
251 type: 'managed',
252 description: 'A blank starter project',
253 id: 'ionic-angular-official-blank',
254 },
255 {
256 name: 'super',
257 projectType: 'ionic-angular',
258 type: 'managed',
259 description: 'A starting project complete with pre-built pages, providers and best practices for Ionic development.',
260 id: 'ionic-angular-official-super',
261 },
262 {
263 name: 'tutorial',
264 projectType: 'ionic-angular',
265 type: 'managed',
266 description: 'A tutorial based project that goes along with the Ionic documentation',
267 id: 'ionic-angular-official-tutorial',
268 },
269 {
270 name: 'aws',
271 projectType: 'ionic-angular',
272 type: 'managed',
273 description: 'AWS Mobile Hub Starter',
274 id: 'ionic-angular-official-aws',
275 },
276 {
277 name: 'tabs',
278 projectType: 'ionic1',
279 type: 'managed',
280 description: 'A starting project for Ionic using a simple tabbed interface',
281 id: 'ionic1-official-tabs',
282 },
283 {
284 name: 'sidemenu',
285 projectType: 'ionic1',
286 type: 'managed',
287 description: 'A starting project for Ionic using a side menu with navigation in the content area',
288 id: 'ionic1-official-sidemenu',
289 },
290 {
291 name: 'blank',
292 projectType: 'ionic1',
293 type: 'managed',
294 description: 'A blank starter project for Ionic',
295 id: 'ionic1-official-blank',
296 },
297 {
298 name: 'maps',
299 projectType: 'ionic1',
300 type: 'managed',
301 description: 'An Ionic starter project using Google Maps and a side menu',
302 id: 'ionic1-official-maps',
303 },
304];