Updated generator to read parent env config
diff --git a/views/ngXosLib/generator-xos/app/index.js b/views/ngXosLib/generator-xos/app/index.js
index 57eee8c..43b82e4 100755
--- a/views/ngXosLib/generator-xos/app/index.js
+++ b/views/ngXosLib/generator-xos/app/index.js
@@ -11,57 +11,24 @@
return string.replace(/^./, string[0].toUpperCase());
},
prompting: {
- name:function(){
+ name: function(){
var done = this.async();
this.prompt({
- type : 'input',
- name : 'name',
- message : 'Your project name',
- default : this.config.get('name') // value set in .yo-rc.json
+ type: 'input',
+ name: 'name',
+ message: 'Your project name',
+ default: this.config.get('name') // value set in .yo-rc.json
}, function (answers) {
// TODO check if this view already exist
config.name = answers.name;
done();
}.bind(this));
- },
- host:function(){
- var done = this.async();
- this.prompt({
- type : 'input',
- name : 'host',
- message : 'Your project remote host (with port)'
- }, function (answers) {
- config.host = answers.host;
- done();
- }.bind(this));
- },
- token:function(){
- var done = this.async();
- this.prompt({
- type : 'input',
- name : 'token',
- message : 'Insert your active session token'
- }, function (answers) {
- config.token = answers.token;
- done();
- }.bind(this));
- },
- session:function(){
- var done = this.async();
- this.prompt({
- type : 'input',
- name : 'session',
- message : 'Insert your active session id'
- }, function (answers) {
- config.session = answers.session;
- done();
- }.bind(this));
}
},
writing: {
rcFiles: function(){
if (!user.git.name()){
- userName = ['','']
+ userName = ['', '']
}
else {
userName = user.git.name().split(' ');
@@ -73,21 +40,21 @@
this.fs.copyTpl(
this.templatePath('package.json'),
this.destinationPath(`${this.config.get('folder')}/${config.name}/package.json`),
- { name: config.name, author: {name:user.git.name()} }
+ { name: config.name, author: {name: user.git.name()} }
);
},
- envConfig: function(){
- this.fs.copyTpl(
- this.templatePath('env/default.js'),
- this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`),
- { host: config.host, token: config.token, session: config.session }
- );
- },
+ // envConfig: function(){
+ // this.fs.copyTpl(
+ // this.templatePath('env/default.js'),
+ // this.destinationPath(`${this.config.get('folder')}/${config.name}/env/default.js`),
+ // { host: config.host, token: config.token, session: config.session }
+ // );
+ // },
bowerJson: function(){
this.fs.copyTpl(
this.templatePath('bower.json'),
this.destinationPath(`${this.config.get('folder')}/${config.name}/bower.json`),
- { name: config.name, author: {name:user.git.name(), email: user.git.email()} }
+ { name: config.name, author: {name: user.git.name(), email: user.git.email()} }
);
},
index: function(){
@@ -125,7 +92,7 @@
this.fs.copyTpl(
this.templatePath('gulp/*.js'),
this.destinationPath(`${this.config.get('folder')}/${config.name}/gulp`),
- {name:config.name, fileName: this._fistCharToUpper(config.name)}
+ {name: config.name, fileName: this._fistCharToUpper(config.name)}
);
this.fs.copy(this.templatePath('gulpfile.js'), this.destinationPath(`${this.config.get('folder')}/${config.name}/gulpfile.js`));
},
@@ -152,10 +119,10 @@
install: function(){
var done = this.async();
this.prompt({
- type : 'confirm',
- name : 'deps',
- message : 'Install dependecies?',
- default : false // value set in .yo-rc.json
+ type: 'confirm',
+ name: 'deps',
+ message: 'Install dependecies?',
+ default: false // value set in .yo-rc.json
}, function (answers) {
if(answers.deps){
process.chdir(`${this.config.get('folder')}/${config.name}`);
diff --git a/views/ngXosLib/generator-xos/app/templates/env/default.js b/views/ngXosLib/generator-xos/app/templates/env/default.js
deleted file mode 100644
index 5db8632..0000000
--- a/views/ngXosLib/generator-xos/app/templates/env/default.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// This is a default configuration for your development environment.
-// You can duplicate this configuration for any of your Backend Environments.
-// Different configurations are loaded setting a NODE_ENV variable that contain the config file name.
-// `NODE_ENV=local npm start`
-//
-// If xoscsrftoken or xossessionid are not specified the browser value are used
-// (works only for local environment as both application are served on the same domain)
-
-module.exports = {
- host: '<%= host %>',
- xoscsrftoken: '<%= token %>',
- xossessionid: '<%= session %>'
-};
diff --git a/views/ngXosLib/generator-xos/app/templates/gulp/server.js b/views/ngXosLib/generator-xos/app/templates/gulp/server.js
index c0678d9..1e40a34 100644
--- a/views/ngXosLib/generator-xos/app/templates/gulp/server.js
+++ b/views/ngXosLib/generator-xos/app/templates/gulp/server.js
@@ -10,18 +10,24 @@
var httpProxy = require('http-proxy');
var del = require('del');
var sass = require('gulp-sass');
+var fs = require('fs');
+var path = require('path');
const environment = process.env.NODE_ENV;
-if (environment){
- var conf = require(`../env/${environment}.js`);
-}
-else{
- var conf = require('../env/default.js')
+if(!fs.existsSync(path.join(__dirname, `../../../env/${environment || 'default'}.js`))){
+ if(!environment){
+ throw new Error('You should define a default.js config in /views/env folder.');
+ }
+ else{
+ throw new Error(`Since you are loading a custom environment, you should define a ${environment}.js config in /views/env folder.`);
+ }
}
+var conf = require(path.join(__dirname, `../../../env/${environment || 'default'}.js`));
+
var proxy = httpProxy.createProxyServer({
- target: conf.host || 'http://0.0.0.0:9999'
+ target: conf.host
});
@@ -51,10 +57,6 @@
},
middleware: function(req, res, next){
if(
- // to be removed, deprecated API
- // req.url.indexOf('/xos/') !== -1 ||
- // req.url.indexOf('/xoslib/') !== -1 ||
- // req.url.indexOf('/hpcapi/') !== -1 ||
req.url.indexOf('/api/') !== -1
){
if(conf.xoscsrftoken && conf.xossessionid){
diff --git a/views/ngXosLib/generator-xos/test/build.spec.js b/views/ngXosLib/generator-xos/test/build.spec.js
index dd49b03..19c338b 100644
--- a/views/ngXosLib/generator-xos/test/build.spec.js
+++ b/views/ngXosLib/generator-xos/test/build.spec.js
@@ -14,6 +14,9 @@
}
}
+// config files
+const cfg = path.join(__dirname, `../../../env/default.js`);
+
// source files
const viewName = 'testDashboard';
const fileName = viewName.replace(/^./, viewName[0].toUpperCase());
@@ -32,6 +35,12 @@
this.timeout(getMillisec(5));
before(done => {
+ // if `default.js` config is not present
+ // create one (we check to avoid screwing up local envs)
+ if(!fs.existsSync(cfg)){
+ fs.writeFileSync(cfg, 'module.exports = {}');
+ }
+
console.log('Running generator');
this.generator = helpers
.run(require.resolve('../app'))
diff --git a/views/ngXosLib/generator-xos/test/generator.spec.js b/views/ngXosLib/generator-xos/test/generator.spec.js
index 4ae1602..2c7abb5 100644
--- a/views/ngXosLib/generator-xos/test/generator.spec.js
+++ b/views/ngXosLib/generator-xos/test/generator.spec.js
@@ -65,10 +65,7 @@
.inDir(testPath)
.withOptions({ 'skip-install': true })
.withPrompts({
- name: viewName,
- host: 'test-host',
- token: 'test-token',
- session: 'test-session'
+ name: viewName
})
.on('end', done);
});
@@ -78,12 +75,6 @@
assert.file(getDefaultFiles());
});
- it('should create the env file with correct params', () => {
- assert.fileContent(`${testPath}env/default.js`, 'host: \'test-host\'');
- assert.fileContent(`${testPath}env/default.js`, 'xoscsrftoken: \'test-token\'');
- assert.fileContent(`${testPath}env/default.js`, 'xossessionid: \'test-session\'');
- });
-
it('should write username in package & bower json', () => {
assert.fileContent(`${testPath}package.json`, '"author": "Test User"');
assert.fileContent(`${testPath}bower.json`, '"Test User <test@mail.org>"')