-
Notifications
You must be signed in to change notification settings - Fork 1
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
20 changed files
with
226 additions
and
8 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
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,11 @@ | ||
/** | ||
* @type {import('gogen').Generator} | ||
*/ | ||
module.exports = async ({src, dest, pipeline, modify}, {name, argv}) => { | ||
const {_, ...args} = argv | ||
await pipeline( | ||
src('template/**'), | ||
modify.json(/data/, (_, x) => ({...x, name, args})), | ||
dest() | ||
) | ||
} |
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,5 @@ | ||
## Development | ||
|
||
``` | ||
npx cli-create <directory> | ||
``` |
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,17 @@ | ||
#!/usr/bin/env node | ||
|
||
const {create, minimist} = require('gogen') | ||
|
||
const run = async () => { | ||
const argv = minimist([__dirname, ...process.argv.slice(2)], { | ||
alias: {h: 'help'}, | ||
boolean: ['help', 'install'], | ||
}) | ||
if (argv.help || argv._.length < 2) { | ||
console.info(`Usage: npx cli-create <directory>`) | ||
return | ||
} | ||
await create(argv) | ||
} | ||
|
||
run().catch(console.error) |
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,12 @@ | ||
{ | ||
"name": "cli-create", | ||
"private": true, | ||
"version": "2.1.0", | ||
"bin": "cli.js", | ||
"scripts": { | ||
"gen": "rm -rf dist && npx cli-create dist" | ||
}, | ||
"dependencies": { | ||
"gogen": "^2.1.0" | ||
} | ||
} |
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 @@ | ||
{} |
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,6 @@ | ||
{ | ||
"name": "mylib", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT" | ||
} |
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,53 @@ | ||
const path = require('path') | ||
const fs = require('fs').promises | ||
const {exec} = require('child_process') | ||
const {promisify} = require('util') | ||
const {mock} = require('gogen') | ||
|
||
const command = promisify(exec) | ||
const resolveDir = path.resolve.bind(null, __dirname) | ||
const cli = resolveDir('cli.js') | ||
const outdir = resolveDir('dist') | ||
const readJson = async (file) => | ||
JSON.parse(await fs.readFile(resolveDir(outdir, file))) | ||
|
||
beforeEach(async () => { | ||
fs.rm | ||
? await fs.rm(outdir, {recursive: true, force: true}) | ||
: // remove in Node v14 | ||
await fs.rmdir(outdir, {recursive: true}).catch(() => {}) | ||
}) | ||
|
||
test('basic', async () => { | ||
const {files, readFile} = await mock(__dirname, 'mylib') | ||
expect(files).toMatchInlineSnapshot(` | ||
Array [ | ||
"data.json", | ||
"package.json", | ||
] | ||
`) | ||
}) | ||
|
||
test('cli args - help', async () => { | ||
const r = await command(`${cli} ${outdir} -h`) | ||
expect(r.stdout).toMatch(/Usage:/) | ||
expect((await command(`${cli}`)).stdout).toMatch(/Usage:/) | ||
}) | ||
|
||
test('cli args - post', async () => { | ||
await command(`${cli} ${outdir} --no-install`) | ||
expect((await readJson('data.json')).args).toMatchInlineSnapshot(` | ||
Object { | ||
"install": false, | ||
} | ||
`) | ||
}) | ||
|
||
test('cli args - pre', async () => { | ||
await command(`${cli} --no-install ${outdir}`) | ||
expect((await readJson('data.json')).args).toMatchInlineSnapshot(` | ||
Object { | ||
"install": false, | ||
} | ||
`) | ||
}) |
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,11 @@ | ||
/** | ||
* @type {import('gogen').Generator} | ||
*/ | ||
module.exports = async ({src, dest, pipeline, modify}, {name, argv}) => { | ||
const {_, ...args} = argv | ||
await pipeline( | ||
src('template/**'), | ||
modify.json(/data/, (_, x) => ({...x, name, args})), | ||
dest() | ||
) | ||
} |
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,5 @@ | ||
## Development | ||
|
||
``` | ||
npx cli-run <directory> | ||
``` |
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,7 @@ | ||
#!/usr/bin/env node | ||
|
||
const {run} = require('gogen') | ||
|
||
run([__dirname, ...process.argv.slice(2)], 'Usage: npx cli-run <directory>', { | ||
boolean: ['install'], | ||
}) |
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,12 @@ | ||
{ | ||
"name": "cli-run", | ||
"private": true, | ||
"version": "2.1.0", | ||
"bin": "cli.js", | ||
"scripts": { | ||
"gen": "rm -rf dist && npx cli-run dist" | ||
}, | ||
"dependencies": { | ||
"gogen": "^2.1.0" | ||
} | ||
} |
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 @@ | ||
{} |
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,6 @@ | ||
{ | ||
"name": "mylib", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT" | ||
} |
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,47 @@ | ||
const path = require('path') | ||
const fs = require('fs').promises | ||
const {exec} = require('child_process') | ||
const {promisify} = require('util') | ||
const {mock} = require('gogen') | ||
|
||
const command = promisify(exec) | ||
const resolveDir = path.resolve.bind(null, __dirname) | ||
const cli = resolveDir('cli.js') | ||
const outdir = resolveDir('dist') | ||
const readJson = async (file) => | ||
JSON.parse(await fs.readFile(resolveDir(outdir, file))) | ||
|
||
beforeEach(async () => { | ||
fs.rm | ||
? await fs.rm(outdir, {recursive: true, force: true}) | ||
: // remove in Node v14 | ||
await fs.rmdir(outdir, {recursive: true}).catch(() => {}) | ||
}) | ||
|
||
test('basic', async () => { | ||
const {files, readFile} = await mock(__dirname, 'mylib') | ||
expect(files).toMatchInlineSnapshot(` | ||
Array [ | ||
"data.json", | ||
"package.json", | ||
] | ||
`) | ||
}) | ||
|
||
test('cli args - post', async () => { | ||
await command(`${cli} ${outdir} --no-install`) | ||
expect((await readJson('data.json')).args).toMatchInlineSnapshot(` | ||
Object { | ||
"install": false, | ||
} | ||
`) | ||
}) | ||
|
||
test('cli args - pre', async () => { | ||
await command(`${cli} --no-install ${outdir}`) | ||
expect((await readJson('data.json')).args).toMatchInlineSnapshot(` | ||
Object { | ||
"install": false, | ||
} | ||
`) | ||
}) |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "test-basic", | ||
"name": "change-context", | ||
"private": true, | ||
"version": "0.0.0", | ||
"dependencies": {} | ||
|
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,5 +1,5 @@ | ||
{ | ||
"name": "test-basic", | ||
"name": "change-dest", | ||
"private": true, | ||
"version": "0.0.0", | ||
"dependencies": {} | ||
|
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