Skip to content

Commit

Permalink
Merge safajirafa/refactor-start-print-routes into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Oct 2, 2018
2 parents 936b68b + e9a9972 commit 9b50c60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
33 changes: 11 additions & 22 deletions commands/start.js
@@ -1,7 +1,5 @@
'use strict';

const fs = require('fs');
const path = require('path');
const out = require('simple-output');
const globby = require('globby');
const methods = require('methods');
Expand Down Expand Up @@ -37,28 +35,19 @@ function startCmd(opts) {
}
}
function printRoutes(srcPath, port) {
globby('**/', {cwd: srcPath})
const patterns = methods.map(m => `**/${m}.+(json|js)`);

globby(patterns, {cwd: srcPath})
.then(paths => {
paths.forEach(pathName => {
if (methods.some(method => {
const fileLocation = path.join(srcPath, pathName, method);
return [
`${fileLocation}.js`,
`${fileLocation}.json`
].some(fileName => {
try {
fs.accessSync(fileName, fs.constants.R_OK);
return true;
} catch (err) {
return false;
}
});
})) {
out.info(`http://localhost:${port}/${pathName}`);
}
const routes = paths.map(p => {
// Remove filename from path
const directoryPath = p.substring(0, p.lastIndexOf('/'));
return `http://localhost:${port}/${directoryPath}`;
});
})
.catch(out.error);
for (let route of new Set(routes)) {
out.info(route);
}
});
}

module.exports = startCmd;
2 changes: 1 addition & 1 deletion test.js
Expand Up @@ -406,7 +406,7 @@ describe('snapstub cli', function () {
child.stdin.end();
function validateRouteMsg() {
child.stdout.once('data', d => {
assert.equal(d.toString(), 'ℹ http://localhost:8059/data/\n');
assert.equal(d.toString(), 'ℹ http://localhost:8059/data\n');
});
}
function validateSuccessMsg() {
Expand Down

0 comments on commit 9b50c60

Please sign in to comment.