Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dist/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

module.exports = function () {
var currentVersion = require('../package.json').version;
return new Promise(function (resolve, reject) {
var spawn = require('child_process').spawn;
var semver = require('semver');
var versionProc = spawn('npm', ['view', 'perk-cli', 'version']);
return versionProc.stdout.on('data', function (data) {
var versionString = String(data);
if (semver.gt(versionString, currentVersion)) {
// version is outdated
console.log('There is a newer version of perk-cli available please upgrade');
return resolve(false);
}
return resolve(true);
});
version.stderr.on('data', function (data) {
// console.log(`stderr: ${data}`);
});
});
};
17 changes: 10 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var path = require('path');
var steps = require('./steps');
var check = require('./check');

var PERK_URL = 'http://api.perkframework.com/location';
var TMP_PATH = path.join(__dirname, 'tmp');
Expand All @@ -21,13 +22,15 @@ if (!path.isAbsolute(targetPath)) {
targetPath = path.join(process.cwd(), targetPath);
}

steps.all({
tmpPath: TMP_PATH,
downloadPath: DOWNLOAD_PATH,
perkUrl: PERK_URL,
zipPath: ZIP_PATH,
extractPath: EXTRACT_PATH,
targetPath: targetPath
check().then(function (current) {
return steps.all({
tmpPath: TMP_PATH,
downloadPath: DOWNLOAD_PATH,
perkUrl: PERK_URL,
zipPath: ZIP_PATH,
extractPath: EXTRACT_PATH,
targetPath: targetPath
}, current);
}).then(console.log).catch(function (err) {
if (err.code === 'EACCES') {
console.log('Permission was denied on ' + err.path + ' directory for downloading perk files');
Expand Down
8 changes: 4 additions & 4 deletions dist/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var mergedirs = require('merge-dirs').default;
var _help = '\n\n\nusage: perk <install path>\n\nPerk is a well documented set of tools for building node web\napplications.\n\nUsing the perk command will download and install of the necessary perk\nfiles in the specified <install path>. The <install path> should\nspecify the directory where you want to set up your perk project.\n\nYou can read more about perk at http://perkframework.com\n\n\n\n';

module.exports = {
all: function all(locations) {
all: function all(locations, current) {
var _this = this;

return this.ensureDir(locations.tmpPath).then(function (p) {
Expand All @@ -26,7 +26,7 @@ module.exports = {
}).then(function (unzipDir) {
return mergedirs(unzipDir, locations.targetPath, 'skip');
}).then(function () {
return _this.finish(locations.targetPath);
return _this.finish(locations.targetPath, current);
});
},
help: function help() {
Expand Down Expand Up @@ -133,7 +133,7 @@ module.exports = {
});
});
},
finish: function finish(dirPath) {
return '\n\n\nYour new project has successfully been created in ' + dirPath + '\n\nYou should run:\n\n\tcd ' + dirPath + ' && npm install\n\nWhile dependencies for your new perk app are installing you can check\nout more info on how to use all the great features of perk at:\n\nhttp://perkframework.com/v1/guides/getting-started-os-x.html\n\n\n\n';
finish: function finish(dirPath, current) {
return '\n\n\nYour new project has successfully been created in ' + dirPath + '\n\nYou should run:\n\n\tcd ' + dirPath + ' && npm install\n\nWhile dependencies for your new perk app are installing you can check\nout more info on how to use all the great features of perk at:\n\nhttp://perkframework.com/v1/guides/getting-started-os-x.html\n\n\n\n' + (current ? '' : 'Be Aware your perky-cli version is outdated, there may be differences with the docs');
}
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"async": "^1.5.2",
"fs-extra": "^0.26.5",
"merge-dirs": "^0.2.1",
"request": "^2.69.0"
"request": "^2.69.0",
"semver": "^5.3.0"
},
"devDependencies": {
"babel-cli": "^6.5.1",
Expand Down
20 changes: 20 additions & 0 deletions src/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function() {
var currentVersion = require('../package.json').version;
return new Promise((resolve, reject) => {
const spawn = require('child_process').spawn;
const semver = require('semver');
const versionProc = spawn('npm', ['view', 'perk-cli', 'version']);
return versionProc.stdout.on('data', (data) => {
const versionString = String(data);
if (semver.gt(versionString, currentVersion)) {
// version is outdated
console.log('There is a newer version of perk-cli available please upgrade');
return resolve(false);
}
return resolve(true);
});
version.stderr.on('data', (data) => {
// console.log(`stderr: ${data}`);
});
});
};
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node --use_strict
let path = require('path');
let steps = require('./steps');
let check = require('./check');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we name this something different than check for clarity. Maybe checkVersion?


const PERK_URL = 'http://api.perkframework.com/location';
const TMP_PATH = path.join(__dirname, 'tmp');
Expand All @@ -19,13 +20,15 @@ if(!path.isAbsolute(targetPath)) {
targetPath = path.join(process.cwd(), targetPath);
}

steps.all({
tmpPath: TMP_PATH,
downloadPath: DOWNLOAD_PATH,
perkUrl: PERK_URL,
zipPath: ZIP_PATH,
extractPath: EXTRACT_PATH,
targetPath: targetPath
check().then((current) => {
return steps.all({
tmpPath: TMP_PATH,
downloadPath: DOWNLOAD_PATH,
perkUrl: PERK_URL,
zipPath: ZIP_PATH,
extractPath: EXTRACT_PATH,
targetPath: targetPath
}, current);
})
.then(console.log)
.catch(err => {
Expand Down
8 changes: 4 additions & 4 deletions src/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You can read more about perk at http://perkframework.com
`;

module.exports = {
all: function(locations) {
all: function(locations, current) {
return this.ensureDir(locations.tmpPath)
.then(p => this.clearPath(locations.extractPath))
.then(p => this.ensureDir(locations.downloadPath))
Expand All @@ -32,7 +32,7 @@ module.exports = {
.then(location => this.download(location, locations.zipPath))
.then(downloadDir => this.unzip(downloadDir, locations.extractPath))
.then(unzipDir => mergedirs(unzipDir, locations.targetPath, 'skip'))
.then(() => this.finish(locations.targetPath));
.then(() => this.finish(locations.targetPath, current));
},
help: function() {
return help;
Expand Down Expand Up @@ -150,7 +150,7 @@ module.exports = {
});
});
},
finish: function(dirPath) {
finish: function(dirPath, current) {
return `


Expand All @@ -167,6 +167,6 @@ http://perkframework.com/v1/guides/getting-started-os-x.html



`;
` + (current ? '' : 'Be Aware your perky-cli version is outdated, there may be differences with the docs');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With ES6 string interpolation you could stick this right inside of the previous message instead of concatenating. Also there's a small typo (perky-cli) and we should notify them how to upgrade their perk-cli if they want to:

eg.

return `


 Your new project has successfully been created in ${dirPath}

 You should run:

    cd ${dirPath} && npm install

 While dependencies for your new perk app are installing you can check
 out more info on how to use all the great features of perk at:

 http://perkframework.com/v1/guides/getting-started-os-x.html


 ${current ? '' : 'Be Aware your perk-cli version is outdated, there may be differences with the docs. To upgrade run `npm install-g perk-cli`'}
 `;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking forward to getting this deployed. Great work!

}
};