Skip to content

Commit

Permalink
add a cjs cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed May 18, 2023
1 parent f7e4251 commit 7e03d46
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .xo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"import/order": "off",
"max-nested-callbacks": "off"
}
},
{
"files": "bin/bin.cjs",
"rules": {
"unicorn/prefer-top-level-await": "off"
}
}
]
}
4 changes: 4 additions & 0 deletions bin/bin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
(async function () {
await import('../dist/cli/index.js');
})();
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.js",
"import": "./dist/index.js"
},
"./cli/*": "./dist/cli/*.js",
"./lib/*": "./dist/*.js",
"./lib/util/*": "./dist/util/*.js",
"./package.json": "./package.json",
"./cli": "./dist/cli/index.js"
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"types": "./dist/index.d.js",
"bin": {
"yoe": "dist/cli/index.js"
"yoe": "bin/bin.cjs"
},
"files": [
"bin",
"dist"
],
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions src/cli/index.js → src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env node
import { readFileSync } from 'node:fs';
import process from 'node:process';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import YeomanCommand, { addEnvironmentOptions } from '../util/command.js';
import packageJson from '../package.json';
import { createEnv } from '../index.js';
import { printGroupedGenerator, environmentAction } from './utils.js';

const program = new YeomanCommand();

const packageJson = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json')).toString());

program.version(packageJson.version).allowExcessArguments(false).enablePositionalOptions();

addEnvironmentOptions(
Expand All @@ -27,7 +30,7 @@ program
.action(async () => {
const env = createEnv();
const generators = await env.lookup();
printGroupedGenerator(generators, env);
printGroupedGenerator(generators);
});

program
Expand All @@ -36,12 +39,13 @@ program
.action(async () => {
const env = createEnv();
await env.lookup();
printGroupedGenerator(Object.values(env.getGeneratorsMeta()), env);
printGroupedGenerator(Object.values(env.getGeneratorsMeta()));
});

try {
await program.parseAsync(process.argv);
} catch (error) {
console.log(error);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

/* Emit */
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
"declaration": false,
"sourceMap": true,
"allowJs": true,
"declaration": true,
"sourceMap": false,

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

0 comments on commit 7e03d46

Please sign in to comment.