123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const tslib_1 = require("tslib");
- const path = require("path");
- const chalk_1 = require("chalk");
- const guards_1 = require("../guards");
- const http_1 = require("./http");
- const fs_1 = require("@ionic/cli-framework/utils/fs");
- exports.STARTER_BASE_URL = 'https://d2ql0qc7j8u4b2.cloudfront.net';
- function isProjectNameValid(name) {
- return name !== '.';
- }
- exports.isProjectNameValid = isProjectNameValid;
- /**
- * If project only contains files generated by GH, it’s safe.
- * We also special case IJ-based products .idea because it integrates with CRA:
- * https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
- */
- function isSafeToCreateProjectIn(root) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const validFiles = [
- '.DS_Store', 'Thumbs.db', '.git', '.gitignore', '.idea', 'README.md', 'LICENSE'
- ];
- const entries = yield fs_1.fsReadDir(root);
- return entries.every(file => {
- return validFiles.indexOf(file) >= 0;
- });
- });
- }
- exports.isSafeToCreateProjectIn = isSafeToCreateProjectIn;
- function getStarterTemplateText(templateList) {
- let headerLine = chalk_1.default.bold(`Ionic Starter templates`);
- let formattedTemplateList = getStarterTemplateTextList(templateList);
- return `
- ${headerLine}
- ${formattedTemplateList.join(`
- `)}
- `;
- }
- exports.getStarterTemplateText = getStarterTemplateText;
- function getStarterTemplateTextList(templateList) {
- return templateList.map(({ name, type, description }) => {
- let templateName = chalk_1.default.green(name);
- return `${templateName} ${Array(20 - name.length).join(chalk_1.default.dim('.'))} ${chalk_1.default.bold(type)} ${description}`;
- });
- }
- exports.getStarterTemplateTextList = getStarterTemplateTextList;
- function getHelloText() {
- return `
- ${chalk_1.default.bold('♬ ♫ ♬ ♫ Your Ionic app is ready to go! ♬ ♫ ♬ ♫')}
-
- ${chalk_1.default.bold('Run your app in the browser (great for initial development):')}
- ${chalk_1.default.green('ionic serve')}
-
- ${chalk_1.default.bold('Install the DevApp to easily test on iOS and Android')}
- ${chalk_1.default.green('https://bit.ly/ionic-dev-app')}
-
- ${chalk_1.default.bold('Run on a device or simulator:')}
- ${chalk_1.default.green('ionic cordova run ios')}
-
- ${chalk_1.default.bold('Test and share your app on a device with the Ionic View app:')}
- https://ionicframework.com/products/view
- `;
- }
- exports.getHelloText = getHelloText;
- function readStarterManifest(p) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- try {
- const manifest = yield fs_1.fsReadJsonFile(p);
- if (!guards_1.isStarterManifest(manifest)) {
- throw new Error(`${p} is not a valid starter manifest.`);
- }
- return manifest;
- }
- catch (e) {
- if (e === fs_1.ERROR_FILE_NOT_FOUND) {
- throw new Error(`${p} not found`);
- }
- else if (e === fs_1.ERROR_FILE_INVALID_JSON) {
- throw new Error(`${p} is not valid JSON.`);
- }
- throw e;
- }
- });
- }
- exports.readStarterManifest = readStarterManifest;
- function updatePackageJsonForCli(projectRoot, appName) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const filePath = path.resolve(projectRoot, 'package.json');
- try {
- const jsonStructure = yield fs_1.fsReadJsonFile(filePath);
- jsonStructure['name'] = appName;
- jsonStructure['version'] = '0.0.1';
- jsonStructure['description'] = 'An Ionic project';
- yield fs_1.fsWriteJsonFile(filePath, jsonStructure, { encoding: 'utf8' });
- }
- catch (e) {
- if (e === fs_1.ERROR_FILE_NOT_FOUND) {
- throw new Error(`${filePath} not found`);
- }
- else if (e === fs_1.ERROR_FILE_INVALID_JSON) {
- throw new Error(`${filePath} is not valid JSON.`);
- }
- throw e;
- }
- });
- }
- exports.updatePackageJsonForCli = updatePackageJsonForCli;
- function getStarterList(config) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { req } = yield http_1.createRequest(config, 'get', `${exports.STARTER_BASE_URL}/starters.json`);
- const res = yield req;
- // TODO: typecheck
- return res.body;
- });
- }
- exports.getStarterList = getStarterList;
- exports.STARTER_TEMPLATES = [
- {
- name: 'tabs',
- type: 'ionic-angular',
- description: 'A starting project with a simple tabbed interface',
- archive: `${exports.STARTER_BASE_URL}/ionic-angular-official-tabs.tar.gz`,
- },
- {
- name: 'blank',
- type: 'ionic-angular',
- description: 'A blank starter project',
- archive: `${exports.STARTER_BASE_URL}/ionic-angular-official-blank.tar.gz`,
- },
- {
- name: 'sidemenu',
- type: 'ionic-angular',
- description: 'A starting project with a side menu with navigation in the content area',
- archive: `${exports.STARTER_BASE_URL}/ionic-angular-official-sidemenu.tar.gz`,
- },
- {
- name: 'super',
- type: 'ionic-angular',
- description: 'A starting project complete with pre-built pages, providers and best practices for Ionic development.',
- archive: `${exports.STARTER_BASE_URL}/ionic-angular-official-super.tar.gz`,
- },
- {
- name: 'conference',
- type: 'ionic-angular',
- description: 'A project that demonstrates a realworld application',
- archive: `https://github.com/ionic-team/ionic-conference-app/archive/master.tar.gz`,
- strip: true,
- },
- {
- name: 'tutorial',
- type: 'ionic-angular',
- description: 'A tutorial based project that goes along with the Ionic documentation',
- archive: `${exports.STARTER_BASE_URL}/ionic-angular-official-tutorial.tar.gz`,
- },
- {
- name: 'aws',
- type: 'ionic-angular',
- description: 'AWS Mobile Hub Starter',
- archive: `${exports.STARTER_BASE_URL}/ionic-angular-official-aws.tar.gz`,
- },
- {
- name: 'tabs',
- type: 'ionic1',
- description: 'A starting project for Ionic using a simple tabbed interface',
- archive: `${exports.STARTER_BASE_URL}/ionic1-official-tabs.tar.gz`,
- },
- {
- name: 'blank',
- type: 'ionic1',
- description: 'A blank starter project for Ionic',
- archive: `${exports.STARTER_BASE_URL}/ionic1-official-blank.tar.gz`,
- },
- {
- name: 'sidemenu',
- type: 'ionic1',
- description: 'A starting project for Ionic using a side menu with navigation in the content area',
- archive: `${exports.STARTER_BASE_URL}/ionic1-official-sidemenu.tar.gz`,
- },
- {
- name: 'maps',
- type: 'ionic1',
- description: 'An Ionic starter project using Google Maps and a side menu',
- archive: `${exports.STARTER_BASE_URL}/ionic1-official-maps.tar.gz`,
- },
- ];
|