Skip to content

Commit

Permalink
check index file before building
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Apr 22, 2020
1 parent 0695a39 commit e5e896d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
53 changes: 28 additions & 25 deletions bin/heta-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ program
.description('Compile Heta based platform and create set of export files.')
//.arguments('<cmd> [dir]')
.usage('[options] [dir]')
.option('-d, --declaration <filepath>', 'platform declaration file without extension, search extensions: ["", ".json", ".json5", ".yml"]', 'platform')
.option('-d, --declaration <filepath>', 'declaration file name without extension to search throught extensions: ["", ".json", ".json5", ".yml"]', 'platform')
// options
.option('--skip-export', 'do not export files to local directory')
.option('--log-mode <never|error|always>', 'When to create log file.')
.option('--debug', 'If set the raw module output will be stored in "meta".')
.option('-S, --skip-export', 'do not export files to local directory')
.option('-L, --log-mode <never|error|always>', 'When to create log file.')
.option('-d, --debug', 'If set the raw module output will be stored in "meta".')
// moduleImport
.option('--source <filepath>', 'path to main heta module.')
.option('--type <heta|xlsx|json|yaml|sbml>', 'type of source file.')
.option('-s, --source <filepath>', 'path to main heta module.')
.option('-t, --type <heta|xlsx|json|yaml|sbml>', 'type of source file.')
.parse(process.argv);

// set target directory of platform
Expand All @@ -46,17 +46,16 @@ let extensionNumber = searches
.indexOf(true);
// is declaration file found ?
if (extensionNumber === -1) {
process.stdout.write('Running compilation without declaration file...\n');
var declaration = {};
//console.log( 'Declaration file is not found in paths:\n', JSON.stringify(searches, null, 2));
console.log('Running compilation without declaration file.');
} else {
let delarationFile = searches[extensionNumber];
console.log(`Running compilation with declaration "${delarationFile}"`);
let declarationText = fs.readFileSync(delarationFile);
let declarationFile = searches[extensionNumber];
process.stdout.write(`Running compilation with declaration file "${declarationFile}"...\n`);
let declarationText = fs.readFileSync(declarationFile);
try {
declaration = safeLoad(declarationText);
} catch (e) {
console.log('Wrong format of declaration file:', e.message);
process.stdout.write(`Wrong format of declaration file: \n"${e.message}"\n`);
process.exit(1);
}
}
Expand All @@ -74,39 +73,43 @@ let CLIDeclaration = {
}
};

// === combine options ===
// === combine options CLI => declaration => default index ===
let integralDeclaration = _.defaultsDeep(CLIDeclaration, declaration);

// wrong version throws, if no version stated than skip
let satisfiesVersion = integralDeclaration.builderVersion
? semver.satisfies(version, integralDeclaration.builderVersion)
: true;
if (!satisfiesVersion) {
console.log(`Version of declaration file "${integralDeclaration.builderVersion}" does not satisfy current builder.`);
process.stdout.write(`Version of declaration file "${integralDeclaration.builderVersion}" does not satisfy current builder.\n`);
process.exit(1);
}

// === runBuilder ===
let builder = new Builder(integralDeclaration, targetDir);
// === this part uses "send errors to developer" message ===
try {
var builder = new Builder(integralDeclaration, targetDir);
} catch(e) {
process.stdout.write(contactMessage + '\n');
throw e;
}
if (builder.logger.hasErrors) {
console.log('Declaration ERROR! See logs.');
process.stdout.write('Declaration ERROR! See logs.\n');
process.exit(1);
}

// send errors to developer
try {
builder.run();
} catch(e) {
console.log(contactMessage);
process.stdout.write(contactMessage + '\n');
throw e;
}

if (builder.logger.hasErrors) {
console.log('Compilation ERROR! See logs.');
integralDeclaration.options.exitWithoutError
? process.exit(0)
: process.exit(1);
process.stdout.write('Compilation ERROR! See logs.\n');
if (integralDeclaration.options.exitWithoutError)
process.exit(0);
else
process.exit(1);
} else {
console.log('Compilation OK!');
process.stdout.write('Compilation OK!\n');
process.exit(0);
}
4 changes: 2 additions & 2 deletions cases/0-hello-world/src/index.heta
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ end
filepath: matlab1,
};

/*
mm::mm_sbml @SBMExport { title: Exported mm model};
/*
mm::mm_sbml @SBMLExport { title: Exported mm model};
mm::mm_simbio @SimbioExport;
mm::full_json @JSONExport;
mm::full_yaml @YAMLExport;
Expand Down
9 changes: 8 additions & 1 deletion src/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Builder {
return;
}

// assignments
// file paths
Object.assign(this, declaration);
this._coreDirname = path.resolve(coreDirname);
this._distDirname = path.resolve(coreDirname, declaration.options.distDir);
Expand All @@ -58,7 +58,14 @@ class Builder {
// create container
this.container = new Container();
this.logger.info(`Builder initialized in directory "${this._coreDirname}".`);

// index file not found
let indexFilepath = path.resolve(coreDirname, declaration.importModule.source);
if (!fs.existsSync(indexFilepath)) {
this.logger.error(`index file "${indexFilepath}" does not exist.`, 'BuilderError');
}
}

run(){
this.logger.info(`Compilation of module "${this.importModule.source}" of type "${this.importModule.type}"...`);

Expand Down

0 comments on commit e5e896d

Please sign in to comment.