Skip to content

Commit

Permalink
Added deploy hooks from framework
Browse files Browse the repository at this point in the history
  • Loading branch information
wgester committed Jun 22, 2015
1 parent c5a1003 commit 926e9f3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
13 changes: 10 additions & 3 deletions lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var checkWidget = function checkWidget(callback) {
storage.getProjectMeta(function(error, config) {
if (!config || !config.widget_id) {
link(null, function(err, results) {
results.scripts = config.scripts;
return callback(err, results);
});
} else {
Expand All @@ -72,10 +73,10 @@ var deployProject = function(directory, done) {
var directoryPath = path.join(process.cwd(), directory);

async.waterfall([
waterfallVariadic(checkDirectory, directoryPath),
waterfallChain(checkSession),
waterfallChain(checkWidget),
waterfallPipe(preDeployHook),
waterfallVariadic(checkDirectory, directoryPath),
updateProject
],
function (error, results) {
Expand Down Expand Up @@ -121,9 +122,15 @@ var deployProject = function(directory, done) {

var deployCLI = function(directory) {
if (!directory) {
directory = 'public';
storage.getProjectMeta(function(error, config) {
if (config && config.scripts && config.scripts['deploy-folder']) {
directory = config.scripts['deploy-folder'];
} else {
directory = 'public';
}
deployProject(directory, function(){});
});
}
deployProject(directory, function(){});
};

/** **/
Expand Down
35 changes: 18 additions & 17 deletions lib/framework/scaffold/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
var chalk = require('chalk');
var createScaffold = require('./create');
var inquirer = require('inquirer');
var getUsername = require('../../user/username');
var seedTools = require('../../util/seedTools');
var npm = require('../../util/npm');

var VALID_USERNAME_REGEXP = /^[a-z\-]+$/;
var VALID_COMPONENT_NAME_REGEXP = /^[a-z\-\:]+$/;

function createScaffoldWithAnswersAndLog(answers) {
createScaffold(answers, function() {
console.log(chalk.green('Created framework scaffold in current working directory!'));
console.log('To start up development, first run:');
console.log(' ', chalk.magenta('$ npm install && npm run dev'));
console.log('Then browse to', chalk.underline('http://localhost:1618'));
console.log('Installing npm dependencies and running setup tasks');
npm.runHook('setup', function(){
console.log('To start up development, first run:');
console.log(' ', chalk.magenta('$ npm run dev'));
console.log('Then browse to', chalk.underline('http://localhost:1618'));
});
});
}

Expand Down Expand Up @@ -47,19 +52,12 @@ function componentNamePrompt(cb) {
}

function usernamePrompt(cb) {
inquirer.prompt([{
type: 'input',
name: 'username',
message: 'Enter a username (e.g. "jon-doe"): '
}], function(usernameAnswer) {
if (!VALID_USERNAME_REGEXP.test(usernameAnswer.username)) {
console.log('Usernames may only contain lowercase letters and hyphens');
return usernamePrompt(cb);
}
return cb(usernameAnswer.username);
getUsername(function(error, data) {
cb(data.user.username);
});
}


function usernameComponentNamePrompt(cb) {
// TODO: Need to verify that the username matches
// the username of the user we just authenticated,
Expand All @@ -68,9 +66,12 @@ function usernameComponentNamePrompt(cb) {
usernamePrompt(function(username) {
componentNamePrompt(function(componentName) {
nameOkPrompt(username, componentName, function() {
return cb({
username: username,
componentName: componentName
var projectName = username + ':' + componentName;
seedTools.setHooks({'deploy-folder': 'public/' + projectName, 'deploy': [['run', 'snapshot-component', '--', '-n', projectName]], 'setup': [['install'], ['run', 'local-only-bootstrap', '--', '--watchAfterBuild=no']]}, function() {
return cb({
username: username,
componentName: componentName
});
});
});
});
Expand Down
9 changes: 5 additions & 4 deletions lib/user/username.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var https = require('https');
var chalk = require('chalk');

var getGlobal = require('../../res/sdk-bundle.js').storage.getGlobal;

Expand All @@ -21,7 +22,7 @@ var getUsername = function getUsername(callback) {
port: 443,
path: '/auth/v1/users',
method: 'GET',
headers: {'X-Authentication-Token': session.authentication_token}
headers: {'X-Authentication-Token': session.authentication_token}
};

var req = https.request(options, function(res) {
Expand All @@ -30,15 +31,15 @@ var getUsername = function getUsername(callback) {
body += d;
});
res.on('end', function() {
callback(JSON.parse(body));
callback(null, JSON.parse(body));
});
});
req.end();

req.on('error', function(e) {
console.error(e);
callback(e);
});
});
};

module.exports = getUsername;
module.exports = getUsername;
2 changes: 1 addition & 1 deletion lib/util/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var npm = {};
npm.runHook = function runHook(hook, callback) {
storage.getProjectMeta(function(error, config) {
if (config && config.scripts && config.scripts[hook]) {
npm.run(config.scripts[hook], callback);
npm.runScripts(config.scripts[hook], callback);
} else {
return callback(null, 1);
}
Expand Down

0 comments on commit 926e9f3

Please sign in to comment.