blob: aecfda246f7c985e5c525db43f15ceca961779fd [file] [log] [blame]
Max Chu3ca3e202017-09-14 10:33:09 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18'use strict';
19
20var Generator = require('yeoman-generator');
21var Path = require('path');
22
23var extensionName, extensionFolder;
24
25module.exports = Generator.extend({
26
27 prompting: {
28
29 init() {
30 this.log('---------------------------');
31 this.log('XOS GUI Extension Generator');
32 this.log('---------------------------');
33 },
34
35 name() {
36 var done = this.async();
37 this.log(`Your extension will be created in the current working directory, ${this.destinationRoot()}`);
38 this.prompt({
39 type: 'input',
40 name: 'name',
41 message: 'Enter the name of your XOS GUI Extension',
42 default: 'new-gui-extension',
43 filter: (str) => {
44 var newstr = str.replace(' ', '-');
45 return newstr;
46 }
47 }).then((answers) => {
48 extensionName = answers.name;
49 done();
50 });
51 },
52 },
53
54 writing: {
55
56 noTmplRoot() {
57 this.log('Creating non-templated files in the extension root...');
58 this.fs.copy(this.templatePath('.dockerignore'), this.destinationPath(`${extensionName}/.dockerignore`));
59 this.fs.copy(this.templatePath('.gitignore'), this.destinationPath(`${extensionName}/.gitignore`));
60 this.fs.copy(this.templatePath('Dockerfile'), this.destinationPath(`${extensionName}/Dockerfile`));
61 this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${extensionName}/gulpfile.js`));
62 this.fs.copy(this.templatePath('package.json'), this.destinationPath(`${extensionName}/package.json`));
63 this.fs.copy(this.templatePath('tsconfig.json'), this.destinationPath(`${extensionName}/tsconfig.json`));
64 this.fs.copy(this.templatePath('tslint.json'), this.destinationPath(`${extensionName}/tslint.json`));
65 this.fs.copy(this.templatePath('typings.json'), this.destinationPath(`${extensionName}/typings.json`));
66 },
67
68 tmplRoot() {
69 this.log('Creating templated files in the extension root...');
70 this.fs.copyTpl(
71 this.templatePath('README.md'),
72 this.destinationPath(`${extensionName}/README.md`),
73 {
74 name: extensionName
75 });
76 this.fs.copyTpl(
77 this.templatePath('xos-sample-gui-extension.yaml'),
78 this.destinationPath(`${extensionName}/${extensionName}.yml`),
79 {
80 name: extensionName
81 });
82 this.fs.copyTpl(
83 this.templatePath('Dockerfile'),
84 this.destinationPath(`${extensionName}/Dockerfile`),
85 {
86 name: extensionName
87 });
88 },
89
90 conf() {
91 this.log('Creating conf...');
92 this.fs.copyTpl(
93 this.templatePath('conf'),
94 this.destinationPath(`${extensionName}/conf`),
95 {
96 name: extensionName
97 });
98 },
99
100 gulp() {
101 this.log('Creating gulp_tasks...');
102 this.fs.copy(this.templatePath('gulp_tasks'), this.destinationPath(`${extensionName}/gulp_tasks`));
103 },
104
105 src() {
106 this.log('Creating src...');
107 this.fs.copyTpl(
108 this.templatePath('src'),
109 this.destinationPath(`${extensionName}/src`),
110 {
111 name: extensionName
112 });
113 }
114 },
115
116 install (){
117 var done = this.async();
118 this.prompt({
119 type: 'confirm',
120 name: 'deps',
121 message: 'Install dependencies?',
122 default: false
123 }).then((answers) => {
124 if(answers.deps){
125 process.chdir(`${extensionName}/`);
126 this.installDependencies({
127 npm: true,
128 bower: false,
129 yarn: false
130 });
131 }
132 done();
133 });
134 }
135
136});