Add moment.js as a dependency, enhance TypeScript configuration to exclude scripts, and introduce new examples for dependency injection and health checks.

This commit is contained in:
2025-10-26 09:39:46 -04:00
parent 5d9b77ef7d
commit 3429df650f
26 changed files with 868 additions and 30 deletions

81
scripts/Runner.js Normal file
View File

@@ -0,0 +1,81 @@
import fs from 'fs';
import path from 'path';
import {spawn} from 'child_process';
const node = process.execPath;
const nodeDir = path.dirname(node);
let npm = path.join(nodeDir, 'npm.cmd');
if (!fs.existsSync(npm)) {
const alternateNpm = path.join(nodeDir, 'npm');
if (fs.existsSync(alternateNpm)) {
npm = alternateNpm;
}
}
class Runner {
_node = process.execPath;
_nodeDir = path.dirname(this._node);
_npm;
constructor() {
this._npm = path.join(this._nodeDir, 'npm.cmd');
if (!fs.existsSync(this._npm)) {
const alternateNpm = path.join(this._nodeDir, 'npm');
if (fs.existsSync(alternateNpm)) {
this._npm = alternateNpm;
}
}
}
runCommands(commands, done) {
let command = commands[0];
if (typeof command === 'string') {
command = command.split(' ');
}
if (command.length > 0) {
if (command[0] === 'npm') {
command[0] = this._npm;
} else if (command[0] === 'node') {
command[0] = this._node;
}
}
this.run(command, () => {
if (commands.length > 1) {
this.runCommands(commands.slice(1), done);
} else {
if (done) {
done();
}
}
});
}
run(command, next) {
const childProcess = spawn(command[0], command.slice(1), {stdio: 'inherit'});
childProcess.on('error', error => {
console.error('Error [%o]', error);
process.exit(40);
});
childProcess.on('close', code => {
if (code !== 0) {
console.error('Command [%o] exited with code [%d]', command, code);
process.exit(code);
}
next();
});
}
}
export default new Runner();

5
scripts/npm-install.js Normal file
View File

@@ -0,0 +1,5 @@
import runner from './Runner.js';
runner.runCommands(['node --version', 'npm --version', 'npm install --no-save'], () => {
process.exit(0);
});

3
scripts/version.js Normal file
View File

@@ -0,0 +1,3 @@
import packageJSON from '../package.json' with {type: 'json'};
process.stdout.write(packageJSON.version);