mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
jaws new: add awsm.json, admin.env creation
This commit is contained in:
parent
f2335dc78e
commit
7c4e200d57
@ -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: '<enter your github repository here>',
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user