chapterjs 0.1.4 → 0.2.0
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/dist/cli/build.js +9 -10
- package/dist/cli/dev.js +17 -16
- package/dist/cli/project.d.ts +38 -25
- package/dist/cli/project.js +199 -134
- package/dist/commands/command.d.ts +25 -11
- package/dist/commands/command.js +5 -5
- package/dist/commands/{convention.d.ts → declaration.d.ts} +24 -11
- package/dist/commands/{convention.js → declaration.js} +61 -33
- package/dist/commands/tree.d.ts +8 -4
- package/dist/commands/tree.js +16 -6
- package/dist/components/button.d.ts +13 -13
- package/dist/components/button.js +9 -11
- package/dist/components/component.d.ts +1 -1
- package/dist/components/component.js +1 -1
- package/dist/components/custom-id.d.ts +4 -4
- package/dist/components/custom-id.js +12 -12
- package/dist/components/declaration.d.ts +42 -0
- package/dist/components/{convention.js → declaration.js} +76 -73
- package/dist/components/declared.d.ts +29 -0
- package/dist/components/declared.js +49 -0
- package/dist/components/embed.d.ts +13 -12
- package/dist/components/embed.js +6 -6
- package/dist/components/instance.d.ts +3 -3
- package/dist/components/instance.js +2 -2
- package/dist/components/modal.d.ts +11 -10
- package/dist/components/modal.js +7 -8
- package/dist/components/router.d.ts +3 -2
- package/dist/components/router.js +14 -19
- package/dist/components/select.d.ts +14 -12
- package/dist/components/select.js +4 -4
- package/dist/events/declaration.d.ts +16 -0
- package/dist/events/declaration.js +80 -0
- package/dist/events/event.d.ts +42 -5
- package/dist/events/event.js +25 -11
- package/dist/events/registry.d.ts +1 -10
- package/dist/events/router.d.ts +3 -2
- package/dist/index.d.ts +11 -9
- package/dist/index.js +2 -0
- package/dist/loader/generated.d.ts +5 -32
- package/dist/loader/generated.js +21 -55
- package/dist/loader/loader.d.ts +57 -44
- package/dist/loader/loader.js +73 -89
- package/dist/main.d.ts +0 -1
- package/dist/main.js +2 -3
- package/dist/messages/commands.d.ts +3 -3
- package/dist/messages/commands.js +29 -10
- package/dist/messages/declaration.d.ts +89 -0
- package/dist/messages/declaration.js +455 -0
- package/dist/messages/messages.d.ts +65 -43
- package/dist/messages/messages.js +11 -10
- package/dist/messages/phrases.js +1 -1
- package/dist/messages/translate.d.ts +4 -4
- package/dist/messages/translate.js +4 -4
- package/dist/presence/declaration.d.ts +19 -0
- package/dist/presence/{convention.js → declaration.js} +13 -28
- package/dist/presence/presence.d.ts +7 -7
- package/dist/presence/presence.js +5 -5
- package/dist/structures/context.d.ts +1 -1
- package/dist/structures/interaction.d.ts +2 -2
- package/dist/structures/interaction.js +3 -3
- package/dist/structures/payload.d.ts +4 -4
- package/dist/structures/payload.js +4 -4
- package/dist/tasks/declaration.d.ts +16 -0
- package/dist/tasks/{convention.js → declaration.js} +14 -36
- package/dist/tasks/scheduler.d.ts +3 -1
- package/dist/tasks/scheduler.js +4 -4
- package/dist/tasks/task.d.ts +8 -9
- package/dist/tasks/task.js +6 -7
- package/package.json +1 -1
- package/dist/components/convention.d.ts +0 -35
- package/dist/components/file.d.ts +0 -30
- package/dist/components/file.js +0 -52
- package/dist/events/convention.d.ts +0 -25
- package/dist/events/convention.js +0 -97
- package/dist/events/types.d.ts +0 -7
- package/dist/events/types.js +0 -48
- package/dist/messages/convention.d.ts +0 -89
- package/dist/messages/convention.js +0 -347
- package/dist/presence/convention.d.ts +0 -26
- package/dist/tasks/convention.d.ts +0 -26
package/dist/cli/build.js
CHANGED
|
@@ -13,9 +13,9 @@ import { mkdir, readdir, readFile, rm, stat, writeFile, } from 'node:fs/promises
|
|
|
13
13
|
import { join, relative, sep } from 'node:path';
|
|
14
14
|
import { pathToFileURL } from 'node:url';
|
|
15
15
|
import { enableProjectLoader } from '../loader/hot.js';
|
|
16
|
-
import {
|
|
16
|
+
import { listSources } from '../loader/loader.js';
|
|
17
17
|
import { sourcesJoinVoice } from '../voice/usage.js';
|
|
18
|
-
import {
|
|
18
|
+
import { createProject, hasSources, writeTypes } from './project.js';
|
|
19
19
|
/** Where the build of a project is, from its folder. */
|
|
20
20
|
export const buildDir = (cwd) => join(cwd, '.chapterjs', 'build');
|
|
21
21
|
/** The file the whole bot is compiled into, in the build. */
|
|
@@ -108,10 +108,9 @@ export async function build(options) {
|
|
|
108
108
|
const sources = createProject({ cwd, version: options.version, log });
|
|
109
109
|
const failures = await sources.load();
|
|
110
110
|
// 2. Types: what the editor underlines, for the whole project. Written
|
|
111
|
-
// once the files ran, so a language
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
await writeTypes(cwd, sources.commands, sources.messages, sources.languageDefaults);
|
|
111
|
+
// once the files ran, so a language only offers the commands they do
|
|
112
|
+
// not describe; written even when a file failed, so the editor follows.
|
|
113
|
+
await writeTypes(cwd, sources.typesInfo());
|
|
115
114
|
if (failures.length > 0) {
|
|
116
115
|
for (const failure of failures)
|
|
117
116
|
sources.report(failure);
|
|
@@ -128,10 +127,10 @@ export async function build(options) {
|
|
|
128
127
|
else {
|
|
129
128
|
log.success('Types checked');
|
|
130
129
|
}
|
|
131
|
-
// 3. The whole bot in one file: every file of
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
const found =
|
|
130
|
+
// 3. The whole bot in one file: every file of src/, with what it
|
|
131
|
+
// imports. Packages stay where they are installed: the bot and the
|
|
132
|
+
// framework must share the same ones.
|
|
133
|
+
const found = await listSources(cwd);
|
|
135
134
|
const entry = [
|
|
136
135
|
...found.map(({ path }, index) => `import * as m${index} from ${JSON.stringify(path)};`),
|
|
137
136
|
`export const files = [${found
|
package/dist/cli/dev.js
CHANGED
|
@@ -9,6 +9,7 @@ import { GetGlobalApplicationCommands } from '../discord/endpoints.js';
|
|
|
9
9
|
import { EVENTS } from '../events/registry.js';
|
|
10
10
|
import { limitsFor } from '../events/router.js';
|
|
11
11
|
import { enableProjectLoader, nextGeneration } from '../loader/hot.js';
|
|
12
|
+
import { siteName } from '../loader/loader.js';
|
|
12
13
|
import { messageOf } from '../loader/locate.js';
|
|
13
14
|
import { watchPublic } from '../assets/public.js';
|
|
14
15
|
import { snapshotFolder, watchFolder } from '../loader/watch.js';
|
|
@@ -45,9 +46,9 @@ export async function dev(options) {
|
|
|
45
46
|
const loaded = snapshotFolder(src);
|
|
46
47
|
for (const failure of await project.load())
|
|
47
48
|
project.report(failure);
|
|
48
|
-
// Now that the
|
|
49
|
-
//
|
|
50
|
-
await writeTypes(cwd, project.
|
|
49
|
+
// Now that the files ran, a language only offers the commands they do
|
|
50
|
+
// not describe, and `t` is typed from the default language.
|
|
51
|
+
await writeTypes(cwd, project.typesInfo());
|
|
51
52
|
// 3. What Discord must agree with before connecting.
|
|
52
53
|
const apiUrl = options.env.CHAPTERJS_API_URL;
|
|
53
54
|
const rest = new RestClient({
|
|
@@ -67,7 +68,7 @@ export async function dev(options) {
|
|
|
67
68
|
// The files of public/ are listed in the types: a file added or removed
|
|
68
69
|
// is offered (or not) by the editor at once.
|
|
69
70
|
const assets = watchPublic(cwd, () => {
|
|
70
|
-
writeTypes(cwd, project.
|
|
71
|
+
writeTypes(cwd, project.typesInfo())
|
|
71
72
|
.then(written => {
|
|
72
73
|
if (written > 0)
|
|
73
74
|
log.reload('public/ changed: types updated');
|
|
@@ -159,20 +160,20 @@ export async function dev(options) {
|
|
|
159
160
|
noted.add(file);
|
|
160
161
|
log.info(`${file} ${what} only works in private messages, and chapterjs dev only runs your bot in ${guild.name}. Try it with chapterjs start.`);
|
|
161
162
|
};
|
|
162
|
-
for (const
|
|
163
|
-
|
|
164
|
-
])) {
|
|
165
|
-
note(file, commandName(command.path));
|
|
163
|
+
for (const entry of privateOnly([...project.commands.values()])) {
|
|
164
|
+
note(siteName(entry), commandName(entry.command.path));
|
|
166
165
|
}
|
|
167
|
-
for (const
|
|
166
|
+
for (const entry of project.events.values()) {
|
|
167
|
+
const { event } = entry;
|
|
168
168
|
if (EVENTS[event.name].options &&
|
|
169
169
|
event.options.where === 'dm') {
|
|
170
|
-
note(
|
|
170
|
+
note(siteName(entry), `this ${event.name} event`);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
for (const
|
|
173
|
+
for (const entry of project.components.values()) {
|
|
174
|
+
const { component } = entry;
|
|
174
175
|
if (component.kind !== 'embed' && component.where === 'dm') {
|
|
175
|
-
note(
|
|
176
|
+
note(siteName(entry), `the ${component.kind} ${component.name}`);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
};
|
|
@@ -197,10 +198,10 @@ export async function dev(options) {
|
|
|
197
198
|
if (project.applyPresence(bot))
|
|
198
199
|
log.reload('Presence updated');
|
|
199
200
|
}
|
|
200
|
-
// A language that appeared or went: `t` is typed from
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
if ((await writeTypes(cwd, project.
|
|
201
|
+
// A language that appeared or went: `t` is typed from it. A
|
|
202
|
+
// command described in its file, or no longer: the languages
|
|
203
|
+
// offer it, or not.
|
|
204
|
+
if ((await writeTypes(cwd, project.typesInfo())) > 0)
|
|
204
205
|
log.reload('Types updated');
|
|
205
206
|
const intents = project.intents(false);
|
|
206
207
|
if ((intents & ~connectedIntents) !== 0 && bot) {
|
package/dist/cli/project.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type CommandEntry } from '../commands/tree.js';
|
|
2
2
|
import { type ComponentEntry } from '../components/router.js';
|
|
3
|
-
import { type LoadedPresence } from '../presence/
|
|
3
|
+
import { type LoadedPresence } from '../presence/declaration.js';
|
|
4
|
+
import { type DeclaredCommand, type DeclaredLanguage } from '../messages/declaration.js';
|
|
4
5
|
import { type LoadedMessages } from '../messages/translate.js';
|
|
6
|
+
import type { Locale } from '../discord/types/common.js';
|
|
5
7
|
import { type TaskEntry } from '../tasks/scheduler.js';
|
|
6
8
|
import { type Bot, type BotOptions } from '../core/bot.js';
|
|
7
9
|
import { type GatewayIntentName } from '../discord/intents.js';
|
|
8
10
|
import { type LoadedEvent } from '../events/router.js';
|
|
9
|
-
import { type BuiltFile, type FailedFile } from '../loader/loader.js';
|
|
11
|
+
import { type BuiltFile, type Declaration, type FailedFile } from '../loader/loader.js';
|
|
10
12
|
import type { Log } from './log.js';
|
|
11
13
|
export interface ProjectOptions {
|
|
12
14
|
/** The folder of the project. */
|
|
@@ -27,20 +29,32 @@ export interface ProjectOptions {
|
|
|
27
29
|
/** Only tests change this. */
|
|
28
30
|
deferAfter?: number;
|
|
29
31
|
}
|
|
32
|
+
/** What the types of a project are written from, once its files ran. */
|
|
33
|
+
export interface TypesInfo {
|
|
34
|
+
/** Every language declared, with where. */
|
|
35
|
+
languages: readonly DeclaredLanguage[];
|
|
36
|
+
/** The language `t` is typed from, when known. */
|
|
37
|
+
defaultLocale?: Locale;
|
|
38
|
+
/** The languages that say `default: true`, as they are now. */
|
|
39
|
+
languageDefaults: readonly Locale[];
|
|
40
|
+
/** Every command, and whether its file describes it. */
|
|
41
|
+
commands: readonly DeclaredCommand[];
|
|
42
|
+
}
|
|
30
43
|
/**
|
|
31
|
-
* Writes the types of a project (`.chapterjs/`):
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* the
|
|
38
|
-
*
|
|
44
|
+
* Writes the types of a project (`.chapterjs/`): what the project adds to
|
|
45
|
+
* 'chapterjs', like the files of `public/`, its languages and its
|
|
46
|
+
* commands. With the project as it loaded (`info`), a language only
|
|
47
|
+
* offers the commands without `description`, `t` is typed from the
|
|
48
|
+
* default language and `default: true` is refused in every language that
|
|
49
|
+
* says it when another one does; without it (`sync`, which runs nothing),
|
|
50
|
+
* the commands and the languages are found by reading the files, every
|
|
51
|
+
* command is offered, and the first language or the one that says
|
|
52
|
+
* `default: true` types `t`.
|
|
39
53
|
* @returns how many files were written
|
|
40
54
|
*/
|
|
41
|
-
export declare function writeTypes(cwd: string,
|
|
42
|
-
/** The
|
|
43
|
-
export declare const
|
|
55
|
+
export declare function writeTypes(cwd: string, info?: TypesInfo): Promise<number>;
|
|
56
|
+
/** The kinds of declarations a project is made of: one per feature. */
|
|
57
|
+
export declare const DECLARATIONS: readonly Declaration<unknown>[];
|
|
44
58
|
/** What a bot of the project is connected with. */
|
|
45
59
|
export interface ConnectOptions {
|
|
46
60
|
token: string;
|
|
@@ -60,27 +74,26 @@ export interface ConnectOptions {
|
|
|
60
74
|
}
|
|
61
75
|
/** The files of a project, and what runs them. */
|
|
62
76
|
export interface Project {
|
|
63
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The last version of each declaration that loaded, by the file and the
|
|
79
|
+
* export it comes from (`src/ping.ts#default`): what the bot runs.
|
|
80
|
+
*/
|
|
64
81
|
readonly events: ReadonlyMap<string, LoadedEvent>;
|
|
65
82
|
readonly commands: ReadonlyMap<string, CommandEntry>;
|
|
66
83
|
readonly components: ReadonlyMap<string, ComponentEntry>;
|
|
67
84
|
readonly tasks: ReadonlyMap<string, TaskEntry>;
|
|
68
|
-
/**
|
|
85
|
+
/** The presence declared, or `null` without one. */
|
|
69
86
|
readonly presence: LoadedPresence | null;
|
|
70
|
-
/** The languages of
|
|
87
|
+
/** The languages of the project, assembled, or `null` without any. */
|
|
71
88
|
readonly messages: LoadedMessages | null;
|
|
89
|
+
/** What the types of the project are written from, as it loaded. */
|
|
90
|
+
typesInfo(): TypesInfo;
|
|
72
91
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* underlined in the editor.
|
|
76
|
-
*/
|
|
77
|
-
readonly languageDefaults: readonly string[];
|
|
78
|
-
/**
|
|
79
|
-
* Loads every file (again). A file that fails is returned; it keeps its
|
|
80
|
-
* last working version when it had one.
|
|
92
|
+
* Loads every file (again). A declaration that fails is returned; it
|
|
93
|
+
* keeps its last working version when it had one.
|
|
81
94
|
*/
|
|
82
95
|
load(): Promise<FailedFile[]>;
|
|
83
|
-
/** Shows a failure with its file and line. */
|
|
96
|
+
/** Shows a failure with its file (and export) and line. */
|
|
84
97
|
report(failure: FailedFile): void;
|
|
85
98
|
/** "2 commands, 3 events, 4 components, a presence loaded". */
|
|
86
99
|
summary(): string;
|