diff --git a/README.md b/README.md index d3e005d..cf54b9f 100644 --- a/README.md +++ b/README.md @@ -208,10 +208,10 @@ speculate --release=7 ### Custom Name -By default speculate will set the name from `package.json`, if you want to override this you can do so by using the `--custom-name` flag: +By default speculate will set the name from `package.json`, if you want to override this you can do so by using the `--name` flag: ```sh -speculate --custom-name=my-cool-api +speculate --name=my-cool-api ``` This is useful if you are using private NPM packages which start with an `@`. diff --git a/bin/speculate.js b/bin/speculate.js index e5b7937..985645c 100755 --- a/bin/speculate.js +++ b/bin/speculate.js @@ -21,20 +21,21 @@ var projectPkg = require(path.resolve(cwd, './package.json')); program .version(commandPkg.version) .option('-r --release ', 'Specify release number of package') - .option('-c --custom-name ', 'Specify custom name for package') + .option('-n --name ', 'Specify custom name for package') .parse(process.argv); -var name = program.customName || projectPkg.name; +// Commander has a magic property called name when not overriden by a parameter +var name = program.name instanceof Function ? undefined : program.name; clean(cwd, projectPkg); -generate(cwd, projectPkg, program.release, program.customName, function (err) { +generate(cwd, projectPkg, program.release, name, function (err, generated) { if (err) { console.error('Error:', err.message); process.exit(1); } - console.log('Created ./SPECS/%s.spec', name); - console.log('Created ./SOURCES/%s.tar.gz', name); - console.log('Created ./%s.service', name); + generated.forEach(function (file) { + console.log('Created ./%s', file); + }); process.exit(0); }); diff --git a/lib/generate.js b/lib/generate.js index 25f0dcb..f6566d9 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -1,5 +1,6 @@ var _ = require('lodash'); var fs = require('fs'); +var path = require('path'); var archiver = require('./archiver'); var createServiceFile = require('./service'); @@ -11,6 +12,8 @@ function generateServiceFile(root, pkg) { var serviceFilePath = files.serviceFile(root, pkg); fs.writeFileSync(serviceFilePath, serviceFileContents); + + return serviceFilePath; } function generateSpecFile(root, pkg, release) { @@ -18,6 +21,8 @@ function generateSpecFile(root, pkg, release) { var specFilePath = files.specFile(root, pkg); fs.writeFileSync(specFilePath, specFileContents); + + return specFilePath; } function addCustomFieldsToPackage(pkg, customName) { @@ -28,6 +33,12 @@ function addCustomFieldsToPackage(pkg, customName) { return pkg; } +function relativeToRoot(root, files) { + return files.map(function (file) { + return path.relative(root, file); + }); +} + module.exports = function (root, pkg, release, customName, cb) { var customPackage = addCustomFieldsToPackage(pkg, customName); var specsDirectory = files.specsDirectory(root); @@ -36,8 +47,18 @@ module.exports = function (root, pkg, release, customName, cb) { fs.mkdirSync(specsDirectory); fs.mkdirSync(sourcesDirectory); - generateServiceFile(root, customPackage); - generateSpecFile(specsDirectory, customPackage, release); + var serviceFile = generateServiceFile(root, customPackage); + var specFile = generateSpecFile(specsDirectory, customPackage, release); + + archiver.compress(root, sourcesArchive, function (err) { + if (err) { + return cb(err); + } - archiver.compress(root, sourcesArchive, cb); + cb(null, relativeToRoot(root, [ + specFile, + sourcesArchive, + serviceFile + ])); + }); }; diff --git a/test/generate.js b/test/generate.js index daaff3b..454ea48 100644 --- a/test/generate.js +++ b/test/generate.js @@ -117,4 +117,13 @@ describe('generate', function () { done(); }); }); + + it('returns an array of files created', function (done) { + var filesExpected = ['SPECS/my-cool-api.spec', 'SOURCES/my-cool-api.tar.gz', 'my-cool-api.service']; + generate('/path/to/project', pkg, null, null, function (err, files) { + assert.ifError(err); + assert.deepEqual(files, filesExpected); + done(); + }); + }); });