Make CLI ESM for compatibility with new yargs
This commit is contained in:
Executable → Regular
+9
-4
@@ -1,6 +1,12 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const yargs = require('yargs')(process.argv.slice(2))
|
import { createRequire } from 'node:module';
|
||||||
|
import yargs from 'yargs';
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const Precompiler = require('../dist/cjs/precompiler');
|
||||||
|
|
||||||
|
const parser = yargs(process.argv.slice(2))
|
||||||
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...')
|
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...')
|
||||||
.help(false)
|
.help(false)
|
||||||
.version(false)
|
.version(false)
|
||||||
@@ -107,18 +113,17 @@ const yargs = require('yargs')(process.argv.slice(2))
|
|||||||
})
|
})
|
||||||
.wrap(120);
|
.wrap(120);
|
||||||
|
|
||||||
const argv = yargs.parseSync();
|
const argv = parser.parseSync();
|
||||||
argv.files = argv._;
|
argv.files = argv._;
|
||||||
delete argv._;
|
delete argv._;
|
||||||
|
|
||||||
const Precompiler = require('../dist/cjs/precompiler');
|
|
||||||
Precompiler.loadTemplates(argv, function (err, opts) {
|
Precompiler.loadTemplates(argv, function (err, opts) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.help || (!opts.templates.length && !opts.version)) {
|
if (opts.help || (!opts.templates.length && !opts.version)) {
|
||||||
yargs.showHelp('log');
|
parser.showHelp('log');
|
||||||
} else {
|
} else {
|
||||||
Precompiler.cli(opts);
|
Precompiler.cli(opts);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
"url": "https://github.com/handlebars-lang/handlebars.js.git"
|
"url": "https://github.com/handlebars-lang/handlebars.js.git"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"handlebars": "bin/handlebars.js"
|
"handlebars": "bin/handlebars.mjs"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"bin",
|
"bin",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Precompile handlebar templates.
|
Precompile handlebar templates.
|
||||||
Usage: handlebars.js [template|directory]...
|
Usage: handlebars.mjs [template|directory]...
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-f, --output Output File [string]
|
-f, --output Output File [string]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const fs = require('fs');
|
|||||||
const { execCommand, FileTestHelper } = require('cli-testlab');
|
const { execCommand, FileTestHelper } = require('cli-testlab');
|
||||||
const Handlebars = require('../../lib');
|
const Handlebars = require('../../lib');
|
||||||
|
|
||||||
const cli = 'node ./bin/handlebars.js';
|
const cli = 'node ./bin/handlebars.mjs';
|
||||||
|
|
||||||
expect.extend({
|
expect.extend({
|
||||||
toEqualWithRelaxedSpace(received, expected) {
|
toEqualWithRelaxedSpace(received, expected) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ cd "$( dirname "$( readlink -f "$0" )" )" || exit 1
|
|||||||
unset npm_config_prefix
|
unset npm_config_prefix
|
||||||
|
|
||||||
echo "Handlebars should be able to run in various versions of NodeJS"
|
echo "Handlebars should be able to run in various versions of NodeJS"
|
||||||
for node_version_to_test in 18 20; do
|
for node_version_to_test in 20 22; do
|
||||||
|
|
||||||
rm -rf target node_modules package-lock.json
|
rm -rf target node_modules package-lock.json
|
||||||
mkdir target
|
mkdir target
|
||||||
|
|||||||
Reference in New Issue
Block a user