-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfo.ts
More file actions
71 lines (60 loc) · 2.23 KB
/
info.ts
File metadata and controls
71 lines (60 loc) · 2.23 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
63
64
65
66
67
68
69
70
71
import type { Command } from 'commander';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'node:path';
import { getConfig } from '../config.ts';
import { PUP_VERSION } from '../app.ts';
import * as output from '../utils/output.ts';
/**
* Registers the `info` command with the CLI program.
*
* @since TBD
*
* @param {Command} program - The Commander.js program instance.
*
* @returns {void}
*/
export function registerInfoCommand(program: Command): void {
program
.command('info')
.description('Gets pup details for the current project.')
.action(async () => {
const config = getConfig();
const workingDir = config.getWorkingDir();
output.title('CLI Info');
output.log(`pup ${PUP_VERSION}`);
// Node.js version
output.log(`Using: Node.js ${process.version}`);
output.section('Working Directory');
output.log(workingDir);
output.section('File info');
const files = ['.distignore', '.distinclude', '.gitattributes', '.puprc'];
const filesError: string[] = [];
const filesExist: string[] = [];
const filesAbsent: string[] = [];
for (const file of files) {
const filePath = path.join(workingDir, file);
const exists = await fs.pathExists(filePath);
const styledFile = chalk.cyan(file);
if (exists && file === '.puprc') {
try {
const contents = await fs.readFile(filePath, 'utf-8');
JSON.parse(contents);
filesExist.push(`✅ ${styledFile} - ${chalk.green('exists')}`);
} catch (e) {
const reason = e instanceof SyntaxError ? e.message : String(e);
filesError.push(`❌ ${styledFile} - ${chalk.green('exists')} but could not be parsed: ${reason}`);
}
} else if (exists) {
filesExist.push(`✅ ${styledFile} - ${chalk.green('exists')}`);
} else {
filesAbsent.push(`⚫ ${styledFile} - does not exist`);
}
}
for (const line of filesError) output.log(line);
for (const line of filesExist) output.log(line);
for (const line of filesAbsent) output.log(line);
output.section('Config');
output.log(JSON.stringify(config.toJSON(), null, 2));
});
}