-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
71 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
# @nlib/ts-to-esm | ||
# @nlib/esmify | ||
|
||
[![Test](https://github.com/nlibjs/ts-to-esm/actions/workflows/test.yml/badge.svg)](https://github.com/nlibjs/ts-to-esm/actions/workflows/test.yml) | ||
[![codecov](https://codecov.io/gh/nlibjs/ts-to-esm/branch/master/graph/badge.svg)](https://codecov.io/gh/nlibjs/ts-to-esm) | ||
[![Test](https://github.com/nlibjs/esmify/actions/workflows/test.yml/badge.svg)](https://github.com/nlibjs/esmify/actions/workflows/test.yml) | ||
[![codecov](https://codecov.io/gh/nlibjs/esmify/branch/master/graph/badge.svg)](https://codecov.io/gh/nlibjs/esmify) | ||
|
||
A command line tool to change file extensions. | ||
A command line tool converts tsc output to ESM modules. | ||
|
||
## Usage | ||
|
||
``` | ||
npx @nlib/ts-to-esm --directory path/to/dir --mapping js/cjs [--mapping mjs/js] | ||
Usage: @nlib/esmify [options] <patterns...> | ||
--directory, -d [string] A directory replaceExt processes | ||
--mapping, -m [string] Specify a mapping in the format from/to (e.g. js/mjs). | ||
--help, -h Show help | ||
--version, -v Output the version number | ||
Arguments: | ||
patterns File patterns passed to fast-glob | ||
Options: | ||
--cwd <cwd> A path to the directory passed to fast-glob. | ||
--keepSourceMap If it exists, esmify won't remove sourcemaps. | ||
-V, --version output the version number | ||
-h, --help display help for command | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env node | ||
import {Command} from 'commander'; | ||
import * as console from 'console'; | ||
import * as fs from 'fs'; | ||
|
||
/** @type {{name: string, version: string, description: string}} */ | ||
const packageJson = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); | ||
const program = new Command(); | ||
program.name(packageJson.name); | ||
program.description(packageJson.description); | ||
program.option('--cwd <cwd>', 'A path to the directory passed to fast-glob.'); | ||
program.option('--keepSourceMap', 'If it exists, esmify won\'t remove sourcemaps.'); | ||
program.argument('<patterns...>', 'File patterns passed to fast-glob'); | ||
program.version(packageJson.version); | ||
program.action( | ||
/** @param {Array<string>} patterns */ | ||
async (patterns, options) => { | ||
const extensions = ['.mjs', '.js']; | ||
while (0 < extensions.length) { | ||
const extension = extensions.shift(); | ||
const file = new URL(`../lib/esmify${extension}`, import.meta.url); | ||
const stats = await fs.promises.stat(file).catch((error) => { | ||
if (error && error.code === 'ENOENT') { | ||
return null; | ||
} | ||
throw error; | ||
}); | ||
if ((stats && stats.isFile()) || extensions.length === 0) { | ||
/** @type {{esmify: (...patterns: Array<string>) => Promise<void>}} */ | ||
const {esmify} = await import(file); | ||
await esmify(patterns, options); | ||
return; | ||
} | ||
} | ||
}, | ||
); | ||
program.parseAsync() | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters