From 7c4e200d57e09b47738bfa8cdefd6aa46cd11a76 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sun, 16 Aug 2015 14:42:23 -0700 Subject: [PATCH] jaws new: add awsm.json, admin.env creation --- lib/command_new.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/command_new.js b/lib/command_new.js index 82e3f57f4..4f0093e91 100644 --- a/lib/command_new.js +++ b/lib/command_new.js @@ -10,8 +10,10 @@ // Defaults var Promise = require('bluebird'), fs = Promise.promisifyAll(require('fs')), +os = require('os'), inquirer = require('inquirer'), chalk = require('chalk'), +jsonfile = Promise.promisifyAll(require('jsonfile')), shortid = require('shortid'); @@ -50,19 +52,19 @@ module.exports = function(JAWS) { inquirer.prompt(prompts, function( answers ) { // Set and sanitize project info - project.name = answers.name.toLowerCase().trim().replace(/\s/g, '-').substring(0,19); + project.name = answers.name.toLowerCase().trim().replace(/[^a-zA-Z-\d\s:]/g, '').replace(/\s/g, '-').substring(0,19); project.awsAdminKeyId = answers.awsAdminKeyId.trim(); project.awsAdminSecretKey = answers.awsAdminSecretKey.trim(); return resolve(); }); - }); + // Process userPrompts.then(function(){ // Set project root path. Append unique id if directory already exists. - if (fs.existsSync(JAWS._meta.cwd + '/' + project.name.replace(/\s/g, '-'))) { + if (fs.existsSync(JAWS._meta.cwd + '/' + project.name)) { project.name = project.name + '-' + shortid.generate(); JAWS._meta.projectRootPath = './' + project.name; } else { @@ -87,6 +89,27 @@ module.exports = function(JAWS) { // Create project/front return fs.mkdirAsync(JAWS._meta.projectRootPath + '/tests'); + }).then(function(){ + + // Create awsm.json + var awsmJson = { + name: project.name, + version: JAWS._meta.version, + type: 'aws_v1', + profile: 'project', + location: '', + cfTemplate: {} + }; + + jsonfile.spaces = 2; + return jsonfile.writeFile(JAWS._meta.projectRootPath + '/awsm.json', awsmJson); + + }).then(function(){ + + // Create admin.env + var adminEnv = 'ADMIN_AWS_ACCESS_KEY_ID=' + project.awsAdminKeyId + os.EOL + 'ADMIN_AWS_SECRET_ACCESS_KEY=' + project.awsAdminSecretKey; + return fs.writeFile(JAWS._meta.projectRootPath + '/admin.env', adminEnv); + }).catch(function(e) { console.error(e);