parent
0ed4ca9cab
commit
8f8a16d025
@ -8,9 +8,10 @@ releases:
|
||||
changes:
|
||||
- port the Perl changelord to JavaScript.
|
||||
change_types:
|
||||
- title: ''
|
||||
- title: ""
|
||||
level: minor
|
||||
keywords: ['']
|
||||
keywords:
|
||||
- ""
|
||||
- title: Features
|
||||
level: minor
|
||||
keywords:
|
||||
|
17
_templates/command/new/command.ejs.t
Normal file
17
_templates/command/new/command.ejs.t
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
to: src/command/<%= name %>.js
|
||||
---
|
||||
|
||||
const handler = async (config) => {
|
||||
// DO SOMETHING
|
||||
};
|
||||
|
||||
export default {
|
||||
command: '<%= name %>',
|
||||
desc : 'TODO',
|
||||
builder: (yargs) => {
|
||||
yargs
|
||||
},
|
||||
handler,
|
||||
}
|
||||
|
5
_templates/generator/help/index.ejs.t
Normal file
5
_templates/generator/help/index.ejs.t
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
message: |
|
||||
hygen {bold generator new} --name [NAME] --action [ACTION]
|
||||
hygen {bold generator with-prompt} --name [NAME] --action [ACTION]
|
||||
---
|
18
_templates/generator/new/hello.ejs.t
Normal file
18
_templates/generator/new/hello.ejs.t
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
|
||||
---
|
||||
---
|
||||
to: app/hello.js
|
||||
---
|
||||
const hello = ```
|
||||
Hello!
|
||||
This is your first hygen template.
|
||||
|
||||
Learn what it can do here:
|
||||
|
||||
https://github.com/jondot/hygen
|
||||
```
|
||||
|
||||
console.log(hello)
|
||||
|
||||
|
18
_templates/generator/with-prompt/hello.ejs.t
Normal file
18
_templates/generator/with-prompt/hello.ejs.t
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t
|
||||
---
|
||||
---
|
||||
to: app/hello.js
|
||||
---
|
||||
const hello = ```
|
||||
Hello!
|
||||
This is your first prompt based hygen template.
|
||||
|
||||
Learn what it can do here:
|
||||
|
||||
https://github.com/jondot/hygen
|
||||
```
|
||||
|
||||
console.log(hello)
|
||||
|
||||
|
14
_templates/generator/with-prompt/prompt.ejs.t
Normal file
14
_templates/generator/with-prompt/prompt.ejs.t
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js
|
||||
---
|
||||
|
||||
// see types of prompts:
|
||||
// https://github.com/enquirer/enquirer/tree/master/examples
|
||||
//
|
||||
module.exports = [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'message',
|
||||
message: "What's your message?"
|
||||
}
|
||||
]
|
4
_templates/init/repo/new-repo.ejs.t
Normal file
4
_templates/init/repo/new-repo.ejs.t
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
setup: <%= name %>
|
||||
force: true # this is because mostly, people init into existing folders is safe
|
||||
---
|
@ -16,6 +16,7 @@
|
||||
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca/)",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@yanick/updeep-remeda": "^2.2.0",
|
||||
"consola": "^3.1.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"markdown-utils": "^1.0.0",
|
||||
|
@ -1,29 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import yargs from 'yargs';
|
||||
import { join } from 'path';
|
||||
import yaml from 'yaml';
|
||||
import fs from 'fs-extra';
|
||||
import { hideBin } from "yargs/helpers";
|
||||
import yargs from "yargs";
|
||||
import { join } from "path";
|
||||
import yaml from "yaml";
|
||||
import fs from "fs-extra";
|
||||
import consola from "consola";
|
||||
|
||||
import print from './command/print.js'
|
||||
import init from './command/init.js'
|
||||
import schema from './command/schema.js';
|
||||
import consola from 'consola';
|
||||
import print from "./command/print.js";
|
||||
import init from "./command/init.js";
|
||||
import schema from "./command/schema.js";
|
||||
import add from "./command/add.js";
|
||||
|
||||
consola.raw = (...args) => console.log(...args);
|
||||
|
||||
|
||||
yargs(hideBin(process.argv))
|
||||
.config({
|
||||
consola,
|
||||
})
|
||||
.default('source', join( process.cwd(), 'CHANGELOG.yml' ))
|
||||
.describe('source', 'changelog source')
|
||||
.default("source", join(process.cwd(), "CHANGELOG.yml"))
|
||||
.describe("source", "changelog source")
|
||||
.command({
|
||||
...print,
|
||||
command: '$0',
|
||||
command: "$0",
|
||||
})
|
||||
.command(init)
|
||||
.command(add)
|
||||
.command(schema)
|
||||
.command(print).help().parse();
|
||||
.command(print)
|
||||
.help()
|
||||
.parse();
|
||||
|
51
src/command/add.js
Normal file
51
src/command/add.js
Normal file
@ -0,0 +1,51 @@
|
||||
import fs from "fs-extra";
|
||||
import yaml from "yaml";
|
||||
import u from "@yanick/updeep-remeda";
|
||||
|
||||
const handler = async (config) => {
|
||||
if (!config.change)
|
||||
throw new Error("can't add a change without a description");
|
||||
|
||||
const entry = {
|
||||
desc: config.change.join(" "),
|
||||
};
|
||||
|
||||
if (config.ticket) entry.ticket = config.ticket;
|
||||
if (config.type) entry.type = config.type;
|
||||
|
||||
config.consola.start(`adding '${entry.desc}' to the changelog`);
|
||||
|
||||
config.add_to_next(entry);
|
||||
|
||||
config.consola.success("done!");
|
||||
};
|
||||
|
||||
export default {
|
||||
command: "add [change...]",
|
||||
desc: "add a change to the NEXT release",
|
||||
builder: (yargs) => {
|
||||
yargs
|
||||
.string("ticket")
|
||||
.string("type")
|
||||
.middleware((argv) => {
|
||||
argv.add_to_next = async (entry) => {
|
||||
const changelog = yaml.parse(await fs.readFile(argv.source, "utf-8"));
|
||||
|
||||
let next = changelog.releases.find(u.matches({ version: "NEXT" }));
|
||||
if (!next) {
|
||||
next = { version: "NEXT", changes: [] };
|
||||
changelog.releases.unshift(next);
|
||||
}
|
||||
|
||||
if (Object.keys(entry).length === 1) {
|
||||
entry = entry.desc;
|
||||
}
|
||||
|
||||
next.changes.push(entry);
|
||||
|
||||
return fs.writeFile(argv.source, yaml.stringify(changelog));
|
||||
};
|
||||
});
|
||||
},
|
||||
handler,
|
||||
};
|
Loading…
Reference in New Issue
Block a user