Skip to content

Commit

Permalink
update commander
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Nov 24, 2023
1 parent 8efaf18 commit 1edd967
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 14.x
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 16.x
- run: npm ci
- run: npm run test:cov
- name: Coveralls GitHub Action
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 14.x
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 16.x
- run: npm ci
- run: npm run jsdoc
- run: cp -f src/builder/declaration-schema.json docs
Expand Down
34 changes: 19 additions & 15 deletions bin/heta-build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const program = require('commander');
const { Command } = require('commander');
const program = new Command();
const fs = require('fs');
const path = require('path');
const { Builder } = require('../src/builder');
Expand All @@ -19,6 +20,7 @@ let contactMessage = colors.bgRed(`
`);

program
.name('heta build')
.description('Compile Heta based platform and create set of export files.')
//.arguments('<cmd> [dir]')
.usage('[options] [dir]')
Expand All @@ -39,11 +41,13 @@ program
.parse(process.argv);

(async () => {
let args = program.args;
let opts = program.opts();
// print newer version message
if (!program.skipUpdates) await printVersionMessage();
if (!opts.skipUpdates) await printVersionMessage();

// set target directory of platform and check if exist
let targetDir = path.resolve(program.args[0] || '.');
let targetDir = path.resolve(args[0] || '.');
if (!fs.existsSync(targetDir) || !fs.statSync(targetDir).isDirectory()) { // check if it does not exist or not a directory
process.stdout.write(`Target directory "${targetDir}" does not exist.\nSTOP!`);
process.exit(1); // BRAKE
Expand All @@ -52,16 +56,16 @@ program
// === read declaration file ===
// search
let searches = ['', '.json', '.json5', '.yml']
.map((ext) => path.join(targetDir, (program.declaration || 'platform') + ext));
.map((ext) => path.join(targetDir, (opts.declaration || 'platform') + ext));
let extensionNumber = searches
.map((x) => fs.existsSync(x) && fs.statSync(x).isFile() ) // check if it exist and is file
.indexOf(true);
// is declaration file found ?
if (!program.declaration && extensionNumber === -1) {
if (!opts.declaration && extensionNumber === -1) {
process.stdout.write('No declaration file, running with defaults...\n');
var declaration = {};
} else if (extensionNumber === -1) {
process.stdout.write(`Declaration file "${program.declaration}" not found.\nSTOP!`);
process.stdout.write(`Declaration file "${opts.declaration}" not found.\nSTOP!`);
process.exit(1); // BRAKE
} else {
let declarationFile = searches[extensionNumber];
Expand All @@ -81,17 +85,17 @@ program
// === options from CLI ===
let CLIDeclaration = {
options: {
unitsCheck: program.unitsCheck,
skipExport: program.skipExport,
logMode: program.logMode,
debug: program.debug,
juliaOnly: program.juliaOnly,
distDir: program.distDir,
metaDir: program.metaDir
unitsCheck: opts.unitsCheck,
skipExport: opts.skipExport,
logMode: opts.logMode,
debug: opts.debug,
juliaOnly: opts.juliaOnly,
distDir: opts.distDir,
metaDir: opts.metaDir
},
importModule: {
source: program.source,
type: program.type
source: opts.source,
type: opts.type
}
};

Expand Down
15 changes: 10 additions & 5 deletions bin/heta-init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const program = require('commander');
const { Command } = require('commander');
const program = new Command();
const fs = require('fs-extra');
const path = require('path');
const { prompt } = require('inquirer');
Expand Down Expand Up @@ -39,33 +40,37 @@ const defaultPlatform = {
};

program
.name('heta init')
.description('Creates template heta platform files in directory')
.usage('[options] [dir]')
.option('-f, --force', 'rewrite files in target directory')
.option('-s, --silent', 'use silent mode with default options')
.parse(process.argv);

let args = program.args;
let opts = program.opts();

// initialize file paths
let targetDir = path.resolve(program.args[0] || '.');
let targetDir = path.resolve(args[0] || '.');
let filePath = path.join(targetDir, 'platform.json');
console.log('Creating a template platform in directory: "' + targetDir + '"...');

// directory does not exist
if(!program.force && !fs.existsSync(targetDir)){
if(!opts.force && !fs.existsSync(targetDir)){
console.log(`Directory ${targetDir} does not exist. Use --force option to create directory.`);
console.log('STOP.');
process.exit(1);
}

// files already exists
if(!program.force && fs.existsSync(filePath)){
if(!opts.force && fs.existsSync(filePath)){
console.log('"platform.json" file already exists. Use --force option to rewrite file.');
console.log('STOP.');
process.exit(1);
}

// silent mode
if(program.silent){
if(opts.silent){
let platform = defaultPlatform;

// saving files
Expand Down
4 changes: 2 additions & 2 deletions bin/heta.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
'use strict';

const program = require('commander');
const { Command } = require('commander');
const program = new Command('heta');
const pkg = require('../package');

let version = pkg.version;
Expand Down
21 changes: 18 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ajv": "^6.12.6",
"ajv-errors": "^1.0.1",
"colors": "^1.4.0",
"commander": "^2.20.3",
"commander": "^11.1.0",
"fs-extra": "^7.0.1",
"heta-parser": "^0.3.16",
"inquirer": "^7.3.3",
Expand Down

0 comments on commit 1edd967

Please sign in to comment.