Skip to content

Commit

Permalink
Update the composer-archive create with improved output (hyperledger-…
Browse files Browse the repository at this point in the history
…archives#1035)

* get the loopback adapter up and working

* updates to unit test

* Unit test updates

* Update the composer archive create cli for better output
  • Loading branch information
mbwhite authored and Jakeeyturner committed May 18, 2017
1 parent b6be6ce commit 275773c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
5 changes: 2 additions & 3 deletions packages/composer-cli/lib/cmds/archive/createCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ module.exports.handler = (argv) => {

argv.thePromise = Create.handler(argv)
.then(() => {
console.log ('Command completed successfully.');
return 0;
})
.catch((error) => {
console.log(error.stack);
console.log(error+ '\nCommand failed.');
throw error;
});

return argv.thePromise;
Expand Down
26 changes: 17 additions & 9 deletions packages/composer-cli/lib/cmds/archive/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const Admin = require('composer-admin');
const BusinessNetworkDefinition = Admin.BusinessNetworkDefinition;
const fs = require('fs');
const sanitize = require('sanitize-filename');

// const ora = require('ora');
const chalk = require('chalk');

/**
* Composer Create Archive command
*
Expand All @@ -37,23 +41,24 @@ class Create {

let inputDir = '';

console.log('Creating Business Network Archive\n');
console.log(chalk.blue.bold('Creating Business Network Archive\n'));
if (argv.sourceType === 'module'){
// using a npm module name
//
let moduleName = argv.sourceName;
const path = require('path');
console.log('Node module search path : \n'+process.env.NODE_PATH+' \n');

let moduleIndexjs;
try {
moduleIndexjs=require.resolve(moduleName);
} catch (err){
if (err.code==='MODULE_NOT_FOUND'){
let localName = process.cwd()+'/node_modules/'+moduleName;
console.log('Not found in main node_module search path, trying current directory :'+localName);
console.log(chalk.bold.yellow('Not found in main node_module search path, trying current directory'));
console.log(chalk.yellow('\tCurrent Directory: ')+localName);
moduleIndexjs=require.resolve(localName);
}else {
console.log('Unable to locate the npm module specified');
console.log(chalk.blue.red('Unable to locate the npm module specified'));
return Promise.reject(err);
}

Expand All @@ -69,12 +74,14 @@ class Create {
inputDir = argv.sourceName;
}
}
console.log('Looking for package.json of Business Network Definition in '+inputDir);
console.log(chalk.blue.bold('\nLooking for package.json of Business Network Definition'));
console.log(chalk.blue('\tInput directory: ')+inputDir);

return BusinessNetworkDefinition.fromDirectory(inputDir).then( (result)=> {
console.log('\nFound:\nDescription:'+result.getDescription());
console.log('Name:'+result.getName());
console.log('Identifier:'+result.getIdentifier());
console.log(chalk.blue.bold('\nFound:'));
console.log(chalk.blue('\tDescription: ')+result.getDescription());
console.log(chalk.blue('\tName: ')+result.getName());
console.log(chalk.blue('\tIdentifier: ')+result.getIdentifier());


if (!argv.archiveFile){
Expand All @@ -85,7 +92,8 @@ class Create {
(result) => {
//write the buffer to a file
fs.writeFileSync(argv.archiveFile,result);
console.log('\nWritten Business Network Definition Archive file to '+argv.archiveFile);
console.log(chalk.blue.bold('\nWritten Business Network Definition Archive file to '));
console.log(chalk.blue('\tOutput file: ')+argv.archiveFile);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/composer-cli/lib/cmds/archive/listCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ module.exports.handler = (argv) => {

argv.thePromise = List.handler(argv)
.then(() => {
console.log ('Command completed successfully.');
return 0;
})
.catch((error) => {
console.log(error+ '\nCommand failed.');
throw error;
});
return argv.thePromise;
};
2 changes: 1 addition & 1 deletion packages/composer-common/lib/businessnetworkdefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class BusinessNetworkDefinition {
let scriptFiles = scriptManager.getScripts();
scriptFiles.forEach(function(file) {
let fileIdentifier = file.identifier;
let fileName = fileIdentifier.substring(fileIdentifier.lastIndexOf('/') + 1);
let fileName = fsPath.parse(fileIdentifier).base;
zip.folder('lib').file(fileName, file.contents);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ module.exports = function (app, callback) {

// Apply any required updates to the specified model schema.
modelSchema = updateModelSchema(modelSchema);

console.log(modelSchema);
// This call creates the model class from the model schema.
let model = app.loopback.createModel(modelSchema);

Expand Down

0 comments on commit 275773c

Please sign in to comment.