Skip to content

Commit 7e03d46

Browse files
committed
add a cjs cli
1 parent f7e4251 commit 7e03d46

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

.xo-config.json

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"import/order": "off",
2626
"max-nested-callbacks": "off"
2727
}
28+
},
29+
{
30+
"files": "bin/bin.cjs",
31+
"rules": {
32+
"unicorn/prefer-top-level-await": "off"
33+
}
2834
}
2935
]
3036
}

bin/bin.cjs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
(async function () {
3+
await import('../dist/cli/index.js');
4+
})();

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@
2222
"type": "module",
2323
"exports": {
2424
".": {
25+
"types": "./dist/index.d.js",
2526
"import": "./dist/index.js"
2627
},
27-
"./cli/*": "./dist/cli/*.js",
28-
"./lib/*": "./dist/*.js",
29-
"./lib/util/*": "./dist/util/*.js",
30-
"./package.json": "./package.json",
31-
"./cli": "./dist/cli/index.js"
28+
"./package.json": "./package.json"
3229
},
3330
"main": "./dist/index.js",
31+
"types": "./dist/index.d.js",
3432
"bin": {
35-
"yoe": "dist/cli/index.js"
33+
"yoe": "bin/bin.cjs"
3634
},
3735
"files": [
36+
"bin",
3837
"dist"
3938
],
4039
"scripts": {

src/cli/index.js src/cli/index.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
#!/usr/bin/env node
1+
import { readFileSync } from 'node:fs';
22
import process from 'node:process';
3+
import { dirname, resolve } from 'node:path';
4+
import { fileURLToPath } from 'node:url';
35
import YeomanCommand, { addEnvironmentOptions } from '../util/command.js';
4-
import packageJson from '../package.json';
56
import { createEnv } from '../index.js';
67
import { printGroupedGenerator, environmentAction } from './utils.js';
78

89
const program = new YeomanCommand();
910

11+
const packageJson = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json')).toString());
12+
1013
program.version(packageJson.version).allowExcessArguments(false).enablePositionalOptions();
1114

1215
addEnvironmentOptions(
@@ -27,7 +30,7 @@ program
2730
.action(async () => {
2831
const env = createEnv();
2932
const generators = await env.lookup();
30-
printGroupedGenerator(generators, env);
33+
printGroupedGenerator(generators);
3134
});
3235

3336
program
@@ -36,12 +39,13 @@ program
3639
.action(async () => {
3740
const env = createEnv();
3841
await env.lookup();
39-
printGroupedGenerator(Object.values(env.getGeneratorsMeta()), env);
42+
printGroupedGenerator(Object.values(env.getGeneratorsMeta()));
4043
});
4144

4245
try {
4346
await program.parseAsync(process.argv);
4447
} catch (error) {
4548
console.log(error);
49+
// eslint-disable-next-line unicorn/no-process-exit
4650
process.exit(1);
4751
}

tsconfig.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
/* Emit */
1414
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
15-
"declaration": false,
16-
"sourceMap": true,
17-
"allowJs": true,
15+
"declaration": true,
16+
"sourceMap": false,
1817

1918
/* Interop Constraints */
2019
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

0 commit comments

Comments
 (0)