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.
Files changed (80) hide show
  1. package/dist/cli/build.js +9 -10
  2. package/dist/cli/dev.js +17 -16
  3. package/dist/cli/project.d.ts +38 -25
  4. package/dist/cli/project.js +199 -134
  5. package/dist/commands/command.d.ts +25 -11
  6. package/dist/commands/command.js +5 -5
  7. package/dist/commands/{convention.d.ts → declaration.d.ts} +24 -11
  8. package/dist/commands/{convention.js → declaration.js} +61 -33
  9. package/dist/commands/tree.d.ts +8 -4
  10. package/dist/commands/tree.js +16 -6
  11. package/dist/components/button.d.ts +13 -13
  12. package/dist/components/button.js +9 -11
  13. package/dist/components/component.d.ts +1 -1
  14. package/dist/components/component.js +1 -1
  15. package/dist/components/custom-id.d.ts +4 -4
  16. package/dist/components/custom-id.js +12 -12
  17. package/dist/components/declaration.d.ts +42 -0
  18. package/dist/components/{convention.js → declaration.js} +76 -73
  19. package/dist/components/declared.d.ts +29 -0
  20. package/dist/components/declared.js +49 -0
  21. package/dist/components/embed.d.ts +13 -12
  22. package/dist/components/embed.js +6 -6
  23. package/dist/components/instance.d.ts +3 -3
  24. package/dist/components/instance.js +2 -2
  25. package/dist/components/modal.d.ts +11 -10
  26. package/dist/components/modal.js +7 -8
  27. package/dist/components/router.d.ts +3 -2
  28. package/dist/components/router.js +14 -19
  29. package/dist/components/select.d.ts +14 -12
  30. package/dist/components/select.js +4 -4
  31. package/dist/events/declaration.d.ts +16 -0
  32. package/dist/events/declaration.js +80 -0
  33. package/dist/events/event.d.ts +42 -5
  34. package/dist/events/event.js +25 -11
  35. package/dist/events/registry.d.ts +1 -10
  36. package/dist/events/router.d.ts +3 -2
  37. package/dist/index.d.ts +11 -9
  38. package/dist/index.js +2 -0
  39. package/dist/loader/generated.d.ts +5 -32
  40. package/dist/loader/generated.js +21 -55
  41. package/dist/loader/loader.d.ts +57 -44
  42. package/dist/loader/loader.js +73 -89
  43. package/dist/main.d.ts +0 -1
  44. package/dist/main.js +2 -3
  45. package/dist/messages/commands.d.ts +3 -3
  46. package/dist/messages/commands.js +29 -10
  47. package/dist/messages/declaration.d.ts +89 -0
  48. package/dist/messages/declaration.js +455 -0
  49. package/dist/messages/messages.d.ts +65 -43
  50. package/dist/messages/messages.js +11 -10
  51. package/dist/messages/phrases.js +1 -1
  52. package/dist/messages/translate.d.ts +4 -4
  53. package/dist/messages/translate.js +4 -4
  54. package/dist/presence/declaration.d.ts +19 -0
  55. package/dist/presence/{convention.js → declaration.js} +13 -28
  56. package/dist/presence/presence.d.ts +7 -7
  57. package/dist/presence/presence.js +5 -5
  58. package/dist/structures/context.d.ts +1 -1
  59. package/dist/structures/interaction.d.ts +2 -2
  60. package/dist/structures/interaction.js +3 -3
  61. package/dist/structures/payload.d.ts +4 -4
  62. package/dist/structures/payload.js +4 -4
  63. package/dist/tasks/declaration.d.ts +16 -0
  64. package/dist/tasks/{convention.js → declaration.js} +14 -36
  65. package/dist/tasks/scheduler.d.ts +3 -1
  66. package/dist/tasks/scheduler.js +4 -4
  67. package/dist/tasks/task.d.ts +8 -9
  68. package/dist/tasks/task.js +6 -7
  69. package/package.json +1 -1
  70. package/dist/components/convention.d.ts +0 -35
  71. package/dist/components/file.d.ts +0 -30
  72. package/dist/components/file.js +0 -52
  73. package/dist/events/convention.d.ts +0 -25
  74. package/dist/events/convention.js +0 -97
  75. package/dist/events/types.d.ts +0 -7
  76. package/dist/events/types.js +0 -48
  77. package/dist/messages/convention.d.ts +0 -89
  78. package/dist/messages/convention.js +0 -347
  79. package/dist/presence/convention.d.ts +0 -26
  80. 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 { listFolder } from '../loader/loader.js';
16
+ import { listSources } from '../loader/loader.js';
17
17
  import { sourcesJoinVoice } from '../voice/usage.js';
18
- import { CONVENTIONS, createProject, hasSources, writeTypes, } from './project.js';
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 file only offers the commands they
112
- // do not describe; written even when a file failed, so the editor
113
- // follows.
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 the conventional folders,
132
- // with what it imports from the project. Packages stay where they are
133
- // installed: the bot and the framework must share the same ones.
134
- const found = (await Promise.all(CONVENTIONS.map(convention => listFolder(cwd, convention)))).flat();
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 command files ran, a language file only offers the ones
49
- // they do not describe.
50
- await writeTypes(cwd, project.commands, project.messages, project.languageDefaults);
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.commands, project.messages, project.languageDefaults)
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 { file, command } of privateOnly([
163
- ...project.commands.values(),
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 { file, event } of project.events.values()) {
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(file, `this ${event.name} file`);
170
+ note(siteName(entry), `this ${event.name} event`);
171
171
  }
172
172
  }
173
- for (const { file, component } of project.components.values()) {
173
+ for (const entry of project.components.values()) {
174
+ const { component } = entry;
174
175
  if (component.kind !== 'embed' && component.where === 'dm') {
175
- note(file, `the ${component.kind} ${component.path}`);
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 the
201
- // folder. A command described in its file, or no longer: the
202
- // language files offer it, or not.
203
- if ((await writeTypes(cwd, project.commands, project.messages, project.languageDefaults)) > 0)
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) {
@@ -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/convention.js';
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/`): one project per typed
32
- * folder (every event, every language file), and what every file gets,
33
- * like the files of `public/`. With the commands and the languages as
34
- * they loaded, a language file only offers the ones without `description`
35
- * in their file, `t` is typed from the default language and `default:
36
- * true` is refused in every file when another one says it (`defaults`,
37
- * the files that do); without them (`sync`, which runs nothing),
38
- * every command is offered and the first language file types `t`.
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, commands?: ReadonlyMap<string, CommandEntry>, messages?: LoadedMessages | null, defaults?: readonly string[]): Promise<number>;
42
- /** The conventional folders of a project: one per feature. */
43
- export declare const CONVENTIONS: readonly [import("../loader/loader.js").Convention<import("../events/convention.js").EventHandler<keyof import("../events/registry.js").EventContexts>>, import("../loader/loader.js").Convention<import("../commands/convention.js").LoadedCommand>, import("../loader/loader.js").Convention<import("../components/convention.js").LoadedComponent>, import("../loader/loader.js").Convention<import("../tasks/convention.js").LoadedTask>, import("../loader/loader.js").Convention<LoadedPresence>, import("../loader/loader.js").Convention<import("../messages/convention.js").LoadedLanguage>];
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
- /** The last version of each file that loaded: what the bot runs. */
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
- /** What `src/presence.ts` declares, or `null` without that file. */
85
+ /** The presence declared, or `null` without one. */
69
86
  readonly presence: LoadedPresence | null;
70
- /** The languages of `src/messages/`, assembled, or `null` without any. */
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
- * The language files that say `default: true`, as they are now: a file
74
- * left out because a second one says it is counted, so that both are
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;