Commit c5ba9d52 authored by Bertrand PINEL's avatar Bertrand PINEL

Add new default blueprint for detecting proxy flag

parent 6bb5bf07
ember-aws-ehipster
==============================================================================
[Short description of the addon.]
This addon simplify the generation of code for model build with JDL Studio https://start.jhipster.tech/jdl-studio/
It also guide you to set up a JSON-API server on top of AWS API Gateway, Lambda and DynamoDB.
Installation
------------------------------------------------------------------------------
......@@ -14,8 +16,14 @@ ember install ember-aws-ehipster
Usage
------------------------------------------------------------------------------
[Longer description of how to use the addon in apps.]
For generating a application, first use the standard command :
ember new test-ember-aws-ehipster --no-welcome
cd test-ember-aws-ehipster
ember install ember-aws-ehipster
Then generate a few entity through provided blueprints using the same syntax as the model blueprint :
ember g entity-factory blog title:string content:string order:number isVisible:boolean
ember g entity-factory post title:string content:string order:number visible:boolean
Contributing
------------------------------------------------------------------------------
......
const EOL = require('os').EOL;
const path = require('path');
const fs = require('fs');
/* eslint-env node */
module.exports = {
description: '',
normalizeEntityName() {}, // no argument
// locals(options) {
// // Return custom template variables here.
// return {
// foo: options.entity.options.foo
// };
// }
afterInstall(options) {
// Perform extra work here.
// Add proxy check to config/environment.js
let configPath = (options.dummy) ? "tests/dummy/config/environment.js" : "config/environment.js";
let proxy = "\nfunction usingProxy() {\n"+
"\tvar usingProxyArg = !!process.argv.filter(function (arg) {\n"+
"\t\treturn arg.indexOf('--proxy') === 0 || arg.indexOf('-pr') === 0 || arg.indexOf('-pxy') === 0;\n"+
"\t}).length;\n\n"+
"\tvar hasGeneratedProxies = false;\n"+
"\tvar proxiesDir = process.env.PWD + '/server/proxies';\n"+
"\ttry {\n"+
"\t\tfs.lstatSync(proxiesDir);\n"+
"\t\thasGeneratedProxies = true;\n"+
"\t} catch (e) {}\n\n"+
"\treturn usingProxyArg || hasGeneratedProxies;\n}\n";
addLineToFile(this, configPath, /'use strict';/, proxy);
addLineToFile(this, configPath, /when it is created/, "\t\tproxy: usingProxy(),");
}
};
function addLineToFile(ctx, filePath, markerString, addedLine) {
let fileContents = fs.readFileSync(filePath, 'utf-8');
if (fileContents.indexOf(addedLine) === -1) {
ctx.ui.writeLine("\tAdd line "+addedLine+" to file "+filePath);
fileContents = fileContents.replace(markerString, [
'$&',
addedLine,
].join('\n'));
}
if (fileContents.indexOf(addedLine) === -1) {
ctx.ui.writeWarnLine(
'Unable to update '+filePath+'. You should update this file manually.');
} else {
fs.writeFileSync(filePath, fileContents, 'utf-8');
}
}
......@@ -161,7 +161,8 @@ module.exports = {
// Complete /mirage/config.js
let mirageConfigPath = (options.dummy) ? "tests/dummy/mirage/config.js" : "mirage/config.js";
let configLine = "\t\tthis.get('/"+inflection.pluralize(entityName)+"', '"+inflection.pluralize(entityName)+"');"
let configLine = "\t\tthis.get('/"+inflection.pluralize(entityName)+"', '"+inflection.pluralize(entityName)+"');\n"+
"\t\tthis.post('/"+inflection.pluralize(entityName)+"');";
if (!fs.existsSync(mirageConfigPath)) {
this.ui.writeLine("Creating file "+mirageConfigPath);
let configContent = "import ENV from './../config/environment';\n"+
......@@ -171,8 +172,7 @@ module.exports = {
"\t\tthis.passthrough();\n\t}\n}\n";
fs.writeFileSync(mirageConfigPath, configContent, 'utf-8','w+');
} else {
//addLineToFile(this, mirageConfigPath, /this\.namespace = \'\';/, configLine);
addLineToFile(this, mirageConfigPath, /if \(ENV\.APP\.proxy\) {/, configLine);
addLineToFile(this, mirageConfigPath, /if \(!ENV\.APP\.proxy\) {/, configLine);
}
// Add route in router.js for the entity page
......
{
"name": "ember-aws-ehipster",
"version": "0.0.6",
"version": "0.1.1",
"description": "The default blueprint for ember-cli addons.",
"keywords": [
"ember-addon"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment