UNPKG

3.26 kBPlain TextView Raw
1import {Arguments} from 'yargs';
2import * as ExtLB from '..'
3import * as Inquirer from 'inquirer'
4import {Answers} from "inquirer";
5import * as path from 'path';
6import * as _ from 'lodash';
7import * as Joi from 'joi';
8
9class App {
10 options: {
11 name: string;
12 camelName: string;
13 snakeName: string;
14 capitalName: string;
15 description: string;
16 version: string;
17 platforms: [string];
18 features: [string];
19 };
20 constructor() {
21 this.options = {
22 name: null,
23 camelName: null,
24 snakeName: null,
25 capitalName: null,
26 description: null,
27 version: null,
28 platforms: null,
29 features: null,
30 };
31 }
32 getName() {
33 let me = this;
34 let curDir = _.last(process.cwd().split(path.sep));
35 return Inquirer.prompt([{
36 type: 'input',
37 name: 'name',
38 message: 'Application Name',
39 default: me.options.name || curDir.toLowerCase(),
40 validate: (name: string) => {
41 if (_.isNull(Joi.validate(name, Joi.string().lowercase().required(), {convert: false}).error)) {
42 return true;
43 } else {
44 return 'Application Name must be lowercase';
45 }
46 }
47 }]).then((answers: Answers) => {
48 me.options.name = answers.name;
49 me.options.camelName = _.camelCase(answers.name);
50 me.options.snakeName = _.snakeCase(answers.name);
51 me.options.capitalName = me.options.camelName.charAt(0).toUpperCase() + me.options.camelName.substr(1);
52 });
53 }
54 getDescription() {
55 let me = this;
56 let curDir = _.last(process.cwd().split(path.sep));
57 return Inquirer.prompt([{
58 type: 'input',
59 name: 'description',
60 message: 'Application Description',
61 default: me.options.name || curDir.toLowerCase()
62 }]).then((answers: Answers) => {
63 me.options.description = answers.description;
64 });
65 }
66 getVersion() {
67 let me = this;
68 return Inquirer.prompt([{
69 type: 'rawlist',
70 name: 'version',
71 message: 'ExtLoop Version',
72 default: '1',
73 choices: ExtLB.default.default.versions,
74 }]).then((answers: Answers) => {
75 me.options.version = answers.version;
76 });
77 }
78 getPlatforms() {
79 let me = this;
80 return Inquirer.prompt([{
81 type: 'checkbox',
82 name: 'platforms',
83 message: 'Platform(s)',
84 choices: ExtLB.default.default.platforms,
85 }]).then((answers: Answers) => {
86 me.options.platforms = answers.platforms;
87 });
88 }
89 getFeatures() {
90 let me = this;
91 return Inquirer.prompt([{
92 type: 'checkbox',
93 name: 'features',
94 message: 'Enable Features',
95 pageSize: 20,
96 choices: ExtLB.default.default.features,
97 }]).then((answers: Answers) => {
98 me.options.features = answers.features;
99 });
100 }
101}
102
103exports.command = 'app';
104exports.describe = 'Create a new ExtLoop Application';
105exports.builder = {};
106exports.handler = (argv: Arguments) => {
107 const app = new App();
108 app.getName().then(() => {
109 return app.getDescription();
110 }).then(() => {
111 return app.getVersion();
112 }).then(() => {
113 return app.getPlatforms();
114 }).then(() => {
115 return app.getFeatures();
116 }).then(() => {
117 ExtLB.default.default.createApp(app.options);
118 }).catch((err) => {
119 console.error(err);
120 });
121};