forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
120 lines (109 loc) · 3.32 KB
/
start.js
File metadata and controls
120 lines (109 loc) · 3.32 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
require('shelljs/global');
var chalk = require('chalk');
var extend = require('../utils/extend');
var fs = require('fs');
var Q = require('q');
var templateUtils = require('../utils/templates');
var IonicAppLib = require('ionic-app-lib');
var Start = IonicAppLib.start;
var log = IonicAppLib.logging.logger;
var appLibUtils = IonicAppLib.utils;
var StartWizard = IonicAppLib.start_wizard;
var settings = {
title: 'start',
name: 'start',
summary: 'Starts a new Ionic project in the specified PATH',
args: {
'[options]': 'any flags for the command',
'<PATH>': 'directory for the new project',
'[template]': 'Starter templates can either come from a named template, \n' +
'(ex: tabs, sidemenu, blank),\n' +
'a Github repo, a Codepen url, or a local directory.\n' +
'Codepen url, ex: http://codepen.io/ionic/pen/odqCz\n' +
'Defaults to Ionic "tabs" starter template'
},
options: {
'--appname|-a': 'Human readable name for the app (Use quotes around the name)',
'--id|-i': 'Package name for <widget id> config, ex: com.mycompany.myapp',
'--skip-npm': {
title: 'Skip npm package installation',
boolean: true
},
'--no-cordova|-w': {
title: 'Create a basic structure without Cordova requirements',
boolean: true
},
'--sass|-s': {
title: 'Setup the project to use Sass CSS precompiling',
boolean: true
},
'--list|-l': {
title: 'List starter templates available',
boolean: true
},
'--io-app-id': 'The Ionic.io app ID to use',
'--template|-t': 'Project starter template',
'--v2|-v': {
boolean: true,
title: 'Start a Ionic v2 project'
},
'--zip-file|-z': 'URL to download zipfile for starter template'
},
isProjectTask: false
};
function run(ionic, argv) {
if (argv.list || argv.l) {
return templateUtils.listTemplates();
}
if (argv._.length < 2 && StartWizard) {
return StartWizard.start();
} else if(argv._length < 2) {
return appLibUtils.fail('Invalid command', 'start');
}
if (argv._[1] === '.') {
return log.error(chalk.red('Please name your Ionic project something meaningful other than \'.\''));
}
// Ensure that the folder name provided is a String
// ie 5 becomes '5' AND '5' stays as '5'
argv._[1] = argv._[1].toString();
var promptPromise;
var options = appLibUtils.preprocessCliOptions(argv);
var startingApp = true;
// Grab the app's relative directory name
if (fs.existsSync(options.targetPath)) {
promptPromise = Start.promptForOverwrite(options.targetPath);
} else {
promptPromise = Q(true);
}
return promptPromise
.then(function(promptToContinue) {
if (!promptToContinue) {
startingApp = false;
log.info('\nIonic start cancelled by user.');
return;
}
return Start.startApp(options);
})
.then(function() {
if (startingApp) {
return Start.printQuickHelp(options);
}
})
.then(function() {
if (startingApp) {
return Start.promptLogin(options);
}
})
.then(function() {
if (options.v2 && startingApp) {
//log.info('\nNew to Ionic? Get started here: http://ionicframework.com/getting-started\n');
}
})
.catch(function(error) {
log.error(error);
throw error;
});
}
module.exports = extend(settings, {
run: run
});