create-yaebal 0.0.0-test → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/bin/cli.mjs +3 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +157 -0
- package/lib/index.js.map +1 -0
- package/lib/index.test.d.ts +2 -0
- package/lib/index.test.d.ts.map +1 -0
- package/lib/index.test.js +29 -0
- package/lib/index.test.js.map +1 -0
- package/package.json +38 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 neverlane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# create-yaebal
|
|
2
|
+
|
|
3
|
+
scaffold a new yaebal bot project interactively or from flags — generates `package.json`, `tsconfig.json`, `src/index.ts`, `.env.example`, and `.gitignore`.
|
|
4
|
+
|
|
5
|
+
## install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm create yaebal
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## usage
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
# interactive
|
|
15
|
+
pnpm create yaebal
|
|
16
|
+
|
|
17
|
+
# non-interactive
|
|
18
|
+
pnpm create yaebal my-bot --runtime bun --plugins session,again
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
supported runtimes: `node` (default), `bun`, `deno`.
|
|
22
|
+
supported plugins: `session` (`@yaebal/session`), `ratelimiter` (`@yaebal/ratelimiter`), `again` (`@yaebal/again`).
|
|
23
|
+
|
|
24
|
+
after scaffolding:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
cd my-bot
|
|
28
|
+
pnpm install
|
|
29
|
+
cp .env.example .env # add your BOT_TOKEN
|
|
30
|
+
pnpm dev
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
part of [**yaebal**](https://github.com/neverlane/yaebal) — a type-safe, runtime-agnostic Telegram Bot API framework. MIT.
|
package/bin/cli.mjs
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Runtime = "node" | "bun" | "deno";
|
|
2
|
+
export interface ScaffoldOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
runtime: Runtime;
|
|
5
|
+
plugins: string[];
|
|
6
|
+
}
|
|
7
|
+
/** pure: turn options into a map of relative path → file content. */
|
|
8
|
+
export declare function renderFiles(opts: ScaffoldOptions): Record<string, string>;
|
|
9
|
+
interface Args {
|
|
10
|
+
name?: string;
|
|
11
|
+
runtime?: string;
|
|
12
|
+
plugins?: string;
|
|
13
|
+
}
|
|
14
|
+
/** pure: parse argv into name + flags. supports `<name> --runtime x --plugins a,b`. */
|
|
15
|
+
export declare function parseArgs(argv: string[]): Args;
|
|
16
|
+
export declare function main(): Promise<void>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AA6B9C,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAcD,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA+DzE;AAID,UAAU,IAAI;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,uFAAuF;AACvF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAY9C;AAED,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA+D1C"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
const CATALOG = {
|
|
7
|
+
session: {
|
|
8
|
+
dep: "@yaebal/session",
|
|
9
|
+
import: 'import { session } from "@yaebal/session";',
|
|
10
|
+
install: "session({ initial: () => ({ seen: 0 }) })",
|
|
11
|
+
},
|
|
12
|
+
ratelimiter: {
|
|
13
|
+
dep: "@yaebal/ratelimiter",
|
|
14
|
+
import: 'import { ratelimiter } from "@yaebal/ratelimiter";',
|
|
15
|
+
install: "ratelimiter()",
|
|
16
|
+
},
|
|
17
|
+
again: {
|
|
18
|
+
dep: "@yaebal/again",
|
|
19
|
+
import: 'import { autoRetry } from "@yaebal/again";',
|
|
20
|
+
setup: "autoRetry(bot.api);",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const SCRIPTS = {
|
|
24
|
+
node: {
|
|
25
|
+
dev: "node --watch --experimental-strip-types src/index.ts",
|
|
26
|
+
start: "node --experimental-strip-types src/index.ts",
|
|
27
|
+
},
|
|
28
|
+
bun: { dev: "bun --watch src/index.ts", start: "bun src/index.ts" },
|
|
29
|
+
deno: {
|
|
30
|
+
dev: "deno run --watch --allow-net --allow-env src/index.ts",
|
|
31
|
+
start: "deno run --allow-net --allow-env src/index.ts",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
/** pure: turn options into a map of relative path → file content. */
|
|
35
|
+
export function renderFiles(opts) {
|
|
36
|
+
const chosen = opts.plugins.filter((p) => p in CATALOG);
|
|
37
|
+
const imports = [
|
|
38
|
+
'import { Bot } from "@yaebal/core";',
|
|
39
|
+
...chosen.map((p) => CATALOG[p]?.import ?? ""),
|
|
40
|
+
]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join("\n");
|
|
43
|
+
const installs = chosen.map((p) => CATALOG[p]?.install).filter((x) => Boolean(x));
|
|
44
|
+
const setups = chosen.map((p) => CATALOG[p]?.setup).filter((x) => Boolean(x));
|
|
45
|
+
const botDecl = installs.length
|
|
46
|
+
? `const bot = new Bot(process.env.BOT_TOKEN ?? "")\n${installs.map((s) => `\t.install(${s})`).join("\n")};`
|
|
47
|
+
: `const bot = new Bot(process.env.BOT_TOKEN ?? "");`;
|
|
48
|
+
const index = `${imports}\n\n${botDecl}\n${setups.length ? `\n${setups.join("\n")}\n` : ""}
|
|
49
|
+
bot.command("start", (ctx) => ctx.reply("hello from yaebal 👋"));
|
|
50
|
+
|
|
51
|
+
bot.on("message:text", (ctx) => ctx.reply(ctx.text));
|
|
52
|
+
|
|
53
|
+
bot.start();
|
|
54
|
+
console.log("bot running");
|
|
55
|
+
`;
|
|
56
|
+
const deps = { "@yaebal/core": "latest" };
|
|
57
|
+
for (const p of chosen) {
|
|
58
|
+
const dep = CATALOG[p]?.dep;
|
|
59
|
+
if (dep)
|
|
60
|
+
deps[dep] = "latest";
|
|
61
|
+
}
|
|
62
|
+
const pkg = {
|
|
63
|
+
name: opts.name,
|
|
64
|
+
version: "0.0.0",
|
|
65
|
+
private: true,
|
|
66
|
+
type: "module",
|
|
67
|
+
scripts: SCRIPTS[opts.runtime],
|
|
68
|
+
dependencies: deps,
|
|
69
|
+
devDependencies: { "@types/node": "^22.0.0", typescript: "^5.7.0" },
|
|
70
|
+
};
|
|
71
|
+
const tsconfig = {
|
|
72
|
+
compilerOptions: {
|
|
73
|
+
target: "ES2022",
|
|
74
|
+
module: "NodeNext",
|
|
75
|
+
moduleResolution: "NodeNext",
|
|
76
|
+
strict: true,
|
|
77
|
+
noUncheckedIndexedAccess: true,
|
|
78
|
+
verbatimModuleSyntax: true,
|
|
79
|
+
skipLibCheck: true,
|
|
80
|
+
outDir: "lib",
|
|
81
|
+
},
|
|
82
|
+
include: ["src"],
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
"package.json": `${JSON.stringify(pkg, null, 2)}\n`,
|
|
86
|
+
"tsconfig.json": `${JSON.stringify(tsconfig, null, 2)}\n`,
|
|
87
|
+
"src/index.ts": index,
|
|
88
|
+
".env.example": "BOT_TOKEN=\n",
|
|
89
|
+
".gitignore": "node_modules\nlib\n.env\n",
|
|
90
|
+
"README.md": `# ${opts.name}\n\na telegram bot built with [yaebal](https://github.com/neverlane/yaebal).\n\n\`\`\`sh\n# 1. put your token in .env\ncp .env.example .env\n\n# 2. run\n${opts.runtime === "deno" ? SCRIPTS.deno.dev : "pnpm dev"}\n\`\`\`\n`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const isRuntime = (v) => v === "node" || v === "bun" || v === "deno";
|
|
94
|
+
/** pure: parse argv into name + flags. supports `<name> --runtime x --plugins a,b`. */
|
|
95
|
+
export function parseArgs(argv) {
|
|
96
|
+
const out = {};
|
|
97
|
+
for (let i = 0; i < argv.length; i++) {
|
|
98
|
+
const a = argv[i];
|
|
99
|
+
if (a === "--runtime" || a === "-r")
|
|
100
|
+
out.runtime = argv[++i];
|
|
101
|
+
else if (a === "--plugins" || a === "-p")
|
|
102
|
+
out.plugins = argv[++i];
|
|
103
|
+
else if (a && !a.startsWith("-") && out.name === undefined)
|
|
104
|
+
out.name = a;
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
export async function main() {
|
|
109
|
+
const args = parseArgs(process.argv.slice(2));
|
|
110
|
+
const tty = Boolean(process.stdin.isTTY);
|
|
111
|
+
const rl = tty ? createInterface({ input: process.stdin, output: process.stdout }) : null;
|
|
112
|
+
try {
|
|
113
|
+
let name = args.name;
|
|
114
|
+
if (!name && rl)
|
|
115
|
+
name = (await rl.question("project name: ")).trim();
|
|
116
|
+
if (!name) {
|
|
117
|
+
console.error("✗ project name is required\n usage: create-yaebal <name> [--runtime node|bun|deno] [--plugins session,again]");
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let runtime = "node";
|
|
122
|
+
if (args.runtime && isRuntime(args.runtime))
|
|
123
|
+
runtime = args.runtime;
|
|
124
|
+
else if (rl) {
|
|
125
|
+
const a = (await rl.question("runtime — node / bun / deno [node]: ")).trim().toLowerCase();
|
|
126
|
+
if (isRuntime(a))
|
|
127
|
+
runtime = a;
|
|
128
|
+
}
|
|
129
|
+
let pluginsRaw = args.plugins ?? "";
|
|
130
|
+
if (args.plugins === undefined && rl) {
|
|
131
|
+
pluginsRaw = await rl.question("plugins — comma list of [session, ratelimiter, again] (enter to skip): ");
|
|
132
|
+
}
|
|
133
|
+
const plugins = pluginsRaw
|
|
134
|
+
.split(",")
|
|
135
|
+
.map((s) => s.trim())
|
|
136
|
+
.filter((p) => p in CATALOG);
|
|
137
|
+
const target = resolve(process.cwd(), name);
|
|
138
|
+
if (existsSync(target)) {
|
|
139
|
+
console.error(`✗ directory "${name}" already exists`);
|
|
140
|
+
process.exitCode = 1;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const files = renderFiles({ name, runtime, plugins });
|
|
144
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
145
|
+
const full = join(target, rel);
|
|
146
|
+
await mkdir(dirname(full), { recursive: true });
|
|
147
|
+
await writeFile(full, content);
|
|
148
|
+
}
|
|
149
|
+
const installCmd = runtime === "deno" ? "deno cache src/index.ts" : "pnpm install";
|
|
150
|
+
const runCmd = runtime === "deno" ? SCRIPTS.deno.dev : "pnpm dev";
|
|
151
|
+
console.log(`\n✓ created ${name}/\n\nnext steps:\n cd ${name}\n ${installCmd}\n # add your BOT_TOKEN to .env\n ${runCmd}\n`);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
rl?.close();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAA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C,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,cAAc,CAAC;QACnF,MAAM,MAAM,GAAG,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;QAElE,OAAO,CAAC,GAAG,CACV,eAAe,IAAI,0BAA0B,IAAI,OAAO,UAAU,uCAAuC,MAAM,IAAI,CACnH,CAAC;IACH,CAAC;YAAS,CAAC;QACV,EAAE,EAAE,KAAK,EAAE,CAAC;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { renderFiles } from "./index.js";
|
|
4
|
+
test("renderFiles: bare project has core only", () => {
|
|
5
|
+
const f = renderFiles({ name: "bot", runtime: "node", plugins: [] });
|
|
6
|
+
const pkg = JSON.parse(f["package.json"] ?? "{}");
|
|
7
|
+
assert.equal(pkg.name, "bot");
|
|
8
|
+
assert.deepEqual(Object.keys(pkg.dependencies), ["@yaebal/core"]);
|
|
9
|
+
assert.match(f["src/index.ts"] ?? "", /new Bot\(process\.env\.BOT_TOKEN/);
|
|
10
|
+
assert.doesNotMatch(f["src/index.ts"] ?? "", /\.install\(/);
|
|
11
|
+
});
|
|
12
|
+
test("renderFiles: chosen plugins add deps, imports and wiring", () => {
|
|
13
|
+
const f = renderFiles({ name: "bot", runtime: "node", plugins: ["session", "again", "bogus"] });
|
|
14
|
+
const pkg = JSON.parse(f["package.json"] ?? "{}");
|
|
15
|
+
assert.ok(pkg.dependencies["@yaebal/session"]);
|
|
16
|
+
assert.ok(pkg.dependencies["@yaebal/again"]);
|
|
17
|
+
assert.equal(pkg.dependencies.bogus, undefined); // unknown plugin ignored
|
|
18
|
+
const src = f["src/index.ts"] ?? "";
|
|
19
|
+
assert.match(src, /import \{ session \} from "@yaebal\/session";/);
|
|
20
|
+
assert.match(src, /\.install\(session\(/);
|
|
21
|
+
assert.match(src, /autoRetry\(bot\.api\);/); // `again` is a setup-style plugin
|
|
22
|
+
});
|
|
23
|
+
test("renderFiles: runtime picks the right scripts", () => {
|
|
24
|
+
const bun = JSON.parse(renderFiles({ name: "b", runtime: "bun", plugins: [] })["package.json"] ?? "{}");
|
|
25
|
+
assert.match(bun.scripts.start, /^bun /);
|
|
26
|
+
const deno = JSON.parse(renderFiles({ name: "d", runtime: "deno", plugins: [] })["package.json"] ?? "{}");
|
|
27
|
+
assert.match(deno.scripts.start, /^deno run /);
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACpD,MAAM,CAAC,GAAG,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IACrE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,CAAC;IAElD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9B,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAClE,MAAM,CAAC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,CAAC,CAAC,cAAc,CAAC,IAAI,IAAI,CAC/E,CAAC;IACF,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAEzC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CACtB,WAAW,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,IAAI,IAAI,CAChF,CAAC;IACF,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-yaebal",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "scaffold a new yaebal telegram bot.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-yaebal": "./bin/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"main": "./lib/index.js",
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib",
|
|
13
|
+
"bin"
|
|
14
|
+
],
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "latest"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"telegram",
|
|
23
|
+
"telegram-bot",
|
|
24
|
+
"yaebal",
|
|
25
|
+
"create",
|
|
26
|
+
"scaffold",
|
|
27
|
+
"cli"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/neverlane/yaebal",
|
|
33
|
+
"directory": "packages/create-yaebal"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
9
38
|
"scripts": {
|
|
10
|
-
"
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
41
|
+
"test": "node --test lib"
|
|
11
42
|
}
|
|
12
43
|
}
|