-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
1 parent
91b0f04
commit 41e628c
Showing
8 changed files
with
184 additions
and
16 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,2 +1,3 @@ | ||
node_modules | ||
build | ||
yarn.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {nodeResolve} from '@rollup/plugin-node-resolve'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import json from '@rollup/plugin-json'; | ||
import license from 'rollup-plugin-license'; | ||
import {globby} from 'globby'; | ||
import {createTag, replaceResultTransformer} from 'common-tags'; | ||
import {delete_comments as deleteComments} from 'delete_comments'; | ||
import {defineConfig} from 'rollup'; | ||
|
||
/** Matches empty lines: https://stackoverflow.com/q/16369642/10292952 */ | ||
const emptyLineRegex = /^\s*[\r\n]/gm; | ||
|
||
const stripComments = createTag( | ||
{onEndResult: deleteComments}, | ||
replaceResultTransformer(emptyLineRegex, ''), | ||
); | ||
|
||
const outputDirectory = 'build'; | ||
|
||
export default defineConfig({ | ||
input: await globby('source/**/*.js'), | ||
output: { | ||
dir: outputDirectory, | ||
interop: 'esModule', | ||
generatedCode: { | ||
preset: 'es2015', | ||
}, | ||
chunkFileNames: '[name].js', | ||
manualChunks(id) { | ||
if (id.includes('node_modules')) { | ||
return 'dependencies'; | ||
} | ||
}, | ||
hoistTransitiveImports: false, | ||
plugins: [{ | ||
name: 'strip-dependency-comments', | ||
renderChunk(code, chunk) { | ||
return chunk.name === 'dependencies' ? stripComments(code) : null; | ||
}, | ||
}], | ||
}, | ||
treeshake: { | ||
moduleSideEffects: 'no-external', | ||
}, | ||
plugins: [ | ||
nodeResolve(), | ||
commonjs({ | ||
include: 'node_modules/**', | ||
}), | ||
json(), | ||
license({ | ||
thirdParty: { | ||
output: `${outputDirectory}/licenses.md`, | ||
}, | ||
}), | ||
], | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import test from 'ava'; | ||
import {readPackage} from 'read-pkg'; | ||
import meow from '../build/index.js'; | ||
import {spawnFixture} from './_utils.js'; | ||
|
||
test('main', t => { | ||
const cli = meow(` | ||
Usage | ||
foo <input> | ||
`, { | ||
importMeta: import.meta, | ||
argv: 'foo --foo-bar --u cat -- unicorn cake'.split(' '), | ||
flags: { | ||
unicorn: { | ||
shortFlag: 'u', | ||
}, | ||
meow: { | ||
default: 'dog', | ||
}, | ||
'--': true, | ||
}, | ||
}); | ||
|
||
t.like(cli, { | ||
input: ['foo'], | ||
flags: { | ||
fooBar: true, | ||
meow: 'dog', | ||
unicorn: 'cat', | ||
'--': [ | ||
'unicorn', | ||
'cake', | ||
], | ||
}, | ||
pkg: { | ||
name: 'meow', | ||
}, | ||
help: '\n CLI app helper\n\n Usage\n foo <input>\n', | ||
}); | ||
}); | ||
|
||
test('spawn cli and show version', async t => { | ||
const pkg = await readPackage(); | ||
const {stdout} = await spawnFixture(['--version']); | ||
t.is(stdout, pkg.version); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
import process from 'node:process'; | ||
import meow from '../../build/index.js'; | ||
|
||
const cli = meow(` | ||
Usage | ||
foo <input> | ||
`, { | ||
importMeta: import.meta, | ||
description: 'Custom description', | ||
autoVersion: !process.argv.includes('--no-auto-version'), | ||
autoHelp: !process.argv.includes('--no-auto-help'), | ||
flags: { | ||
unicorn: { | ||
shortFlag: 'u', | ||
}, | ||
meow: { | ||
default: 'dog', | ||
}, | ||
camelCaseOption: { | ||
default: 'foo', | ||
}, | ||
}, | ||
}); | ||
|
||
if (cli.flags.camelCaseOption === 'foo') { | ||
for (const flagKey of Object.keys(cli.flags)) { | ||
console.log(flagKey); | ||
} | ||
} else { | ||
console.log(cli.flags.camelCaseOption); | ||
} |