Skip to content

Commit 5994e1f

Browse files
authored
Merge pull request #20 from DouglasNeuroInformatics/dev
accommodate subpar GNU design choices
2 parents 06876aa + 243be15 commit 5994e1f

File tree

6 files changed

+34
-32
lines changed

6 files changed

+34
-32
lines changed

src/cli/bin/libnest

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/usr/bin/env node
1+
#!/bin/sh
22

3-
import { register } from 'node:module';
3+
DIR="$(dirname "$(realpath "$0")")"
4+
PARENT_DIR="$(dirname "$DIR")"
45

5-
register('@swc-node/register/esm', import.meta.url);
6-
7-
await import('../libnest.js');
6+
node --enable-source-maps "${PARENT_DIR}"/libnest.js "$@"

src/cli/bin/libnest-build

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/usr/bin/env node --enable-source-maps
1+
#!/bin/sh
22

3-
import { register } from 'node:module';
3+
DIR="$(dirname "$(realpath "$0")")"
4+
PARENT_DIR="$(dirname "$DIR")"
45

5-
register('@swc-node/register/esm', import.meta.url);
6-
7-
await import('../libnest-build.js');
6+
node --enable-source-maps "${PARENT_DIR}"/libnest-build.js "$@"

src/cli/bin/libnest-dev

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/usr/bin/env node --enable-source-maps --watch
1+
#!/bin/sh
22

3-
import { register } from 'node:module';
3+
DIR="$(dirname "$(realpath "$0")")"
4+
PARENT_DIR="$(dirname "$DIR")"
45

5-
register('@swc-node/register/esm', import.meta.url);
6-
7-
await import('../libnest-dev.js');
6+
node --enable-source-maps --watch "${PARENT_DIR}"/libnest-dev.js "$@"
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import * as module from 'node:module';
12
import * as process from 'node:process';
23

34
import { Command } from 'commander';
45

5-
import { buildProd } from '../meta/build.js';
6+
module.register('@swc-node/register/esm', import.meta.url);
7+
8+
const { buildProd } = await import('../meta/build.js');
69

710
const program = new Command();
811

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import * as module from 'node:module';
12
import * as process from 'node:process';
23

34
import { Command } from 'commander';
45

5-
const program = new Command();
6+
module.register('@swc-node/register/esm', import.meta.url);
67

78
const { runDev } = await import('../meta/dev.js');
89

10+
const program = new Command();
11+
912
program.exitOverride((err) => {
1013
process.kill(process.ppid);
1114
process.exit(err.exitCode);
1215
});
1316

14-
program.action(async function (this: void) {
17+
program.action(async function () {
1518
const configFile = process.env.LIBNEST_CONFIG_FILEPATH;
1619
if (!configFile) {
1720
return program.error(`error: environment variable 'LIBNEST_CONFIG_FILEPATH' must be defined`);
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
/**
2-
* The purpose of this file structure is to force commander to
3-
* use the shebang, which is necessary to provide flags to Node. If
4-
* the files do not have an extension, TypeScript won't check them, while
5-
* if they have an extension, Commander executes them with Node to accommodate
6-
* Windows users.
7-
*/
8-
91
import * as module from 'node:module';
2+
import * as path from 'node:path';
103
import * as process from 'node:process';
114

125
import { Command, InvalidArgumentError } from 'commander';
136

14-
import { resolveAbsoluteImportPath } from '../meta/resolve.js';
7+
module.register('@swc-node/register/esm', import.meta.url);
8+
9+
const { resolveAbsoluteImportPath } = await import('../meta/resolve.js');
1510

1611
const require = module.createRequire(import.meta.url);
1712

18-
const { name, version } = require('../../package.json') as { name: string; version: string };
13+
const { name, version } = require('../../package.json');
1914

2015
const program = new Command();
2116
program.name(name);
2217
program.version(version);
2318
program.allowExcessArguments(false);
24-
program.allowUnknownOption(false);
19+
program.allowUnknownOption(true);
2520
program.requiredOption('-c, --config-file <path>', 'path to the config file', (filename) => {
2621
const result = resolveAbsoluteImportPath(filename, process.cwd());
2722
if (result.isErr()) {
@@ -30,11 +25,15 @@ program.requiredOption('-c, --config-file <path>', 'path to the config file', (f
3025
return result.value;
3126
});
3227

33-
program.command('build', 'build application for production');
34-
program.command('dev', 'run application in development mode');
28+
program.command('build', 'build application for production', {
29+
executableFile: path.resolve(import.meta.dirname, 'bin/libnest-build')
30+
});
31+
program.command('dev', 'run application in development mode', {
32+
executableFile: path.resolve(import.meta.dirname, 'bin/libnest-dev')
33+
});
3534

3635
program.hook('preSubcommand', (command) => {
37-
const configFile = command.getOptionValue('configFile') as string;
36+
const configFile = command.getOptionValue('configFile');
3837
process.env.LIBNEST_CONFIG_FILEPATH = configFile;
3938
});
4039

0 commit comments

Comments
 (0)