-
Notifications
You must be signed in to change notification settings - Fork 0
TypeScript Rewrite: App bootstrap, config, and shared utilities #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ENG-219/build-setup
Are you sure you want to change the base?
Changes from 14 commits
ff051ce
e768bf1
71b22cc
d18da44
d130c3e
b0a0516
37f4c92
56a1585
12df110
3fb3385
741d07d
cd4894d
ec2249e
9f478e1
3ccbe0a
3135f4b
75308bc
fe88e3a
8bc0588
35d61a5
f6c5a1d
959c4a6
8c31609
bf9d965
658a8fa
391ea51
3c45c6f
f7e5f20
4aeabfd
ea8ee0e
a497018
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
This file was deleted.
This file was deleted.
d4mation marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { Command } from 'commander'; | ||
| import { Config, getConfig, resetConfig } from './config.js'; | ||
| import * as output from './utils/output.js'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import path from 'node:path'; | ||
| import fs from 'fs-extra'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| /** | ||
| * Reads the pup version from the nearest package.json. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @returns {string} The version string from package.json, or '2.0.0' as a fallback. | ||
| */ | ||
| function getVersion(): string { | ||
| // Try to read from package.json | ||
| const candidates = [ | ||
| path.resolve(__dirname, '..', 'package.json'), | ||
| path.resolve(__dirname, '..', '..', 'package.json'), | ||
| ]; | ||
|
|
||
| for (const candidate of candidates) { | ||
| if (fs.existsSync(candidate)) { | ||
| const pkg = JSON.parse(fs.readFileSync(candidate, 'utf-8')) as { version: string }; | ||
| return pkg.version; | ||
| } | ||
| } | ||
|
|
||
| return '2.0.0'; | ||
| } | ||
|
|
||
| export const PUP_VERSION = getVersion(); | ||
|
|
||
| /** | ||
| * Creates and configures the Commander program instance. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @returns {Command} The configured Commander program. | ||
| */ | ||
| export function createApp(): Command { | ||
| resetConfig(); | ||
|
|
||
| const config = getConfig(); | ||
| if (config.hasInvalidPuprc()) { | ||
| output.error('There is a .puprc file in this directory, but it could not be parsed.'); | ||
| output.error(`JSON Error: ${config.getPuprcParseError()}`); | ||
| } | ||
|
|
||
| const program = new Command(); | ||
| program | ||
| .name('pup') | ||
| .version(PUP_VERSION) | ||
| .description("StellarWP's Project Utilities & Packager"); | ||
|
|
||
| return program; | ||
| } | ||
|
|
||
| export { Config, getConfig, resetConfig }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { createApp } from './app.js'; | ||
|
|
||
| const program = createApp(); | ||
|
|
||
| program.parseAsync(process.argv).catch((err) => { | ||
| console.error(err instanceof Error ? err.message : String(err)); | ||
| process.exit(1); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.