Skip to content

Commit

Permalink
chore(cli): uncomment cli
Browse files Browse the repository at this point in the history
  • Loading branch information
gregswindle committed Apr 2, 2017
1 parent 83bf9b2 commit a9a1ac0
Showing 1 changed file with 109 additions and 109 deletions.
218 changes: 109 additions & 109 deletions lib/crc-model-cli.js
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
// #!/usr/bin/env node --harmony
// Const CrcModelFormatter = require('./crc-model-formatter');
// Const CrcModelList = require('./crc-model-list');
// Const concat = require('concat');
// Const fs = require('fs');
// Const glob = require('glob');
// Const mkdirp = require('mkdirp');
// Const path = require('path');
// Const program = require('commander');
// Const {version} = require('../package');
//
// /**
// * Prepend JavaScript comments to shebangs (!#) to prevent breaking the AST parser.
// *
// * @private
// * @param {string} code The source code to be parsed.
// *
// * @returns {string} The source code with shebangs commented (if any).
// */
// Const preprocessShebangs = (code) => {
// Return code.replace('#!', '// #!');
// };
//
// /**
// * Saves `CrcModels` to file.
// *
// * @private
// * @param {array<string>} files A list of files to be parsed.
// * @param {string} reportFilePath The filesystem location for the report.
// *
// * @returns {void}
// */
// Const generateReport = (files, output) => {
// Concat(files).then((code) => {
// Const crcModelList = new CrcModelList(preprocessShebangs(code));
// Const template = fs.readFileSync(path.resolve(__dirname, 'templates', 'crc-card.html'));
// Const formatter = new CrcModelFormatter(template);
// Const report = formatter.format(crcModelList);
// SaveToFile(report, output);
// }, (reason) => {
// Console.error(reason);
// }).catch((err) => {
// Console.warn(err);
// });
// };
//
// /**
// * Saves a Class-Responsibility-Collaboration report to the filesystem.
// *
// * @private
// * @param {string} report The CRC Model report.
// * @param {string} filepath The filesystem location for the report.
// *
// * @throws {Error} Throws an `Error` if the report cannot be saved.
// *
// * @returns {void}
// */
// Const saveToFile = (report, filepath) => {
// Const buffer = new Buffer(report);
// Const msg = 'Class-Responsibility-Collaborators report';
// Fs.open(filepath, 'w', function(err, fd) {
// If (err) {
// Throw `Error saving ${msg}: ${err}`;
// }
//
// Fs.write(fd, buffer, 0, buffer.length, null, function(err) {
// If (err) {
// Throw `Error saving ${msg}: ${err}`;
// }
// Fs.close(fd, function() {
// Console.log(`Saved ${msg} to ${filepath}.`);
// });
// });
// });
// };
//
// /**
// * A command-line interface that creates a Class-Responsibility-Collaborators report.
// */
// Program
// .version(version)
// .description('Generates a Class-Responsibility-Collaboration report for analysis and refactoring.')
// .arguments('<files>')
// .option('-o, --output [output]', 'The report destination. Defaults to "./crc-model-report."')
// .action((filePattern) => {
// Glob(filePattern, (err, files) => {
// If (err) {
// Console.error(err);
// }
// Const destFile = program.output || './reports/crc-model-report.md';
// Const destPath = path.dirname(destFile);
// Mkdirp(destPath, function (err) {
// If (err) {
// Console.error(err);
// }
// Else {
// GenerateReport(files, destFile);
// }
// });
// });
// });
//
// Const isCli = require.main === module;
//
// If (isCli) {
// Program.parse(process.argv);
// }
//
// Module.exports = program;
#!/usr/bin/env node --harmony
const CrcModelFormatter = require('./crc-model-formatter');
const CrcModelList = require('./crc-model-list');
const concat = require('concat');
const fs = require('fs');
const glob = require('glob');
const mkdirp = require('mkdirp');
const path = require('path');
const program = require('commander');
const {version} = require('../package');

/**
* Prepend JavaScript comments to shebangs (!#) to prevent breaking the AST parser.
*
* @private
* @param {string} code The source code to be parsed.
*
* @returns {string} The source code with shebangs commented (if any).
*/
const preprocessShebangs = (code) => {
return code.replace('#!', '// #!');
};

/**
* Saves `CrcModels` to file.
*
* @private
* @param {array<string>} files A list of files to be parsed.
* @param {string} reportFilePath The filesystem location for the report.
*
* @returns {void}
*/
const generateReport = (files, output) => {
concat(files).then((code) => {
const crcModelList = new CrcModelList(preprocessShebangs(code));
const template = fs.readFileSync(path.resolve(__dirname, 'templates', 'crc-card.html'));
const formatter = new CrcModelFormatter(template);
const report = formatter.format(crcModelList);
saveToFile(report, output);
}, (reason) => {
console.error(reason);
}).catch((err) => {
console.warn(err);
});
};

/**
* Saves a Class-Responsibility-Collaboration report to the filesystem.
*
* @private
* @param {string} report The CRC Model report.
* @param {string} filepath The filesystem location for the report.
*
* @throws {Error} throws an `Error` if the report cannot be saved.
*
* @returns {void}
*/
const saveToFile = (report, filepath) => {
const buffer = new Buffer(report);
const msg = 'Class-Responsibility-Collaborators report';
fs.open(filepath, 'w', function(err, fd) {
if (err) {
throw `Error saving ${msg}: ${err}`;
}

fs.write(fd, buffer, 0, buffer.length, null, function(err) {
if (err) {
throw `Error saving ${msg}: ${err}`;
}
fs.close(fd, function() {
console.log(`Saved ${msg} to ${filepath}.`);
});
});
});
};

/**
* A command-line interface that creates a Class-Responsibility-Collaborators report.
*/
program
.version(version)
.description('Generates a Class-Responsibility-Collaboration report for analysis and refactoring.')
.arguments('<files>')
.option('-o, --output [output]', 'The report destination. Defaults to "./crc-model-report."')
.action((filePattern) => {
glob(filePattern, (err, files) => {
if (err) {
console.error(err);
}
const destFile = program.output || './reports/crc-model-report.md';
const destPath = path.dirname(destFile);
mkdirp(destPath, function (err) {
if (err) {
console.error(err);
}
else {
generateReport(files, destFile);
}
});
});
});

const isCli = require.main === module;

if (isCli) {
program.parse(process.argv);
}

module.exports = program;

0 comments on commit a9a1ac0

Please sign in to comment.