-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
62 lines (52 loc) · 1.58 KB
/
app.ts
File metadata and controls
62 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 };