Skip to content

Commit 69f7b5b

Browse files
committed
feat!: generi programatically commands
1 parent d9dfa76 commit 69f7b5b

File tree

6 files changed

+73
-3
lines changed

6 files changed

+73
-3
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ Revert `generi log` last command
5858

5959
Monorepo versions may depend on external tools. Given this, Generi supports lerna workspaces, using the command `lerna version` before creating the changelog. In other setups, we recommend disabling the `tag` and `version` options.
6060

61+
### Code
62+
63+
Use generi in .js|.ts files programatically
64+
65+
```ts
66+
import * as generi from 'generi/code.js'
67+
68+
generi.init().then(async () => {
69+
await generi.log('patch')
70+
71+
// code here
72+
})
73+
```
74+
6175
### generi.json
6276

6377
##### `silent` Default: `false`

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
],
3535
"scripts": {
3636
"dev": "pnpm build && node .",
37-
"build": "tsup src/index.ts --minify --clean",
38-
"build:watch": "tsup src/index.ts --minify --clean --watch",
37+
"build": "tsup",
38+
"build:watch": "tsup --watch",
3939
"test": "vitest run --coverage",
4040
"test:dev": "vitest",
4141
"format": "prettier --write src/ tests/",

src/code/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { Awaitable, GitLogOptions, GitNewTag } from '../types';
2+
3+
import * as _log from '../commands/log';
4+
import * as _init from '../commands/init';
5+
import * as _revert from '../commands/revert';
6+
7+
export const log = (tag: GitNewTag, git: GitLogOptions = {}): Awaitable<void> => {
8+
return new Promise(async (res, rej) => {
9+
try {
10+
await _log.setup(tag, { header: true, git });
11+
12+
res();
13+
} catch (e) {
14+
rej(e);
15+
}
16+
});
17+
};
18+
19+
export const init = (tag: GitNewTag, git: GitLogOptions = {}): Awaitable<void> => {
20+
return new Promise(async (res, rej) => {
21+
try {
22+
await _init.setup();
23+
24+
res();
25+
} catch (e) {
26+
rej(e);
27+
}
28+
});
29+
};
30+
31+
export const revert = (tag: GitNewTag, git: GitLogOptions = {}): Awaitable<void> => {
32+
return new Promise(async (res, rej) => {
33+
try {
34+
await _revert.setup();
35+
36+
res();
37+
} catch (e) {
38+
rej(e);
39+
}
40+
});
41+
};
42+
43+
export * from '../types';

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sade from 'sade';
44

5-
import { GitLogOptions, GitNewTag } from './types';
5+
import type { GitLogOptions, GitNewTag } from './types';
66

77
import * as init from './commands/init';
88
import * as log from './commands/log';

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type Maybe<T> = T | undefined | null | false;
2+
export type Awaitable<T = void> = T | Promise<T>;
23

34
export interface Commit {
45
sha: string;

tsup.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig({
4+
entry: {
5+
index: 'src/index.ts',
6+
code: 'src/code/index.ts',
7+
},
8+
target: ['node18'],
9+
minify: true,
10+
clean: true,
11+
dts: true
12+
});

0 commit comments

Comments
 (0)