@makoojs/cli 0.1.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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.CN.md +373 -0
  3. package/README.md +373 -0
  4. package/dist/bin.js +1506 -0
  5. package/dist/command/_util.d.ts +16 -0
  6. package/dist/command/add.d.ts +1 -0
  7. package/dist/command/bin.d.ts +2 -0
  8. package/dist/command/build.d.ts +1 -0
  9. package/dist/command/dev.d.ts +1 -0
  10. package/dist/command/inspect.d.ts +1 -0
  11. package/dist/config/config.d.ts +3 -0
  12. package/dist/config/defaults.d.ts +26 -0
  13. package/dist/config/resolve.d.ts +17 -0
  14. package/dist/config/types.d.ts +140 -0
  15. package/dist/config/validation.d.ts +15 -0
  16. package/dist/error/error.d.ts +46 -0
  17. package/dist/generator/generator.d.ts +3 -0
  18. package/dist/generator/render/import/importAdapter.d.ts +3 -0
  19. package/dist/generator/render/import/importComp.d.ts +3 -0
  20. package/dist/generator/render/import/importInjector.d.ts +1 -0
  21. package/dist/generator/render/import/importRuntimeSetup.d.ts +1 -0
  22. package/dist/generator/render/init/initInjector.d.ts +3 -0
  23. package/dist/generator/render/init/registerComp.d.ts +2 -0
  24. package/dist/generator/render/run/renderInjectorRun.d.ts +1 -0
  25. package/dist/generator/render/util/value.d.ts +1 -0
  26. package/dist/generator/types.d.ts +21 -0
  27. package/dist/index.cjs +86 -0
  28. package/dist/index.d.ts +5 -0
  29. package/dist/index.js +5090 -0
  30. package/dist/monkey/clipboard.d.ts +3 -0
  31. package/dist/monkey/download.d.ts +3 -0
  32. package/dist/monkey/index.cjs +1 -0
  33. package/dist/monkey/index.d.ts +60 -0
  34. package/dist/monkey/index.js +60 -0
  35. package/dist/monkey/info.d.ts +5 -0
  36. package/dist/monkey/menu.d.ts +4 -0
  37. package/dist/monkey/notification.d.ts +3 -0
  38. package/dist/monkey/request.d.ts +7 -0
  39. package/dist/monkey/resource.d.ts +4 -0
  40. package/dist/monkey/storage.d.ts +11 -0
  41. package/dist/monkey/style.d.ts +4 -0
  42. package/dist/monkey/tab.d.ts +6 -0
  43. package/dist/scanner/collectDependenics.d.ts +2 -0
  44. package/dist/scanner/load/loadManifes.d.ts +3 -0
  45. package/dist/scanner/load/loadMeta.d.ts +2 -0
  46. package/dist/scanner/scanner.d.ts +3 -0
  47. package/dist/scanner/types.d.ts +23 -0
  48. package/dist/scanner/util.d.ts +2 -0
  49. package/dist/scanner/validation.d.ts +121 -0
  50. package/dist/vitePlugin/hmrController.d.ts +4 -0
  51. package/dist/vitePlugin/makoo.d.ts +3 -0
  52. package/dist/vitePlugin/makooMonkey.d.ts +3 -0
  53. package/dist/vitePlugin/types.d.ts +12 -0
  54. package/dist/vitePlugin/virtualModule.d.ts +2 -0
  55. package/dist/vitePlugin/watchList.d.ts +4 -0
  56. package/package.json +54 -0
@@ -0,0 +1,16 @@
1
+ import { ResolvedConfig } from '../config/types';
2
+ export declare const ansi: {
3
+ readonly reset: "\u001B[0m";
4
+ readonly bold: "\u001B[1m";
5
+ readonly cyan: "\u001B[36m";
6
+ readonly green: "\u001B[32m";
7
+ readonly dim: "\u001B[2m";
8
+ };
9
+ export declare const colorize: (value: string, ...codes: string[]) => string;
10
+ export declare function loadCliVersion(cliVersionCache: string | null): Promise<string>;
11
+ export declare function loadMakooConfig(): Promise<ResolvedConfig>;
12
+ export declare function getExtName(framework: string): string | null;
13
+ export declare function updateManifest(moduleName: string, updateData: Record<string, unknown>): Promise<void>;
14
+ export declare function moduleTemplate(framework: string): string;
15
+ export declare function vueTemplate(): string;
16
+ export declare function reactTemplate(): string;
@@ -0,0 +1 @@
1
+ export declare function addCommand(moduleName: string, framework: string): Promise<void>;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1 @@
1
+ export declare function buildCommand(): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function devCommand(): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function inspectCommand(): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { InjectionManifest, InjectionModuleConfig, StrictShape } from './types';
2
+ export declare const defineInjection: <T extends InjectionModuleConfig>(config: StrictShape<InjectionModuleConfig, T>) => T;
3
+ export declare function defineInjections<T extends InjectionManifest>(manifest: StrictShape<InjectionManifest, T>): T;
@@ -0,0 +1,26 @@
1
+ import { InjectorConfig, MonkeyBuildConfig, MonkeyConfig, MonkeyServerConfig, ResolvedRuntimeConfig } from './types';
2
+ export declare const SOURCE_EXTENSIONS: string[];
3
+ export declare const ESM_IMPORT_RE: RegExp;
4
+ export declare const CJS_IMPORT_RE: RegExp;
5
+ export declare const VIRTUAL_MODULE_ID = "virtual:makoo/entry";
6
+ export declare const RESOLVED_ID = "\0virtual:makoo/entry";
7
+ export declare const FAKE_ENTRY = "makoo-entry.ts";
8
+ export declare const FAKE_RESOLVED_ID = "\0makoo-entry.ts";
9
+ export declare const REACT_EXTENSIONS: Set<string>;
10
+ export declare const VUE_EXTENSIONS: Set<string>;
11
+ export declare const DEFAULT_SOURCE_DIR = "injections";
12
+ export declare const DEFAULT_MANIFEST_FILE_NAME = "manifest";
13
+ export declare const DEFAULT_SOURCE_CONFIG: {
14
+ dir: string;
15
+ include: string[];
16
+ exclude: string[];
17
+ manifest: string;
18
+ };
19
+ export declare const DEFAULT_RUNTIME_CONFIG: ResolvedRuntimeConfig;
20
+ export declare const DEFAULT_INJECTOR_CONFIG: Required<InjectorConfig>;
21
+ export declare const DEFAULT_MONKEY_SERVER_CONFIG: Required<MonkeyServerConfig>;
22
+ export declare const DEFAULT_MONKEY_BUILD_CONFIG: Pick<Required<MonkeyBuildConfig>, 'metaFileName' | 'autoGrant'>;
23
+ export declare const DEFAULT_MONKEY_CONFIG: Pick<MonkeyConfig, 'align' | 'styleImport'> & {
24
+ clientAlias: string;
25
+ };
26
+ export declare const DEFAULT_FILE_NAME_SUFFIX = ".user.js";
@@ -0,0 +1,17 @@
1
+ import { MonkeyOption } from 'vite-plugin-monkey';
2
+ import { AppConfig, CliConfig, InjectionManifest, InjectionModuleConfig, InjectorConfig, MonkeyConfig, ResolveConfigOptions, ResolvedConfig, ResolvedInjectionManifest, ResolvedInjectionModule, ResolvedInjectorConfig, ResolvedMonkeyBuildConfig, ResolvedMonkeyConfig, ResolvedMonkeyServerConfig, ResolvedRuntimeConfig, ResolvedSourceConfig, ResolveInjectionOptions, RuntimeConfig, SourceConfig } from './types';
3
+ export declare const normalizeInjectionManifest: (injections: InjectionManifest | undefined) => ResolvedInjectionManifest;
4
+ export declare const resolveAppConfig: (config: AppConfig) => AppConfig;
5
+ export declare const resolveSourceConfig: (config: SourceConfig | undefined, root: string) => ResolvedSourceConfig;
6
+ export declare const resolveInjectorConfig: (config: InjectorConfig | undefined) => ResolvedInjectorConfig;
7
+ export declare const resolveRuntimeConfig: (config: RuntimeConfig | undefined, root: string) => ResolvedRuntimeConfig;
8
+ export declare const resolveMonkeyServerConfig: (config: MonkeyConfig | undefined) => ResolvedMonkeyServerConfig;
9
+ export declare const resolveMonkeyBuildConfig: (app: AppConfig, config: MonkeyConfig | undefined) => ResolvedMonkeyBuildConfig;
10
+ export declare const resolveMonkeyConfig: (app: AppConfig, config: MonkeyConfig | undefined) => ResolvedMonkeyConfig;
11
+ export declare const resolveInjection: (config: InjectionModuleConfig, options: ResolveInjectionOptions) => ResolvedInjectionModule;
12
+ export declare const resolveInjections: (injections: InjectionManifest | undefined, options: ResolveConfigOptions & {
13
+ source: ResolvedSourceConfig;
14
+ injector: ResolvedInjectorConfig;
15
+ }) => ResolvedInjectionModule[];
16
+ export declare const resolveConfig: (config: CliConfig, root?: string) => ResolvedConfig;
17
+ export declare function resolveMonkeyPluginOptions(config: ResolvedConfig, override?: Partial<MonkeyOption>): MonkeyOption;
@@ -0,0 +1,140 @@
1
+ import { ArtifactOptions, LifecycleHookMap, InjectionConfig as RuntimeInjectionConfig } from '../../../../../core';
2
+ import { ExternalGlobals, ExternalResource, MonkeyOption, MonkeyUserScript } from 'vite-plugin-monkey';
3
+ export type StrictShape<Shape, Value extends Shape> = Value & Record<Exclude<keyof Value, keyof Shape>, never>;
4
+ export type Thenable<T> = T | Promise<T>;
5
+ export type MonkeyMode = 'serve' | 'build' | 'meta';
6
+ export type ResolveConfigOptions = {
7
+ root?: string;
8
+ };
9
+ export type ResolveInjectionOptions = {
10
+ root?: string;
11
+ source?: ResolvedSourceConfig;
12
+ injector?: ResolvedInjectorConfig;
13
+ moduleId?: string;
14
+ moduleDir?: string;
15
+ componentPath?: string;
16
+ overridePath?: string;
17
+ fallbackName?: string;
18
+ index?: number;
19
+ };
20
+ export type MonkeyGenerateContext = {
21
+ userscript: string;
22
+ mode: MonkeyMode;
23
+ };
24
+ export type MonkeyServerConfig = {
25
+ open?: boolean;
26
+ prefix?: string | ((name: string) => string) | false;
27
+ };
28
+ export type MonkeyBuildConfig = {
29
+ fileName?: string;
30
+ metaFileName?: string | boolean | ((fileName: string) => string);
31
+ externalGlobals?: ExternalGlobals;
32
+ autoGrant?: boolean;
33
+ externalResource?: ExternalResource;
34
+ systemjs?: 'inline' | ((version: string, packageName: string, importName?: string, resolveName?: string) => string);
35
+ cssSideEffects?: string | ((css: string) => void);
36
+ };
37
+ export type MonkeyConfig = {
38
+ userscript?: MonkeyUserScript;
39
+ align?: number | false;
40
+ generate?: (options: MonkeyGenerateContext) => Thenable<string>;
41
+ styleImport?: boolean;
42
+ server?: MonkeyServerConfig;
43
+ build?: MonkeyBuildConfig;
44
+ };
45
+ export type AppConfig = {
46
+ name: string;
47
+ version: string;
48
+ description?: string;
49
+ };
50
+ export type SourceConfig = {
51
+ include?: string[];
52
+ exclude?: string[];
53
+ };
54
+ export type RuntimeConfig = {
55
+ setup?: string | string[];
56
+ };
57
+ export type ResolvedRuntimeConfig = {
58
+ setup: string[];
59
+ };
60
+ export type ResolvedSourceConfig = {
61
+ dir: string;
62
+ include: string[];
63
+ exclude: string[];
64
+ manifest: string;
65
+ };
66
+ export type InjectorConfig = Partial<Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout' | 'hooks'>>;
67
+ export type ResolvedInjectorConfig = Pick<RuntimeInjectionConfig, 'alive' | 'scope' | 'timeout'> & {
68
+ hooks?: LifecycleHookMap;
69
+ };
70
+ export type InjectionFramework = 'auto' | 'Vue' | 'React';
71
+ export type ResolvedInjectionFramework = Exclude<InjectionFramework, 'auto'>;
72
+ export type InjectionMatchObject = {
73
+ include?: string[];
74
+ exclude?: string[];
75
+ };
76
+ export type InjectionMatchConfig = string[] | InjectionMatchObject;
77
+ export type InjectionModuleConfig = ArtifactOptions & {
78
+ name?: string;
79
+ injectAt: string;
80
+ component: string;
81
+ framework?: InjectionFramework;
82
+ enabled?: boolean;
83
+ match?: InjectionMatchConfig;
84
+ };
85
+ export type InjectionManifestRecord = Record<string, Omit<InjectionModuleConfig, 'name'>>;
86
+ export type InjectionManifest = {
87
+ globalInjector?: InjectorConfig;
88
+ injections: InjectionModuleConfig[] | InjectionManifestRecord;
89
+ };
90
+ export type ResolvedInjectionManifest = InjectionModuleConfig[];
91
+ export type ResolvedInjectionModule = Omit<InjectionModuleConfig, 'name' | 'component' | 'framework' | 'enabled' | 'alive' | 'scope' | 'timeout'> & {
92
+ moduleId: string;
93
+ componentPath: string;
94
+ framework: ResolvedInjectionFramework;
95
+ moduleDir: string;
96
+ overridePath?: string;
97
+ enabled: boolean;
98
+ alive: ResolvedInjectorConfig['alive'];
99
+ scope: ResolvedInjectorConfig['scope'];
100
+ timeout: ResolvedInjectorConfig['timeout'];
101
+ match?: InjectionMatchObject;
102
+ };
103
+ export type ResolvedMonkeyServerConfig = {
104
+ open: boolean;
105
+ prefix: string | ((name: string) => string) | false;
106
+ mountGmApi: boolean;
107
+ };
108
+ export type ResolvedMonkeyBuildConfig = {
109
+ fileName: string;
110
+ metaFileName: string | false;
111
+ externalGlobals?: MonkeyBuildConfig['externalGlobals'];
112
+ autoGrant: boolean;
113
+ externalResource?: MonkeyBuildConfig['externalResource'];
114
+ systemjs?: MonkeyBuildConfig['systemjs'];
115
+ cssSideEffects?: MonkeyBuildConfig['cssSideEffects'];
116
+ };
117
+ export type ResolvedMonkeyConfig = Omit<MonkeyConfig, 'userscript' | 'align' | 'styleImport' | 'server' | 'build'> & {
118
+ userscript: MonkeyUserScript;
119
+ align: number | false;
120
+ clientAlias: string;
121
+ styleImport: boolean;
122
+ server: ResolvedMonkeyServerConfig;
123
+ build: ResolvedMonkeyBuildConfig;
124
+ };
125
+ export type CliConfig = {
126
+ app: AppConfig;
127
+ monkey?: MonkeyConfig;
128
+ source?: SourceConfig;
129
+ injector?: InjectorConfig;
130
+ runtime?: RuntimeConfig;
131
+ };
132
+ export type ResolvedConfig = {
133
+ root: string;
134
+ app: AppConfig;
135
+ monkey: ResolvedMonkeyConfig;
136
+ source: ResolvedSourceConfig;
137
+ injector: ResolvedInjectorConfig;
138
+ runtime: ResolvedRuntimeConfig;
139
+ };
140
+ export type MonkeyUserscriptOption = NonNullable<MonkeyOption['userscript']>;
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ export declare const CliConfigSchema: z.ZodObject<{
3
+ app: z.ZodObject<{
4
+ name: z.ZodString;
5
+ version: z.ZodString;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strip>;
8
+ monkey: z.ZodOptional<z.ZodObject<{
9
+ server: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
10
+ }, z.core.$loose>>;
11
+ source: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
12
+ injector: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
13
+ runtime: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
14
+ }, z.core.$strip>;
15
+ export declare function validateCliConfig(data: unknown): asserts data is z.infer<typeof CliConfigSchema>;
@@ -0,0 +1,46 @@
1
+ import { MakooError, MakooIssue } from '../../../../../core';
2
+ export interface ValidationIssue {
3
+ code: string;
4
+ path: PropertyKey[];
5
+ message: string;
6
+ }
7
+ export declare class ModuleAlreadyExistsError extends MakooError {
8
+ constructor(message: string, code?: string, cause?: Error);
9
+ }
10
+ export declare class LoadViteMakooConfigError extends MakooError {
11
+ constructor(message: string, code: string, cause?: Error);
12
+ }
13
+ export declare class RuntimeSetupNotFoundError extends MakooError {
14
+ constructor(file: string, code?: string, cause?: Error);
15
+ }
16
+ export declare class ManifestValidationError extends MakooError {
17
+ constructor(file: string, zodIssues: ValidationIssue[], code?: string, cause?: Error);
18
+ }
19
+ export declare class ConfigValidationError extends MakooError {
20
+ constructor(issues: MakooIssue[], code?: string, cause?: Error);
21
+ }
22
+ export declare class UnknownFrameworkError extends MakooError {
23
+ constructor(componentPath: string, code?: string, cause?: Error);
24
+ }
25
+ export declare class ComponentNotFoundError extends MakooError {
26
+ constructor(injectionName: string, code?: string, cause?: Error);
27
+ }
28
+ export declare class UnsupportedFrameworkGenerationError extends MakooError {
29
+ constructor(ext: string, code?: string, cause?: Error);
30
+ }
31
+ export declare class SourceDirNotFoundError extends MakooError {
32
+ constructor(dir: string, code?: string, cause?: Error);
33
+ }
34
+ export declare class ManifestNotFoundError extends MakooError {
35
+ constructor(dir: string, code?: string, cause?: Error);
36
+ }
37
+ export declare class ManifestLoadError extends MakooError {
38
+ constructor(path: string, code?: string, cause?: Error);
39
+ }
40
+ export declare class ModuleManifestLoadError extends MakooError {
41
+ constructor(path: string, code?: string, cause?: Error);
42
+ }
43
+ export declare class NoEnabledInjectionsError extends MakooError {
44
+ constructor(code?: string, cause?: Error);
45
+ }
46
+ export declare function toMakooIssue(issue: ValidationIssue): MakooIssue;
@@ -0,0 +1,3 @@
1
+ import { ScannerResult } from '../scanner/types';
2
+ import { GeneratorResult } from './types';
3
+ export declare function generate(sannerResult: ScannerResult): GeneratorResult;
@@ -0,0 +1,3 @@
1
+ import { ResolvedInjectionModule } from '../../../config/types';
2
+ import { RenderImportResult } from '../../types';
3
+ export declare function renderImportAdapter(injections: ResolvedInjectionModule[]): RenderImportResult;
@@ -0,0 +1,3 @@
1
+ import { ResolvedInjectionModule } from '../../../config/types';
2
+ import { RenderImportCompResult } from '../../types';
3
+ export declare function renderImportComp(injections: ResolvedInjectionModule[]): RenderImportCompResult;
@@ -0,0 +1 @@
1
+ export declare function renderImportInjector(): string;
@@ -0,0 +1 @@
1
+ export declare function renderRuntimeSetupImport(setup: string[]): string;
@@ -0,0 +1,3 @@
1
+ import { ResolvedInjectorConfig } from '../../../config/types';
2
+ import { RenderInitResult } from '../../types';
3
+ export declare function renderInitInjector(frameworks: string[], globlaConfig: ResolvedInjectorConfig): RenderInitResult;
@@ -0,0 +1,2 @@
1
+ import { Component, RenderInitResult } from '../../../generator/types';
2
+ export declare function renderRegisterComponent(instanceName: string, components: Component[]): RenderInitResult;
@@ -0,0 +1 @@
1
+ export declare function renderInjectorRun(instanceName: string): string;
@@ -0,0 +1 @@
1
+ export declare const renderInlineValue: (value: unknown) => string;
@@ -0,0 +1,21 @@
1
+ import { ResolvedInjectionModule } from '../config/types';
2
+ export type RenderImportResult = {
3
+ code: string;
4
+ importsName: string[];
5
+ };
6
+ export type Component = {
7
+ code: string;
8
+ componentName: string;
9
+ componentMeta: ResolvedInjectionModule;
10
+ };
11
+ export type RenderImportCompResult = Omit<RenderImportResult, 'importsName'> & {
12
+ component: Component[];
13
+ };
14
+ export type RenderInitResult = {
15
+ code: string;
16
+ instanceName: string;
17
+ };
18
+ export type GeneratorResult = {
19
+ code: string;
20
+ instanceName: string;
21
+ };