command-code 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const configCommand: Command;
3
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0BpC,eAAO,MAAM,aAAa,SA2DvB,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { Command } from 'commander';
2
+ import { Logger, parseJSON } from '@command-code/shared';
3
+ import * as fs from 'fs/promises';
4
+ import * as path from 'path';
5
+ import * as os from 'os';
6
+ const logger = new Logger('Config');
7
+ const configPath = path.join(os.homedir(), '.command-code-config.json');
8
+ async function loadConfig() {
9
+ try {
10
+ const data = await fs.readFile(configPath, 'utf-8');
11
+ return parseJSON(data) || {};
12
+ }
13
+ catch {
14
+ return {};
15
+ }
16
+ }
17
+ async function saveConfig(config) {
18
+ await fs.writeFile(configPath, JSON.stringify(config, null, 2));
19
+ }
20
+ export const configCommand = new Command('config')
21
+ .description('Manage CLI configuration')
22
+ .addCommand(new Command('get')
23
+ .description('Get a configuration value')
24
+ .argument('<key>', 'Configuration key')
25
+ .action(async (key) => {
26
+ const config = await loadConfig();
27
+ const value = config[key];
28
+ if (value !== undefined) {
29
+ logger.info(`${key}: ${JSON.stringify(value)}`);
30
+ }
31
+ else {
32
+ logger.warn(`Key "${key}" not found in configuration`);
33
+ }
34
+ }))
35
+ .addCommand(new Command('set')
36
+ .description('Set a configuration value')
37
+ .argument('<key>', 'Configuration key')
38
+ .argument('<value>', 'Configuration value')
39
+ .action(async (key, value) => {
40
+ const config = await loadConfig();
41
+ let parsedValue = value;
42
+ if (value === 'true')
43
+ parsedValue = true;
44
+ else if (value === 'false')
45
+ parsedValue = false;
46
+ else if (!isNaN(Number(value)))
47
+ parsedValue = Number(value);
48
+ config[key] = parsedValue;
49
+ await saveConfig(config);
50
+ logger.success(`Set ${key} = ${JSON.stringify(parsedValue)}`);
51
+ }))
52
+ .addCommand(new Command('list')
53
+ .description('List all configuration values')
54
+ .action(async () => {
55
+ const config = await loadConfig();
56
+ if (Object.keys(config).length === 0) {
57
+ logger.info('No configuration values set');
58
+ }
59
+ else {
60
+ logger.info('Current configuration:');
61
+ Object.entries(config).forEach(([key, value]) => {
62
+ console.log(` ${key}: ${JSON.stringify(value)}`);
63
+ });
64
+ }
65
+ }))
66
+ .addCommand(new Command('reset')
67
+ .description('Reset all configuration')
68
+ .action(async () => {
69
+ await saveConfig({});
70
+ logger.success('Configuration reset successfully');
71
+ }));
72
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,2BAA2B,CAAC,CAAC;AAMxE,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACpD,OAAO,SAAS,CAAS,IAAI,CAAC,IAAI,EAAE,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,K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@@
1
+ import { Command } from 'commander';
2
+ export declare const greetCommand: Command;
3
+ //# sourceMappingURL=greet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greet.d.ts","sourceRoot":"","sources":["../../src/commands/greet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,YAAY,SAmBrB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { Command } from 'commander';
2
+ import { Logger, capitalize } from '@command-code/shared';
3
+ const logger = new Logger('Greet');
4
+ export const greetCommand = new Command('greet')
5
+ .description('Greet a user')
6
+ .argument('[name]', 'Name to greet', 'World')
7
+ .option('-u, --uppercase', 'Convert to uppercase')
8
+ .option('-e, --excited', 'Add excitement')
9
+ .action((name, options) => {
10
+ let greeting = `Hello, ${capitalize(name)}`;
11
+ if (options.uppercase) {
12
+ greeting = greeting.toUpperCase();
13
+ }
14
+ if (options.excited) {
15
+ greeting += '!!!';
16
+ }
17
+ else {
18
+ greeting += '!';
19
+ }
20
+ logger.success(greeting);
21
+ });
22
+ //# sourceMappingURL=greet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"greet.js","sourceRoot":"","sources":["../../src/commands/greet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAC7C,WAAW,CAAC,cAAc,CAAC;KAC3B,QAAQ,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,CAAC;KAC5C,MAAM,CAAC,iBAAiB,EAAE,sBAAsB,CAAC;KACjD,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC;KACzC,MAAM,CAAC,CAAC,IAAY,EAAE,OAAmD,EAAE,EAAE;IAC5E,IAAI,QAAQ,GAAG,UAAU,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;IAE5C,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,QAAQ,IAAI,KAAK,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,QAAQ,IAAI,GAAG,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const infoCommand: Command;
3
+ //# sourceMappingURL=info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../src/commands/info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,WAAW,SAkCpB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { Command } from 'commander';
2
+ import { Logger, formatDate } from '@command-code/shared';
3
+ import * as os from 'os';
4
+ const logger = new Logger('Info');
5
+ export const infoCommand = new Command('info')
6
+ .description('Display system information')
7
+ .option('-v, --verbose', 'Show verbose output')
8
+ .action((options) => {
9
+ logger.info('System Information:');
10
+ console.log('-------------------');
11
+ console.log(`📅 Date: ${formatDate()}`);
12
+ console.log(`💻 Platform: ${os.platform()}`);
13
+ console.log(`🏗️ Architecture: ${os.arch()}`);
14
+ console.log(`🧮 CPUs: ${os.cpus().length}`);
15
+ console.log(`💾 Memory: ${Math.round(os.totalmem() / 1024 / 1024 / 1024)} GB`);
16
+ console.log(`📁 Home Directory: ${os.homedir()}`);
17
+ if (options.verbose) {
18
+ console.log('\nDetailed CPU Information:');
19
+ os.cpus().forEach((cpu, index) => {
20
+ console.log(` CPU ${index}: ${cpu.model} @ ${cpu.speed} MHz`);
21
+ });
22
+ console.log('\nNetwork Interfaces:');
23
+ const networkInterfaces = os.networkInterfaces();
24
+ Object.keys(networkInterfaces).forEach((iface) => {
25
+ const addresses = networkInterfaces[iface];
26
+ if (addresses) {
27
+ addresses.forEach((addr) => {
28
+ if (addr.family === 'IPv4' && !addr.internal) {
29
+ console.log(` ${iface}: ${addr.address}`);
30
+ }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ logger.success('Information displayed successfully!');
36
+ });
37
+ //# sourceMappingURL=info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"info.js","sourceRoot":"","sources":["../../src/commands/info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,4BAA4B,CAAC;KACzC,MAAM,CAAC,eAAe,EAAE,qBAAqB,CAAC;KAC9C,MAAM,CAAC,CAAC,OAA8B,EAAE,EAAE;IACzC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,YAAY,UAAU,EAAE,EAAE,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,CAAC,MA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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { Logger } from '@command-code/shared';
4
+ import { greetCommand } from './commands/greet.js';
5
+ import { infoCommand } from './commands/info.js';
6
+ import { configCommand } from './commands/config.js';
7
+ const logger = new Logger('CommandCode');
8
+ const program = new Command();
9
+ program
10
+ .name('command-code')
11
+ .description('A TypeScript CLI with Commander.js')
12
+ .version('1.0.0');
13
+ program.addCommand(greetCommand);
14
+ program.addCommand(infoCommand);
15
+ program.addCommand(configCommand);
16
+ program.hook('preAction', () => {
17
+ logger.debug('Command starting...');
18
+ });
19
+ program.hook('postAction', () => {
20
+ logger.debug('Command completed.');
21
+ });
22
+ program.parse();
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,CAAC;AACzC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,cAAc,CAAC;KACpB,WAAW,CAAC,oCAAoC,CAAC;KACjD,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAElC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;IAC7B,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "command-code",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "command-code": "./dist/index.js",
9
+ "cmd": "./dist/index.js",
10
+ "cmnd": "./dist/index.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "dev": "tsx src/index.ts",
15
+ "typecheck": "tsc --noEmit",
16
+ "start": "node dist/index.js"
17
+ },
18
+ "keywords": [],
19
+ "author": "Ahmad Awais <me@AhmadAwais.com> (https://twitter.com/MrAhmadAwais)",
20
+ "license": "UNLICENSED",
21
+ "packageManager": "pnpm@10.8.1",
22
+ "dependencies": {
23
+ "@command-code/shared": "workspace:^",
24
+ "commander": "^14.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^24.2.0",
28
+ "tsx": "^4.20.3"
29
+ }
30
+ }
@@ -0,0 +1,82 @@
1
+ import { Command } from 'commander';
2
+ import { Logger, parseJSON } from '@command-code/shared';
3
+ import * as fs from 'fs/promises';
4
+ import * as path from 'path';
5
+ import * as os from 'os';
6
+
7
+ const logger = new Logger('Config');
8
+ const configPath = path.join(os.homedir(), '.command-code-config.json');
9
+
10
+ interface Config {
11
+ [key: string]: any;
12
+ }
13
+
14
+ async function loadConfig(): Promise<Config> {
15
+ try {
16
+ const data = await fs.readFile(configPath, 'utf-8');
17
+ return parseJSON<Config>(data) || {};
18
+ } catch {
19
+ return {};
20
+ }
21
+ }
22
+
23
+ async function saveConfig(config: Config): Promise<void> {
24
+ await fs.writeFile(configPath, JSON.stringify(config, null, 2));
25
+ }
26
+
27
+ export const configCommand = new Command('config')
28
+ .description('Manage CLI configuration')
29
+ .addCommand(
30
+ new Command('get')
31
+ .description('Get a configuration value')
32
+ .argument('<key>', 'Configuration key')
33
+ .action(async (key: string) => {
34
+ const config = await loadConfig();
35
+ const value = config[key];
36
+
37
+ if (value !== undefined) {
38
+ logger.info(`${key}: ${JSON.stringify(value)}`);
39
+ } else {
40
+ logger.warn(`Key "${key}" not found in configuration`);
41
+ }
42
+ })
43
+ )
44
+ .addCommand(
45
+ new Command('set')
46
+ .description('Set a configuration value')
47
+ .argument('<key>', 'Configuration key')
48
+ .argument('<value>', 'Configuration value')
49
+ .action(async (key: string, value: string) => {
50
+ const config = await loadConfig();
51
+
52
+ let parsedValue: any = value;
53
+ if (value === 'true') parsedValue = true;
54
+ else if (value === 'false') parsedValue = false;
55
+ else if (!isNaN(Number(value))) parsedValue = Number(value);
56
+
57
+ config[key] = parsedValue;
58
+ await saveConfig(config);
59
+
60
+ logger.success(`Set ${key} = ${JSON.stringify(parsedValue)}`);
61
+ })
62
+ )
63
+ .addCommand(
64
+ new Command('list').description('List all configuration values').action(async () => {
65
+ const config = await loadConfig();
66
+
67
+ if (Object.keys(config).length === 0) {
68
+ logger.info('No configuration values set');
69
+ } else {
70
+ logger.info('Current configuration:');
71
+ Object.entries(config).forEach(([key, value]) => {
72
+ console.log(` ${key}: ${JSON.stringify(value)}`);
73
+ });
74
+ }
75
+ })
76
+ )
77
+ .addCommand(
78
+ new Command('reset').description('Reset all configuration').action(async () => {
79
+ await saveConfig({});
80
+ logger.success('Configuration reset successfully');
81
+ })
82
+ );
@@ -0,0 +1,25 @@
1
+ import { Command } from 'commander';
2
+ import { Logger, capitalize } from '@command-code/shared';
3
+
4
+ const logger = new Logger('Greet');
5
+
6
+ export const greetCommand = new Command('greet')
7
+ .description('Greet a user')
8
+ .argument('[name]', 'Name to greet', 'World')
9
+ .option('-u, --uppercase', 'Convert to uppercase')
10
+ .option('-e, --excited', 'Add excitement')
11
+ .action((name: string, options: { uppercase?: boolean; excited?: boolean }) => {
12
+ let greeting = `Hello, ${capitalize(name)}`;
13
+
14
+ if (options.uppercase) {
15
+ greeting = greeting.toUpperCase();
16
+ }
17
+
18
+ if (options.excited) {
19
+ greeting += '!!!';
20
+ } else {
21
+ greeting += '!';
22
+ }
23
+
24
+ logger.success(greeting);
25
+ });
@@ -0,0 +1,42 @@
1
+ import { Command } from 'commander';
2
+ import { Logger, formatDate } from '@command-code/shared';
3
+ import * as os from 'os';
4
+ import * as path from 'path';
5
+
6
+ const logger = new Logger('Info');
7
+
8
+ export const infoCommand = new Command('info')
9
+ .description('Display system information')
10
+ .option('-v, --verbose', 'Show verbose output')
11
+ .action((options: { verbose?: boolean }) => {
12
+ logger.info('System Information:');
13
+ console.log('-------------------');
14
+ console.log(`📅 Date: ${formatDate()}`);
15
+ console.log(`💻 Platform: ${os.platform()}`);
16
+ console.log(`🏗️ Architecture: ${os.arch()}`);
17
+ console.log(`🧮 CPUs: ${os.cpus().length}`);
18
+ console.log(`💾 Memory: ${Math.round(os.totalmem() / 1024 / 1024 / 1024)} GB`);
19
+ console.log(`📁 Home Directory: ${os.homedir()}`);
20
+
21
+ if (options.verbose) {
22
+ console.log('\nDetailed CPU Information:');
23
+ os.cpus().forEach((cpu, index) => {
24
+ console.log(` CPU ${index}: ${cpu.model} @ ${cpu.speed} MHz`);
25
+ });
26
+
27
+ console.log('\nNetwork Interfaces:');
28
+ const networkInterfaces = os.networkInterfaces();
29
+ Object.keys(networkInterfaces).forEach((iface) => {
30
+ const addresses = networkInterfaces[iface];
31
+ if (addresses) {
32
+ addresses.forEach((addr) => {
33
+ if (addr.family === 'IPv4' && !addr.internal) {
34
+ console.log(` ${iface}: ${addr.address}`);
35
+ }
36
+ });
37
+ }
38
+ });
39
+ }
40
+
41
+ logger.success('Information displayed successfully!');
42
+ });
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { Logger } from '@command-code/shared';
5
+ import { greetCommand } from './commands/greet.js';
6
+ import { infoCommand } from './commands/info.js';
7
+ import { configCommand } from './commands/config.js';
8
+
9
+ const logger = new Logger('CommandCode');
10
+ const program = new Command();
11
+
12
+ program.name('command-code').description('A TypeScript CLI with Commander.js').version('1.0.0');
13
+
14
+ program.addCommand(greetCommand);
15
+ program.addCommand(infoCommand);
16
+ program.addCommand(configCommand);
17
+
18
+ program.hook('preAction', () => {
19
+ logger.debug('Command starting...');
20
+ });
21
+
22
+ program.hook('postAction', () => {
23
+ logger.debug('Command completed.');
24
+ });
25
+
26
+ program.parse();
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist",
6
+ "composite": true
7
+ },
8
+ "include": ["src/**/*"],
9
+ "exclude": ["node_modules", "dist"],
10
+ "references": [{ "path": "../shared" }]
11
+ }