@bitakit/cli 0.0.0-stage → 0.2.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 +153 -2
- package/package.json +44 -4
- package/src/add.mjs +190 -0
- package/src/agent-rules.mjs +63 -0
- package/src/build.mjs +203 -0
- package/src/cli.mjs +266 -0
- package/src/doctor.mjs +908 -0
- package/src/index.mjs +36 -0
- package/src/init.mjs +261 -0
- package/src/inventory.mjs +126 -0
- package/src/project.mjs +97 -0
- package/src/routes.mjs +124 -0
- package/src/templates.mjs +530 -0
package/src/build.mjs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { cp, mkdir, realpath, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { describeModule, describeDefinitions, validatePackageStyles } from '@bitakit/discovery';
|
|
6
|
+
import { findProject } from './project.mjs';
|
|
7
|
+
|
|
8
|
+
const quote = JSON.stringify;
|
|
9
|
+
const header = '// Generated by BitaKit. Do not edit.\n';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Builds a plugin package from the same folders apps use. It generates the plugin's own types
|
|
13
|
+
* (`.bitakit/plugin.d.ts`), compiles `src` with the package's TypeScript config and writes
|
|
14
|
+
* `dist/plugin.js`, the entry apps discover. `check` stops after a type check.
|
|
15
|
+
*/
|
|
16
|
+
export async function buildPlugin({ cwd, check = false } = {}) {
|
|
17
|
+
const project = await findProject(cwd);
|
|
18
|
+
if (project.kind !== 'plugin')
|
|
19
|
+
throw new Error(
|
|
20
|
+
'Run "bitakit build" inside a plugin package (a package.json with a bitakit.plugin entry).',
|
|
21
|
+
);
|
|
22
|
+
const { root, pluginId: id, moduleRoot, manifest, metadata } = project;
|
|
23
|
+
const module = await describeModule(moduleRoot);
|
|
24
|
+
for (const warning of module.warnings) console.warn(`[bitakit] ${warning}`);
|
|
25
|
+
// Discovery resolves symlinks (macOS /var → /private/var); relate the files to the real root,
|
|
26
|
+
// or the generated imports would leave the package and the type augmentation would not apply.
|
|
27
|
+
const realRoot = await realpath(root);
|
|
28
|
+
await mkdir(path.join(root, '.bitakit'), { recursive: true });
|
|
29
|
+
await writeFile(
|
|
30
|
+
path.join(root, '.bitakit/plugin.d.ts'),
|
|
31
|
+
declarations(
|
|
32
|
+
id,
|
|
33
|
+
module,
|
|
34
|
+
(file) =>
|
|
35
|
+
`../${path
|
|
36
|
+
.relative(realRoot, file)
|
|
37
|
+
.split(path.sep)
|
|
38
|
+
.join('/')
|
|
39
|
+
.replace(/\.tsx?$/, '')}`,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
const tsc = createRequire(path.join(root, 'package.json')).resolve('typescript/bin/tsc');
|
|
43
|
+
const compile = (args) => {
|
|
44
|
+
try {
|
|
45
|
+
execFileSync(process.execPath, [tsc, '-p', 'tsconfig.json', ...args], {
|
|
46
|
+
cwd: root,
|
|
47
|
+
stdio: 'pipe',
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`TypeScript found problems:\n${String(error.stdout || error.message).trim()}`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (check) {
|
|
56
|
+
compile(['--noEmit']);
|
|
57
|
+
return { id, module, checked: true };
|
|
58
|
+
}
|
|
59
|
+
const dist = path.join(root, 'dist');
|
|
60
|
+
await rm(dist, { recursive: true, force: true });
|
|
61
|
+
compile([]);
|
|
62
|
+
const local = (file) =>
|
|
63
|
+
`./${path
|
|
64
|
+
.relative(module.directory, file)
|
|
65
|
+
.split(path.sep)
|
|
66
|
+
.join('/')
|
|
67
|
+
.replace(/\.tsx?$/, '.js')}`;
|
|
68
|
+
await writeFile(path.join(dist, 'plugin.js'), entry(id, module, manifest, metadata, local));
|
|
69
|
+
// Derived tooling hints travel with the entry; the source declarations remain the authority.
|
|
70
|
+
const slotInfo = await describeDefinitions(module.slotDefinitions, {
|
|
71
|
+
helper: 'defineSlot', moduleId: id, properties: ['accepts', 'policy'],
|
|
72
|
+
});
|
|
73
|
+
const source = (file) => path.relative(module.directory, file).split(path.sep).join('/');
|
|
74
|
+
await writeFile(path.join(dist, 'plugin.slots.json'), JSON.stringify({
|
|
75
|
+
version: 1,
|
|
76
|
+
definitions: slotInfo.definitions.map((item) => ({ ...item, file: source(item.file), plugin: id, policy: item.policy ?? 'list' })),
|
|
77
|
+
unresolved: slotInfo.unresolved.map(source),
|
|
78
|
+
}, null, 2) + '\n');
|
|
79
|
+
await writeFile(
|
|
80
|
+
path.join(dist, 'plugin.d.ts'),
|
|
81
|
+
`${declarations(id, module, (file) => local(file))}import type { Plugin } from '@bitakit/core';
|
|
82
|
+
/** Creates the "${id}" plugin. Apps discover it through package.json bitakit.plugin. */
|
|
83
|
+
declare const plugin: () => Plugin & { readonly id: ${quote(id)} };
|
|
84
|
+
export default plugin;
|
|
85
|
+
`,
|
|
86
|
+
);
|
|
87
|
+
if (module.locales.length) {
|
|
88
|
+
await mkdir(path.join(dist, 'locales'), { recursive: true });
|
|
89
|
+
for (const file of module.locales)
|
|
90
|
+
await cp(file, path.join(dist, 'locales', path.basename(file)));
|
|
91
|
+
}
|
|
92
|
+
const styles = (value) => (value === undefined ? [] : Array.isArray(value) ? value : [value])
|
|
93
|
+
.map((entry) => `${manifest.name}/${entry.replace(/^\.\//, '')}`);
|
|
94
|
+
await validatePackageStyles([{
|
|
95
|
+
name: manifest.name,
|
|
96
|
+
manifestFile: path.join(root, 'package.json'),
|
|
97
|
+
manifest,
|
|
98
|
+
styles: styles(metadata.styles),
|
|
99
|
+
theme: styles(metadata.theme),
|
|
100
|
+
}]);
|
|
101
|
+
return { id, module, dist };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Typed services, actions, events and config for TypeScript, through @bitakit/core augmentation. */
|
|
105
|
+
function declarations(id, module, specifier) {
|
|
106
|
+
const lines = [];
|
|
107
|
+
const files = (entries, kind) =>
|
|
108
|
+
entries.map((entry, index) => {
|
|
109
|
+
const name = `${kind}${index}`;
|
|
110
|
+
lines.push(`import type ${name}Entry from ${quote(specifier(entry.file))};`);
|
|
111
|
+
lines.push(`type ${name} = DiscoveredFile<typeof ${name}Entry, ${quote(entry.path)}>;`);
|
|
112
|
+
return name;
|
|
113
|
+
});
|
|
114
|
+
const services = files(module.services, 'Service');
|
|
115
|
+
const settings = files(module.settings, 'Settings');
|
|
116
|
+
const slots = files(module.slotDefinitions, 'Slot');
|
|
117
|
+
const actions = files(module.actions, 'Action');
|
|
118
|
+
const configs = files(module.configs, 'Config');
|
|
119
|
+
const events = files(module.events, 'Events');
|
|
120
|
+
const intersect = (items, map) => items.map(map).join(' & ') || '{}';
|
|
121
|
+
return `${header}import type { DiscoveredFile, DiscoveredSlotEntry, DiscoveredServiceEntry, DiscoveredActionEntry, DiscoveredConfigEntry, DiscoveredEventsEntry, DiscoveredCancelableEntry, DiscoveredSettingsEntry } from '@bitakit/core';
|
|
122
|
+
${lines.join('\n')}
|
|
123
|
+
type PluginSettings = ${intersect(settings, (name) => `DiscoveredSettingsEntry<${name}, ${quote(id)}>`)};
|
|
124
|
+
type PluginSlots = ${intersect(slots, (name) => `DiscoveredSlotEntry<${name}, ${quote(id)}>`)};
|
|
125
|
+
type PluginServices = ${intersect(services, (name) => `DiscoveredServiceEntry<${name}, ${quote(id)}>`)};
|
|
126
|
+
type PluginActions = ${intersect(actions, (name) => `DiscoveredActionEntry<${name}, ${quote(id)}>`)};
|
|
127
|
+
type PluginEvents = ${intersect(events, (name) => `DiscoveredEventsEntry<${name}, ${quote(id)}>`)};
|
|
128
|
+
type PluginCancelable = ${intersect(events, (name) => `DiscoveredCancelableEntry<${name}, ${quote(id)}>`)};
|
|
129
|
+
declare module '@bitakit/core' {
|
|
130
|
+
interface ServiceMap extends PluginServices {}
|
|
131
|
+
interface ActionMap extends PluginActions {}
|
|
132
|
+
interface EventMap extends PluginEvents {}
|
|
133
|
+
interface CancelableEventMap extends PluginCancelable {}
|
|
134
|
+
interface SlotMap extends PluginSlots {}
|
|
135
|
+
interface SettingsMap extends PluginSettings {}
|
|
136
|
+
interface ConfigMap { ${quote(id)}: ${intersect(configs, (name) => `DiscoveredConfigEntry<${name}>`)} }
|
|
137
|
+
}
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The published plugin factory: the same normalizers apps use, with static imports only. */
|
|
142
|
+
function entry(id, module, manifest, metadata, local) {
|
|
143
|
+
const imports = [];
|
|
144
|
+
let serial = 0;
|
|
145
|
+
const load = (file, namespace = false) => {
|
|
146
|
+
const name = `${namespace ? 'module' : 'entry'}${serial++}`;
|
|
147
|
+
imports.push(
|
|
148
|
+
namespace
|
|
149
|
+
? `import * as ${name} from ${quote(local(file))};`
|
|
150
|
+
: `import ${name} from ${quote(local(file))};`,
|
|
151
|
+
);
|
|
152
|
+
return name;
|
|
153
|
+
};
|
|
154
|
+
const discovered = (entries) =>
|
|
155
|
+
entries.map((item) => {
|
|
156
|
+
const name = load(item.file);
|
|
157
|
+
return `discoveredFile(${name}, ${quote(item.path)}, ${quote(path.relative(module.directory, item.file).split(path.sep).join('/'))})`;
|
|
158
|
+
});
|
|
159
|
+
const info = {};
|
|
160
|
+
for (const key of ['name', 'version', 'description', 'author', 'homepage', 'bugs', 'license', 'coverImage', 'tags'])
|
|
161
|
+
if (manifest[key] !== undefined) info[key] = manifest[key];
|
|
162
|
+
const services = discovered(module.services);
|
|
163
|
+
const settings = discovered(module.settings);
|
|
164
|
+
const settingsPage = module.settingsPage ? `pluginSettingsPage(${load(module.settingsPage, true)})` : undefined;
|
|
165
|
+
const slotDefinitions = discovered(module.slotDefinitions);
|
|
166
|
+
const actions = discovered(module.actions);
|
|
167
|
+
const configs = discovered(module.configs);
|
|
168
|
+
const interceptors = discovered(module.interceptors);
|
|
169
|
+
const events = discovered(module.events);
|
|
170
|
+
const pages = module.pages.map(
|
|
171
|
+
(item) =>
|
|
172
|
+
`pluginPage(${load(item.file, true)}, ${quote(`/${id}${item.path ? `/${item.path.split('.').join('/')}` : ''}`)})`,
|
|
173
|
+
);
|
|
174
|
+
const slots = module.slots.map(
|
|
175
|
+
(item) => `pluginSlot(${load(item.file, true)}, ${quote(item.path)}, ${quote(path.relative(module.directory, item.file).split(path.sep).join('/'))})`,
|
|
176
|
+
);
|
|
177
|
+
const providers = module.providers.map(
|
|
178
|
+
(item) => `pluginProvider(${load(item.file, true)}, ${quote(`${id}.${item.path}`)})`,
|
|
179
|
+
);
|
|
180
|
+
const setup = module.setup ? load(module.setup) : 'undefined';
|
|
181
|
+
return `'use client';
|
|
182
|
+
${header}import { definePlugin, discoveredFile, discoverActions, discoverServices, discoverSlots, discoverConfig, discoverInterceptors, discoverEvents, discoverSettings, pluginSettingsPage, pluginPage, pluginSlot, pluginProvider } from '@bitakit/core';
|
|
183
|
+
${imports.join('\n')}
|
|
184
|
+
|
|
185
|
+
/** Creates the ${quote(id)} plugin; apps call this once per runtime. */
|
|
186
|
+
export default function plugin() {
|
|
187
|
+
return definePlugin({
|
|
188
|
+
id: ${quote(id)},
|
|
189
|
+
metadata: ${quote(info)},
|
|
190
|
+
dependencies: ${quote(metadata?.dependencies ?? [])},
|
|
191
|
+
events: discoverEvents([${events.join(', ')}]),
|
|
192
|
+
settings: discoverSettings([${settings.join(', ')}]),
|
|
193
|
+
slots: discoverSlots([${slotDefinitions.join(', ')}], ${quote(id)}),
|
|
194
|
+
services: discoverServices([${services.join(', ')}], ${quote(id)}),
|
|
195
|
+
actions: discoverActions([${actions.join(', ')}], ${quote(id)}),
|
|
196
|
+
config: discoverConfig([${configs.join(', ')}]),
|
|
197
|
+
interceptors: discoverInterceptors([${interceptors.join(', ')}]),
|
|
198
|
+
ui: { pages: [${pages.join(', ')}], slots: [${slots.join(', ')}], providers: [${providers.join(', ')}]${settingsPage ? `, settings: ${settingsPage}` : ''} },
|
|
199
|
+
setup: ${setup},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
`;
|
|
203
|
+
}
|
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { styleText } from 'node:util';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import {
|
|
7
|
+
describeBitaKit,
|
|
8
|
+
generateBitaKit,
|
|
9
|
+
migrateProject,
|
|
10
|
+
watchBitaKit,
|
|
11
|
+
} from '@bitakit/discovery';
|
|
12
|
+
import { addContribution, addPlugin, contributionKinds } from './add.mjs';
|
|
13
|
+
import { inspectionFromDescription } from './inventory.mjs';
|
|
14
|
+
import { buildPlugin } from './build.mjs';
|
|
15
|
+
import { doctor } from './doctor.mjs';
|
|
16
|
+
import { initProject } from './init.mjs';
|
|
17
|
+
import { findProject, findProjectRoot } from './project.mjs';
|
|
18
|
+
|
|
19
|
+
const manifest = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
20
|
+
const relative = (file) => path.relative(process.cwd(), file) || '.';
|
|
21
|
+
const created = (files) =>
|
|
22
|
+
files.forEach((file) => console.log(` ${styleText('green', '+')} ${relative(file)}`));
|
|
23
|
+
|
|
24
|
+
const program = new Command()
|
|
25
|
+
.name('bitakit')
|
|
26
|
+
.description(
|
|
27
|
+
'Wire an app, add plugins and contributions, generate the wiring, and check a project for problems.',
|
|
28
|
+
)
|
|
29
|
+
.version(manifest.version);
|
|
30
|
+
|
|
31
|
+
const add = program
|
|
32
|
+
.command('add')
|
|
33
|
+
.description('Create a plugin or a contribution from a template.');
|
|
34
|
+
add
|
|
35
|
+
.command('plugin')
|
|
36
|
+
.argument('<name>', 'plugin name, for example "notes"')
|
|
37
|
+
.option('--example', 'a complete example feature: a service, events, actions and a list page')
|
|
38
|
+
.option(
|
|
39
|
+
'--minimal',
|
|
40
|
+
'only a service, its events and one action, without a page or navigation link',
|
|
41
|
+
)
|
|
42
|
+
.description(
|
|
43
|
+
'Create src/plugins/<name> with one page and, when the app has Shell, its navigation link.',
|
|
44
|
+
)
|
|
45
|
+
.action(async (name, options) => {
|
|
46
|
+
const result = await addPlugin(name, { minimal: options.minimal, example: options.example });
|
|
47
|
+
console.log(`\nCreated plugin "${name}":`);
|
|
48
|
+
created(result.created);
|
|
49
|
+
console.log(
|
|
50
|
+
result.navigation
|
|
51
|
+
? `\n"${result.title}" now appears in the navigation and opens ${result.path}.\nThe dev server picks it up automatically; no registration needed.\nNext: npx bitakit add service ${name}/items, then npx bitakit add action ${name}/<name>.\n`
|
|
52
|
+
: result.path
|
|
53
|
+
? `\n"${result.title}" opens ${result.path}.\nThe dev server picks it up automatically; no registration needed.\n`
|
|
54
|
+
: `\nThe dev server picks it up automatically; no registration needed.\n`,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
for (const kind of contributionKinds)
|
|
58
|
+
add
|
|
59
|
+
.command(kind)
|
|
60
|
+
.argument(
|
|
61
|
+
kind === 'events' || kind === 'settings' || kind === 'settings-page'
|
|
62
|
+
? '[plugin]'
|
|
63
|
+
: kind === 'layout'
|
|
64
|
+
? '<name>'
|
|
65
|
+
: '<target>',
|
|
66
|
+
kind === 'events' || kind === 'settings' || kind === 'settings-page'
|
|
67
|
+
? `the plugin that owns the ${kind}; omit it inside a plugin package`
|
|
68
|
+
: kind === 'layout'
|
|
69
|
+
? 'the layout name; pages choose it with export const layout'
|
|
70
|
+
: kind === 'slot'
|
|
71
|
+
? '"<plugin>/<slot path>": "activity/projects/sidebar" adds a component of plugin "activity" to slot "projects.sidebar"'
|
|
72
|
+
: `"<plugin>/<name>" in an app (nested names allowed), or "<name>" inside a plugin package`,
|
|
73
|
+
)
|
|
74
|
+
.description(
|
|
75
|
+
kind === 'events' || kind === 'settings'
|
|
76
|
+
? `Create the ${kind}.ts of a plugin.`
|
|
77
|
+
: kind === 'settings-page'
|
|
78
|
+
? "Create ui/settings/page.tsx, which replaces the plugin's generated settings page."
|
|
79
|
+
: kind === 'layout'
|
|
80
|
+
? 'Create src/layouts/<name>.tsx of the app.'
|
|
81
|
+
: `Create ${/^[aeiou]/.test(kind) ? 'an' : 'a'} ${kind} file. Its ID comes from the file path.`,
|
|
82
|
+
)
|
|
83
|
+
.action(async (target) => {
|
|
84
|
+
const result = await addContribution(kind, target);
|
|
85
|
+
if (result.createdPlugin) console.log(`\nCreated plugin "${result.plugin}".`);
|
|
86
|
+
console.log(
|
|
87
|
+
kind === 'slot'
|
|
88
|
+
? `\nCreated a component of plugin "${result.plugin}" for slot "${result.id}":`
|
|
89
|
+
: `\nCreated ${kind} ${kind === 'page' ? result.path : `"${result.id}"`}:`,
|
|
90
|
+
);
|
|
91
|
+
created(result.created);
|
|
92
|
+
console.log('');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
program
|
|
96
|
+
.command('init')
|
|
97
|
+
.description(
|
|
98
|
+
'Wire an existing Next.js or TanStack Start app: bitakit.config.ts, the config wrapper or Vite plugin, the provider, the catch-all route and .gitignore.',
|
|
99
|
+
)
|
|
100
|
+
.action(async () => {
|
|
101
|
+
const { written, skipped, install } = await initProject();
|
|
102
|
+
if (written.length) {
|
|
103
|
+
console.log('\nWritten:');
|
|
104
|
+
for (const { file, created } of written)
|
|
105
|
+
console.log(` ${styleText('green', created ? '+' : '~')} ${relative(file)}`);
|
|
106
|
+
}
|
|
107
|
+
if (skipped.length) {
|
|
108
|
+
console.log('\nSkipped:');
|
|
109
|
+
for (const { file, reason } of skipped)
|
|
110
|
+
console.log(
|
|
111
|
+
` ${styleText('yellow', '-')} ${relative(file)} ${styleText('dim', `(${reason})`)}`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
if (!written.length) console.log('\nNothing to write: the app is already wired.');
|
|
115
|
+
if (install.length)
|
|
116
|
+
console.log(`\nInstall the packages the wiring imports:\n npm install ${install.join(' ')}`);
|
|
117
|
+
console.log('\nThen run "npx bitakit generate" and "npx bitakit doctor".\n');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
program
|
|
121
|
+
.command('generate')
|
|
122
|
+
.option('--watch', 'keep regenerating while files change')
|
|
123
|
+
.description('Write src/bitakit.gen.* from the plugin folders and installed packages.')
|
|
124
|
+
.action(async (options) => {
|
|
125
|
+
const project = await findProject();
|
|
126
|
+
if (project.kind !== 'app') throw new Error('Run "bitakit generate" inside an app.');
|
|
127
|
+
if (options.watch) {
|
|
128
|
+
watchBitaKit(project.root, (error) =>
|
|
129
|
+
console.error(styleText('red', String(error?.message ?? error))),
|
|
130
|
+
);
|
|
131
|
+
console.log(`Watching ${relative(project.root)} for changes…`);
|
|
132
|
+
await new Promise(() => {});
|
|
133
|
+
}
|
|
134
|
+
const result = await generateBitaKit(project.root);
|
|
135
|
+
console.log(
|
|
136
|
+
`\nGenerated ${relative(result.generated)} (${result.framework === 'none' ? 'no framework provider' : result.framework}).${result.warnings.length ? ` ${result.warnings.length} warning${result.warnings.length === 1 ? '' : 's'} above.` : ''}\n`,
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
program
|
|
141
|
+
.command('migrate')
|
|
142
|
+
.option('--navigation-slot <name>', 'explicit target for legacy navigation group Actions')
|
|
143
|
+
.option('--dry-run', 'only list the changes')
|
|
144
|
+
.description(
|
|
145
|
+
'Rewrite a 0.1 project to the current layout: bitakit.config.ts, folder-only files, ui/ folders, generated imports.',
|
|
146
|
+
)
|
|
147
|
+
.action(async (options) => {
|
|
148
|
+
// Only the root is needed: a 0.1 configuration may not even load before it is migrated.
|
|
149
|
+
const { root } = await findProjectRoot();
|
|
150
|
+
const { changes } = await migrateProject(root, {
|
|
151
|
+
dryRun: options.dryRun,
|
|
152
|
+
navigationSlot: options.navigationSlot,
|
|
153
|
+
});
|
|
154
|
+
if (!changes.length) {
|
|
155
|
+
console.log('\nNothing to migrate.\n');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
console.log(options.dryRun ? '\nWould change:' : '\nChanged:');
|
|
159
|
+
for (const change of changes)
|
|
160
|
+
console.log(
|
|
161
|
+
` ${styleText(change.kind === 'skip' ? 'yellow' : 'green', change.kind.padEnd(7))} ${change.from}${change.to ? ` → ${change.to}` : ''}${change.detail ? styleText('dim', ` (${change.detail})`) : ''}`,
|
|
162
|
+
);
|
|
163
|
+
console.log(
|
|
164
|
+
options.dryRun
|
|
165
|
+
? '\nRun without --dry-run to apply.\n'
|
|
166
|
+
: '\nReview the diff, then run "bitakit generate" and "bitakit doctor".\n',
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
program
|
|
171
|
+
.command('build')
|
|
172
|
+
.option('--check', 'only generate types and type-check, without writing dist')
|
|
173
|
+
.description('Build a plugin package: types, compiled sources and the dist/plugin.js entry.')
|
|
174
|
+
.action(async (options) => {
|
|
175
|
+
const result = await buildPlugin({ check: options.check });
|
|
176
|
+
const count = ['services', 'actions', 'pages']
|
|
177
|
+
.map((kind) => `${result.module[kind].length} ${kind}`)
|
|
178
|
+
.join(', ');
|
|
179
|
+
console.log(
|
|
180
|
+
options.check
|
|
181
|
+
? `\nPlugin "${result.id}" type-checks (${count}).\n`
|
|
182
|
+
: `\nBuilt plugin "${result.id}" (${count}) into ${relative(result.dist)}.\nPublish it with npm publish; apps that install it discover it automatically.\n`,
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
program
|
|
187
|
+
.command('doctor')
|
|
188
|
+
.option('--json', 'machine-readable output')
|
|
189
|
+
.description(
|
|
190
|
+
'Check versions, wiring, routes, links, service names, styles and deprecated layouts.',
|
|
191
|
+
)
|
|
192
|
+
.action(async (options) => {
|
|
193
|
+
const { project, results } = await doctor();
|
|
194
|
+
const errors = results.filter((result) => result.status === 'error').length;
|
|
195
|
+
const warnings = results.filter((result) => result.status === 'warn').length;
|
|
196
|
+
if (options.json) {
|
|
197
|
+
console.log(
|
|
198
|
+
JSON.stringify({ project: project.manifest.name, results, errors, warnings }, null, 2),
|
|
199
|
+
);
|
|
200
|
+
if (errors) process.exitCode = 1;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
console.log(`\nBitaKit doctor · ${project.manifest.name ?? relative(project.root)}\n`);
|
|
204
|
+
const symbols = {
|
|
205
|
+
ok: styleText('green', '✔'),
|
|
206
|
+
warn: styleText('yellow', '⚠'),
|
|
207
|
+
error: styleText('red', '✖'),
|
|
208
|
+
};
|
|
209
|
+
for (const result of results) {
|
|
210
|
+
console.log(`${symbols[result.status]} ${result.title}`);
|
|
211
|
+
for (const detail of result.details ?? []) console.log(` ${detail}`);
|
|
212
|
+
if (result.fix)
|
|
213
|
+
console.log(` ${styleText('cyan', 'Fix:')} ${result.fix.replaceAll('\n', '\n ')}`);
|
|
214
|
+
}
|
|
215
|
+
console.log(
|
|
216
|
+
`\n${errors ? `${errors} problem${errors === 1 ? '' : 's'}` : 'No problems'}${warnings ? `, ${warnings} warning${warnings === 1 ? '' : 's'}` : ''}.\n`,
|
|
217
|
+
);
|
|
218
|
+
if (errors) process.exitCode = 1;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
program
|
|
222
|
+
.command('info')
|
|
223
|
+
.option('--json', 'machine-readable output')
|
|
224
|
+
.description('List the plugins, services, actions, events and pages discovery finds.')
|
|
225
|
+
.action(async (options) => {
|
|
226
|
+
const project = await findProject();
|
|
227
|
+
if (project.kind !== 'app') throw new Error('Run "bitakit info" inside an app.');
|
|
228
|
+
const description = await describeBitaKit(project.root);
|
|
229
|
+
const inventory = await inspectionFromDescription(description);
|
|
230
|
+
if (options.json) {
|
|
231
|
+
console.log(JSON.stringify(inventory, null, 2));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
for (const plugin of inventory.static.plugins) {
|
|
235
|
+
const title =
|
|
236
|
+
plugin.source.kind === 'package' ? `Package "${plugin.id}"` : `Plugin "${plugin.id}"`;
|
|
237
|
+
console.log(
|
|
238
|
+
`\n${styleText('bold', title)}${plugin.enabled === false ? ' (disabled)' : ''} ${styleText('dim', plugin.source.path ?? '')}`,
|
|
239
|
+
);
|
|
240
|
+
if (plugin.declarations === null)
|
|
241
|
+
console.log(' declarations: unavailable (static package entry)');
|
|
242
|
+
else
|
|
243
|
+
for (const kind of new Set(plugin.declarations.map((entry) => entry.kind)))
|
|
244
|
+
console.log(
|
|
245
|
+
` ${kind}: ${plugin.declarations
|
|
246
|
+
.filter((entry) => entry.kind === kind)
|
|
247
|
+
.map((entry) => entry.id ?? entry.source)
|
|
248
|
+
.join(', ')}`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
console.log('\nLive state: unavailable (static discovery).');
|
|
252
|
+
if (description.warnings.length) {
|
|
253
|
+
console.log(
|
|
254
|
+
`\n${styleText('yellow', `${description.warnings.length} warning${description.warnings.length === 1 ? '' : 's'}`)}`,
|
|
255
|
+
);
|
|
256
|
+
for (const warning of description.warnings) console.log(` ${warning}`);
|
|
257
|
+
}
|
|
258
|
+
console.log('');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
await program.parseAsync();
|
|
263
|
+
} catch (error) {
|
|
264
|
+
console.error(styleText('red', error.message));
|
|
265
|
+
process.exitCode = 1;
|
|
266
|
+
}
|