Skip to content

Commit

Permalink
[bin] [refactor] Allow for non-pkg deployments
Browse files Browse the repository at this point in the history
  * Can now deploy single files without package
  * Moves require logic from `Hook.deploy` to bin
  * Should resolve #14
  • Loading branch information
Marak committed Dec 4, 2017
1 parent cddec3c commit 7b0dbdf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
30 changes: 25 additions & 5 deletions bin/hook-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,33 @@ var argv = require('minimist')(process.argv.slice(2));
var deployPath = argv._[0] || process.cwd();

var prompt = require('mschema-prompt');
var requireServiceSync = require('microcule').requireServiceSync;

// check incoming deployPath to see if there is a valid package.json or file to deploy

console.log('checking local file-system...');
var pkg;

try {
pkg = requireServiceSync({ path: deployPath });
} catch (err) {
throw err;
}

if (typeof pkg.pkg !== 'object') {
console.log('warning: no package.json found. using default values.')
}

console.log('detected language:', pkg.language);

// TODO: better handling of passed in options and deploy both
// allow for deploying single file without package, but make sure to confirm file name and then create name as file without ext, language auto-detected by extention and presented to user
// attempt to require service before confirmation in order to confirm location and language
var handlers = {
'confirm' : {
default: "yes",
required: true,
label: 'Deploy ' + deployPath + " ?",
label: 'Deploy ' + pkg.localPath + " ?",
conform: require('../lib/helpers/cli/conform-yes-no')
}
}
Expand All @@ -36,10 +57,11 @@ function _deploy (err, input) {
console.log('cancelled');
process.exit();
}
console.log('attempting to deploy: ' + deployPath);

console.log('attempting to deploy: ' + pkg.name);
console.log('connecting to: ' + config.uri);

client.hook.deploy({ path: deployPath }, function (err, result) {
client.hook.deploy(pkg, function (err, result) {
if (err) {
console.log('Error: ' + err.message);
if (err.code === "ENOENT") {
Expand All @@ -56,11 +78,9 @@ function _deploy (err, input) {
}
if (result.status === "created") {
console.log('created new service at: '+ config.uri + '/' + result.hook.owner + '/' + result.hook.name);
return;
}
if (result.status === "updated") {
console.log('updated service: ' + config.uri + '/' + result.hook.owner + '/' + result.hook.name);
return;
}
console.log(result);
});
Expand Down
21 changes: 6 additions & 15 deletions lib/hook/deploy.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
var config = require('../../config');

module['exports'] = function Deploy (opts, cb) {
module['exports'] = function Deploy (pkg, cb) {

var fs = require('fs');
var requireServiceSync = require('microcule').requireServiceSync;

var self = this;

//
// scan directory for potential app, if app is found attempt to create new hook with index.js as source
// package.json
// mschema.js - optional - mschema of the service
// view.html - optional - View of the service
// presenter.js - optional - View Presenter of the service
// read package.json for properties and use them ( if they exist )
var pkg, e = null;
try {
pkg = requireServiceSync({ path: opts.path });
} catch (err){
e = err;
}
if (e) {
return cb(e);

if (typeof pkg !== 'object') {
return cb(new Error('No pkg option was found.'))
}

pkg.owner = config.user;
self.get({ name: pkg.name, owner: config.user }, function (err, _hook) {
if (err) {
// return cb(err);
}
if (err) {
// could not find existing hook service with this name,
// attempt to create new service
// TODO: _create();
_create(pkg, function (err, _service){
if (err) {
return cb(err);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"microcule": "4.1.x",
"microcule-examples": "^5.0.0",
"minimist": "^1.2.0",
"mschema-prompt": "1.x.x",
"mschema-prompt": "^2.1.0",
"request": "^2.69.0",
"thenify": "^3.2.0",
"through2-concurrent": "^1.1.1",
Expand Down

0 comments on commit 7b0dbdf

Please sign in to comment.