sammi-next 1.4.2 → 1.5.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/README.md +12 -4
- package/bin/sammi-next.mjs +3 -0
- package/dist/node/cli.mjs +324 -2
- package/dist/node/cli.mjs.map +1 -1
- package/dist/runtime/{index.d.mts → index.d.ts} +35 -4
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/{index.mjs → index.js} +5 -22
- package/dist/runtime/index.js.map +1 -0
- package/dist/shared/{config-types.d.mts → config-types.d.ts} +3 -2
- package/dist/shared/{config-types.d.mts.map → config-types.d.ts.map} +1 -1
- package/dist/shared/{config-types.mjs → config-types.js} +3 -2
- package/dist/shared/config-types.js.map +1 -0
- package/package.json +14 -10
- package/dist/build-CZcDZxfX.mjs +0 -170
- package/dist/build-CZcDZxfX.mjs.map +0 -1
- package/dist/global-BaL6-Y6j.d.mts +0 -349
- package/dist/global-BaL6-Y6j.d.mts.map +0 -1
- package/dist/node/build.d.mts +0 -20
- package/dist/node/build.d.mts.map +0 -1
- package/dist/node/build.mjs +0 -3
- package/dist/node/config.d.mts +0 -11
- package/dist/node/config.d.mts.map +0 -1
- package/dist/node/config.mjs +0 -164
- package/dist/node/config.mjs.map +0 -1
- package/dist/runtime/index.d.mts.map +0 -1
- package/dist/runtime/index.mjs.map +0 -1
- package/dist/shared/config-types.mjs.map +0 -1
package/dist/node/config.mjs
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { i as DEFAULT_CONFIG_EXTENSIONS, n as BuildModes } from "../build-CZcDZxfX.mjs";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import Ajv from "ajv";
|
|
5
|
-
|
|
6
|
-
//#region src/node/config.ts
|
|
7
|
-
const ajv = new Ajv();
|
|
8
|
-
ajv.addKeyword({
|
|
9
|
-
keyword: "fileExists",
|
|
10
|
-
validate: (_schema, data) => {
|
|
11
|
-
if (!data) return true;
|
|
12
|
-
return fs.existsSync(data);
|
|
13
|
-
},
|
|
14
|
-
errors: false
|
|
15
|
-
});
|
|
16
|
-
const configValidator = ajv.compile({
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {
|
|
19
|
-
id: {
|
|
20
|
-
type: "string",
|
|
21
|
-
minLength: 1,
|
|
22
|
-
pattern: "^[a-zA-Z0-9-_]+$"
|
|
23
|
-
},
|
|
24
|
-
name: {
|
|
25
|
-
type: "string",
|
|
26
|
-
minLength: 1,
|
|
27
|
-
pattern: "^[a-zA-Z0-9 -_]+$"
|
|
28
|
-
},
|
|
29
|
-
info: {
|
|
30
|
-
type: "string",
|
|
31
|
-
default: "",
|
|
32
|
-
nullable: true
|
|
33
|
-
},
|
|
34
|
-
version: {
|
|
35
|
-
type: "string",
|
|
36
|
-
minLength: 1,
|
|
37
|
-
pattern: "^\\d+(?:\\.\\d+)*(?:-.*)?$"
|
|
38
|
-
},
|
|
39
|
-
entry: {
|
|
40
|
-
type: "string",
|
|
41
|
-
minLength: 1,
|
|
42
|
-
fileExists: true
|
|
43
|
-
},
|
|
44
|
-
external: {
|
|
45
|
-
type: "string",
|
|
46
|
-
minLength: 1,
|
|
47
|
-
fileExists: true,
|
|
48
|
-
nullable: true
|
|
49
|
-
},
|
|
50
|
-
over: {
|
|
51
|
-
type: "string",
|
|
52
|
-
minLength: 1,
|
|
53
|
-
fileExists: true,
|
|
54
|
-
nullable: true
|
|
55
|
-
},
|
|
56
|
-
out: {
|
|
57
|
-
type: "object",
|
|
58
|
-
properties: {
|
|
59
|
-
dir: {
|
|
60
|
-
type: "string",
|
|
61
|
-
minLength: 1,
|
|
62
|
-
pattern: "^[^<>:\"|?*]+$",
|
|
63
|
-
default: "dist",
|
|
64
|
-
nullable: true
|
|
65
|
-
},
|
|
66
|
-
js: {
|
|
67
|
-
type: "string",
|
|
68
|
-
minLength: 4,
|
|
69
|
-
pattern: "^[\\w\\-. ]+\\.js$",
|
|
70
|
-
default: "extension.js",
|
|
71
|
-
nullable: true
|
|
72
|
-
},
|
|
73
|
-
sef: {
|
|
74
|
-
type: "string",
|
|
75
|
-
minLength: 5,
|
|
76
|
-
pattern: "^[\\w\\-. ]+\\.sef$",
|
|
77
|
-
default: "extension.sef",
|
|
78
|
-
nullable: true
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
required: [],
|
|
82
|
-
nullable: true,
|
|
83
|
-
additionalProperties: false
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
required: [
|
|
87
|
-
"name",
|
|
88
|
-
"id",
|
|
89
|
-
"version",
|
|
90
|
-
"entry"
|
|
91
|
-
],
|
|
92
|
-
additionalProperties: false
|
|
93
|
-
});
|
|
94
|
-
async function loadConfig(rootDir) {
|
|
95
|
-
for (const ext of DEFAULT_CONFIG_EXTENSIONS) {
|
|
96
|
-
const configPath = path.join(rootDir, `sammi.config${ext}`);
|
|
97
|
-
if (!fs.existsSync(configPath)) continue;
|
|
98
|
-
try {
|
|
99
|
-
const { createJiti } = await import("jiti");
|
|
100
|
-
return validateExtensionConfig(await createJiti(rootDir, {
|
|
101
|
-
interopDefault: true,
|
|
102
|
-
moduleCache: true
|
|
103
|
-
}).import(configPath, { default: true }), configPath);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
throw new Error(`Error loading ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const jsonPath = path.join(rootDir, "sammi.config.json");
|
|
109
|
-
if (fs.existsSync(jsonPath)) try {
|
|
110
|
-
const raw = fs.readFileSync(jsonPath, "utf-8");
|
|
111
|
-
return validateExtensionConfig(JSON.parse(raw), jsonPath);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
throw new Error(`Error loading ${jsonPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
114
|
-
}
|
|
115
|
-
throw new Error("SAMMI Next extension config file not found in the root dir.");
|
|
116
|
-
}
|
|
117
|
-
function validateExtensionConfig(config, configPath) {
|
|
118
|
-
if (!configValidator(config)) {
|
|
119
|
-
const errors = configValidator.errors?.map((err) => ` - ${err.instancePath} ${err.message}`).join("\n");
|
|
120
|
-
throw new Error(`Invalid config from ${configPath}:\n${errors}`);
|
|
121
|
-
}
|
|
122
|
-
return config;
|
|
123
|
-
}
|
|
124
|
-
function resolveExtensionConfig(config, rootDir) {
|
|
125
|
-
const resolved = {
|
|
126
|
-
id: config.id,
|
|
127
|
-
name: config.name,
|
|
128
|
-
version: config.version,
|
|
129
|
-
info: config.info || "",
|
|
130
|
-
entry: path.resolve(rootDir, config.entry),
|
|
131
|
-
external: config.external ? path.resolve(rootDir, config.external) : "",
|
|
132
|
-
over: config.over ? path.resolve(rootDir, config.over) : "",
|
|
133
|
-
out: {
|
|
134
|
-
dir: config.out?.dir || "dist",
|
|
135
|
-
js: config.out?.js || "extension.js",
|
|
136
|
-
sef: config.out?.sef || "extension.sef"
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
if (!fs.existsSync(resolved.entry)) throw new Error(`Entry file not found: ${resolved.entry}`);
|
|
140
|
-
if (resolved.external && !fs.existsSync(resolved.external)) throw new Error(`External file not found: ${resolved.external}`);
|
|
141
|
-
if (resolved.over && !fs.existsSync(resolved.over)) throw new Error(`Over file not found: ${resolved.over}`);
|
|
142
|
-
return resolved;
|
|
143
|
-
}
|
|
144
|
-
async function resolveBuildConfig(root, command, build_cli) {
|
|
145
|
-
const mode = BuildModes.findIndex((m) => {
|
|
146
|
-
return m.toLowerCase() === command.toLowerCase();
|
|
147
|
-
});
|
|
148
|
-
if (mode < 0) throw new Error(`Invalid mode: ${command}. It must be one of: ${BuildModes.join(", ")}`);
|
|
149
|
-
const rootDir = root ?? process.cwd();
|
|
150
|
-
const config = await loadConfig(rootDir);
|
|
151
|
-
config.out ??= {};
|
|
152
|
-
config.out.dir = build_cli.outDir ?? config.out.dir;
|
|
153
|
-
config.out.js = build_cli.outJs ?? config.out.js;
|
|
154
|
-
config.out.sef = build_cli.outSef ?? config.out.sef;
|
|
155
|
-
return {
|
|
156
|
-
rootDir,
|
|
157
|
-
mode,
|
|
158
|
-
config: resolveExtensionConfig(config, rootDir)
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
//#endregion
|
|
163
|
-
export { loadConfig, resolveBuildConfig, resolveExtensionConfig };
|
|
164
|
-
//# sourceMappingURL=config.mjs.map
|
package/dist/node/config.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/node/config.ts"],"sourcesContent":["\n\nimport { ExtensionConfig, ResolvedExtensionConfig } from \"@shared/config-types\";\nimport Ajv, { JSONSchemaType } from \"ajv\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { DEFAULT_CONFIG_EXTENSIONS } from \"./constants\";\nimport { BuildCLIOptions } from \"./cli\";\nimport { BuildModes, ResolvedBuildOptions } from \"./build\";\n\nconst ajv = new Ajv();\n\najv.addKeyword({\n keyword: \"fileExists\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n validate: (_schema: any, data: any) => {\n if (!data) return true;\n\n return fs.existsSync(data as string);\n },\n errors: false\n});\n\nconst schema: JSONSchemaType<ExtensionConfig> = {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[a-zA-Z0-9-_]+$\",\n },\n name: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[a-zA-Z0-9 -_]+$\",\n },\n info: {\n type: \"string\",\n default: \"\",\n nullable: true,\n },\n version: {\n type: \"string\",\n minLength: 1,\n pattern: \"^\\\\d+(?:\\\\.\\\\d+)*(?:-.*)?$\",\n },\n entry: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n },\n external: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n nullable: true,\n },\n over: {\n type: \"string\",\n minLength: 1,\n fileExists: true,\n nullable: true,\n },\n out: {\n type: \"object\",\n properties: {\n dir: {\n type: \"string\",\n minLength: 1,\n pattern: \"^[^<>:\\\"|?*]+$\",\n default: \"dist\",\n nullable: true,\n },\n js: {\n type: \"string\",\n minLength: 4,\n pattern: \"^[\\\\w\\\\-. ]+\\\\.js$\",\n default: \"extension.js\",\n nullable: true,\n },\n sef: {\n type: \"string\",\n minLength: 5,\n pattern: \"^[\\\\w\\\\-. ]+\\\\.sef$\",\n default: \"extension.sef\",\n nullable: true,\n }\n },\n required: [],\n nullable: true,\n additionalProperties: false,\n }\n },\n required: [\"name\", \"id\", \"version\", \"entry\"],\n additionalProperties: false,\n};\n\nconst configValidator = ajv.compile(schema);\n\nexport async function loadConfig(rootDir: string) {\n for (const ext of DEFAULT_CONFIG_EXTENSIONS) {\n const configPath = path.join(rootDir, `sammi.config${ext}`);\n\n if (!fs.existsSync(configPath)) continue;\n\n try {\n const { createJiti } = await import('jiti');\n const jiti = createJiti(rootDir, {\n interopDefault: true,\n moduleCache: true,\n });\n\n const config = await jiti.import(configPath, { default: true });\n\n return validateExtensionConfig(config, configPath);\n } catch (error) {\n throw new Error(`Error loading ${configPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n const jsonPath = path.join(rootDir, 'sammi.config.json');\n if (fs.existsSync(jsonPath)) {\n try {\n const raw = fs.readFileSync(jsonPath, 'utf-8');\n const config = JSON.parse(raw) as unknown;\n return validateExtensionConfig(config, jsonPath);\n } catch (error) {\n throw new Error(`Error loading ${jsonPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n throw new Error('SAMMI Next extension config file not found in the root dir.');\n}\n\n\nfunction validateExtensionConfig(config: unknown, configPath: string): ExtensionConfig {\n if (!configValidator(config)) {\n const errors = configValidator.errors?.map(err => ` - ${err.instancePath} ${err.message}`).join('\\n');\n throw new Error(`Invalid config from ${configPath}:\\n${errors}`);\n }\n\n return config;\n}\n\nexport function resolveExtensionConfig(config: ExtensionConfig, rootDir: string): ResolvedExtensionConfig {\n const resolved: ResolvedExtensionConfig = {\n id: config.id,\n name: config.name,\n version: config.version,\n info: config.info || '',\n entry: path.resolve(rootDir, config.entry),\n external: config.external ? path.resolve(rootDir, config.external) : '',\n over: config.over ? path.resolve(rootDir, config.over) : '',\n out: {\n dir: config.out?.dir || 'dist',\n js: config.out?.js || 'extension.js',\n sef: config.out?.sef || 'extension.sef',\n },\n };\n\n if (!fs.existsSync(resolved.entry))\n throw new Error(`Entry file not found: ${resolved.entry}`);\n\n if (resolved.external && !fs.existsSync(resolved.external))\n throw new Error(`External file not found: ${resolved.external}`);\n\n if (resolved.over && !fs.existsSync(resolved.over))\n throw new Error(`Over file not found: ${resolved.over}`);\n\n return resolved;\n}\n\nexport async function resolveBuildConfig(\n root: string | undefined,\n command: string,\n build_cli: BuildCLIOptions,\n) {\n const mode = BuildModes.findIndex(m => {\n return m.toLowerCase() === command.toLowerCase();\n });\n if (mode < 0)\n throw new Error(`Invalid mode: ${command}. It must be one of: ${BuildModes.join(', ')}`);\n\n const rootDir = root ?? process.cwd();\n const config = await loadConfig(rootDir);\n\n config.out ??= {};\n\n config.out.dir = build_cli.outDir ?? config.out.dir;\n config.out.js = build_cli.outJs ?? config.out.js;\n config.out.sef = build_cli.outSef ?? config.out.sef;\n\n const resolvedConfig = resolveExtensionConfig(config, rootDir);\n\n const resolved: ResolvedBuildOptions = {\n rootDir,\n mode,\n config: resolvedConfig\n }\n return resolved;\n}\n"],"mappings":";;;;;;AAUA,MAAM,MAAM,IAAI,KAAK;AAErB,IAAI,WAAW;CACX,SAAS;CAET,WAAW,SAAc,SAAc;AACnC,MAAI,CAAC,KAAM,QAAO;AAElB,SAAO,GAAG,WAAW,KAAe;;CAExC,QAAQ;CACX,CAAC;AA4EF,MAAM,kBAAkB,IAAI,QA1EoB;CAC5C,MAAM;CACN,YAAY;EACR,IAAI;GACA,MAAM;GACN,WAAW;GACX,SAAS;GACZ;EACD,MAAM;GACF,MAAM;GACN,WAAW;GACX,SAAS;GACZ;EACD,MAAM;GACF,MAAM;GACN,SAAS;GACT,UAAU;GACb;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MAAM,iBAAiB,QAAQ,uBAAuB,WAAW,KAAK,KAAK,GAAG;CAE5F,MAAM,UAAU,QAAQ,QAAQ,KAAK;CACrC,MAAM,SAAS,MAAM,WAAW,QAAQ;AAExC,QAAO,QAAQ,EAAE;AAEjB,QAAO,IAAI,MAAM,UAAU,UAAU,OAAO,IAAI;AAChD,QAAO,IAAI,KAAK,UAAU,SAAS,OAAO,IAAI;AAC9C,QAAO,IAAI,MAAM,UAAU,UAAU,OAAO,IAAI;AAShD,QALuC;EACnC;EACA;EACA,QALmB,uBAAuB,QAAQ,QAAQ;EAM7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":";;;;UAOU,oBAAA;EAAA;;;;;AA2BV;;EAnBI,YAAA;AAAA;;;;;;;;;;;;AAgFJ;;;iBA7DgB,aAAA,CAEZ,MAAA,EAAQ,MAAA,eACR,OAAA,GAAS,oBAAA,GAGV,eAAA;;AAyDF;;;;;AA4DD;;;;;;;iBA9DgB,kBAAA,CAAmB,YAAA,WAAuB,cAAA;AAAA,UAIhD,2BAAA;;;;;;;;EAQN,kBAAA;;;;;;;EAOA,sBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CY,oBAAA,CACZ,QAAA,cACA,OAAA,GAAS,2BAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import \"sammi-bridge-types\";\nimport \"./global.d.ts\";\nimport { ExtensionConfig } from \"./types\";\n\n\nconst PROXY_PREFIX = \"[SAMMI-NEXT-PROXY]\";\n\ninterface initExtensionOptions {\n /**\n * Whether to skip the process of proxying your extension.\n *\n * Warning: this allows other scripts to modify your exports.\n *\n * @default false\n */\n skipProxying?: boolean\n}\nconst defaultInitExtensionOptions: initExtensionOptions = {\n skipProxying: false,\n}\n/**\n * Removes unnecessary data from a raw extension config object and parses it into an ExtensionConfig.\n *\n * Exports the config through the `SAMMIExtensions` namespace with the `_config` key.\n *\n * Generates a Proxy of the extension object to avoid other scripts trying to overwrite it.\n *\n * @example\n * const extension_config = SAMMIExtensions['extension-id']._config;\n *\n * @param config Unparsed config object.\n * @param options Whether to skip the process of proxying your extension (allowing other scripts to modify your exports).\n * @returns Parsed and cleaned config.\n */\nexport function initExtension(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config: Record<string, any>,\n options: initExtensionOptions = {\n skipProxying: false,\n }\n): ExtensionConfig {\n let response: ExtensionConfig = {\n id: config.id as string,\n name: config.name as string,\n version: config.version as string,\n info: config.info as string | undefined,\n };\n\n window.SAMMIExtensions = window.SAMMIExtensions || {};\n SAMMIExtensions[response.id] = SAMMIExtensions[response.id] || {};\n if (SAMMIExtensions[response.id]?._config)\n throw new Error('The extension with the provided id was already initialized');\n\n const settings = Object.assign(defaultInitExtensionOptions, options);\n if (!settings.skipProxying)\n response = Object.freeze(response);\n\n // @ts-expect-error This is before proxying the extension, so no error.\n SAMMIExtensions[response.id]!._config ??= response;\n if (settings.skipProxying) return response;\n\n SAMMIExtensions[response.id] = new Proxy(SAMMIExtensions[response.id]!, {\n set(target, prop) {\n console.error(PROXY_PREFIX, \": Blocked setting value of:\", prop, \"on:\", target._config?.id);\n return true;\n },\n defineProperty(target, property) {\n console.error(PROXY_PREFIX, \": Blocked property redefinition of:\", property, \"on:\", target._config?.id);\n return true;\n },\n deleteProperty(target, p) {\n console.error(PROXY_PREFIX, \": Blocked deletion of:\", p, \"on:\", target._config?.id);\n return true;\n },\n setPrototypeOf(target) {\n console.error(PROXY_PREFIX, \": Blocked changing prototype of:\", target._config?.id);\n return true;\n },\n });\n return response;\n}\n\n/**\n * Retrieves an [insert_external] section by its extension id.\n *\n * ### Original documentation from https://sammi.solutions/extensions/build\n * This section appears inside the extension’s tab in Bridge, and it provides a visual interface for the extension if needed. It’s written in HTML and CSS.\n *\n * @example\n * const EXTERNAL = getExternalSection(config.id);\n * EXTERNAL.querySelector(\"button\")?.addEventListener('click', () => console.log('Hello world!'));\n *\n * @param extension_id The id of the SAMMI Next extension to retrieve its [insert_external] section.\n * @returns the div element that wraps your extension.\n */\nexport function getExternalSection(extension_id: string): HTMLDivElement {\n return document.getElementById(`${extension_id}-external`) as HTMLDivElement;\n}\n\ninterface insertCommandSectionOptions {\n /**\n * Whether to wait for `sammiclient` to exist.\n * This is enabled by default because every extension that uses `SAMMI` depends on `sammiclient`.\n * You can disable it if your [insert_command] section doesn't use neither `SAMMI` nor `sammiclient`.\n *\n * @default true\n */\n waitForSammiclient?: boolean;\n /**\n * Whether to wait for `SAMMIExtensions` to exist.\n * You must set this to `true` if you use the `SAMMIExtensions` namespace inside your [insert_command] section.\n *\n * @default false\n */\n waitForSAMMIExtensions?: boolean;\n}\nconst defaultInsertCommandSectionOptions: insertCommandSectionOptions = {\n waitForSammiclient: true,\n waitForSAMMIExtensions: false,\n}\n/**\n * Generates your [insert_command] section.\n * This should be used in the default export of your extension.\n *\n * By default, it wraps your callback to wait for `sammiclient` and `SAMMI` are initialized.\n * Its behavior can be changed in the options param.\n *\n * ### Original documentation from https://sammi.solutions/extensions/build\n * In this section, you can define Extension Commands.\n * These commands will be available to users in SAMMI Core when they install your extension.\n * You can define multiple commands in this section.\n * Refer to the SAMMI Bridge documentation for Extension Command details.\n * In this section, you can also automatically call your main extension function that should run as soon as SAMMI connects to Bridge.\n *\n * @example\n * export default insertCommandSection(() => {\n * SAMMI.extCommand(\"Extension Sample Command\", 3355443, 52).catch(e => console.error(e));\n * sammiclient.on(\"Extension Sample Command\", () => {\n * const handler = async () => {\n * await SAMMI.notification('Command Sample');\n * };\n * handler().catch((e) => console.error(e));\n * });\n * });\n * export default insertCommandSection(\n * () => console.log(\"Hello world\"),\n * { waitForSammiclient: false }\n * );\n * export default insertCommandSection(\n * () => console.log(SAMMIExtensions[\"extension-id\"]),\n * { waitForSAMMIExtensions: true }\n * );\n *\n * @param callback A callback with the logic that you will insert in your [insert_command] section.\n * @param options The initialization options.\n * @returns wrapped export default callback\n */\nexport function insertCommandSection(\n callback: () => void,\n options: insertCommandSectionOptions = {\n waitForSammiclient: true,\n waitForSAMMIExtensions: false,\n },\n): () => void {\n const settings = Object.assign(defaultInsertCommandSectionOptions, options);\n\n const wrapper = () => {\n if (!sammiclient && settings.waitForSammiclient) {\n setTimeout(wrapper, 0);\n return;\n }\n\n if (!SAMMIExtensions && settings.waitForSAMMIExtensions) {\n setTimeout(wrapper, 0);\n return;\n }\n\n callback();\n };\n\n return wrapper;\n}\n\nexport type { SAMMINextExtension } from \"./types\";\nexport type { ExtensionConfig as FullExtensionConfig } from '@shared/config-types';\nexport type { ExtensionConfig };\n"],"mappings":";;;AAKA,MAAM,eAAe;AAYrB,MAAM,8BAAoD,EACtD,cAAc,OACjB;;;;;;;;;;;;;;;AAeD,SAAgB,cAEZ,QACA,UAAgC,EAC5B,cAAc,OACjB,EACc;CACf,IAAI,WAA4B;EAC5B,IAAI,OAAO;EACX,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,MAAM,OAAO;EAChB;AAED,QAAO,kBAAkB,OAAO,mBAAmB,EAAE;AACrD,iBAAgB,SAAS,MAAM,gBAAgB,SAAS,OAAO,EAAE;AACjE,KAAI,gBAAgB,SAAS,KAAK,QAC9B,OAAM,IAAI,MAAM,6DAA6D;CAEjF,MAAM,WAAW,OAAO,OAAO,6BAA6B,QAAQ;AACpE,KAAI,CAAC,SAAS,aACV,YAAW,OAAO,OAAO,SAAS;AAGtC,iBAAgB,SAAS,IAAK,YAAY;AAC1C,KAAI,SAAS,aAAc,QAAO;AAElC,iBAAgB,SAAS,MAAM,IAAI,MAAM,gBAAgB,SAAS,KAAM;EACpE,IAAI,QAAQ,MAAM;AACd,WAAQ,MAAM,cAAc,+BAA+B,MAAM,OAAO,OAAO,SAAS,GAAG;AAC3F,UAAO;;EAEX,eAAe,QAAQ,UAAU;AAC7B,WAAQ,MAAM,cAAc,uCAAuC,UAAU,OAAO,OAAO,SAAS,GAAG;AACvG,UAAO;;EAEX,eAAe,QAAQ,GAAG;AACtB,WAAQ,MAAM,cAAc,0BAA0B,GAAG,OAAO,OAAO,SAAS,GAAG;AACnF,UAAO;;EAEX,eAAe,QAAQ;AACnB,WAAQ,MAAM,cAAc,oCAAoC,OAAO,SAAS,GAAG;AACnF,UAAO;;EAEd,CAAC;AACF,QAAO;;;;;;;;;;;;;;;AAgBX,SAAgB,mBAAmB,cAAsC;AACrE,QAAO,SAAS,eAAe,GAAG,aAAa,WAAW;;AAoB9D,MAAM,qCAAkE;CACpE,oBAAoB;CACpB,wBAAwB;CAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,SAAgB,qBACZ,UACA,UAAuC;CACnC,oBAAoB;CACpB,wBAAwB;CAC3B,EACS;CACV,MAAM,WAAW,OAAO,OAAO,oCAAoC,QAAQ;CAE3E,MAAM,gBAAgB;AAClB,MAAI,CAAC,eAAe,SAAS,oBAAoB;AAC7C,cAAW,SAAS,EAAE;AACtB;;AAGJ,MAAI,CAAC,mBAAmB,SAAS,wBAAwB;AACrD,cAAW,SAAS,EAAE;AACtB;;AAGJ,YAAU;;AAGd,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-types.mjs","names":[],"sources":["../../src/shared/config-types.ts"],"sourcesContent":["\n/**\n * Represents the full extension config from sammi.config.ts.\n * Used by the CLI to build the extension.\n*/\nexport interface ExtensionConfig {\n /**\n * Specify a unique id for your extension here.\n * Please use alphanumeric characters, dashes, and underscores only.\n */\n id: string;\n\n /**\n * This section names your extension, and is visible in SAMMI Bridge and SAMMI Core.\n * Please use alphanumeric characters and spaces only.\n */\n name: string;\n\n /**\n * This section is for descriptive text about the extension, e.g. what the extension does.\n * This information is displayed to the users in SAMMI Bridge-Extensions tab when they hover\n * over the extension name inside the list of installed extensions.\n *\n * @default \"\"\n */\n info?: string;\n\n /**\n * Specify your extension version here, using numbers and dots (e.g., 2.01).\n * This is crucial for the automatic version checker in Bridge, which can notify users of updates.\n *\n * Note: the regex pattern used for validation is `^\\d+(?:\\.\\d+)*(?:-.*)?$`.\n * Although SAMMI Next allows beta/alpha suffixes due to its RegExp,\n * please note that the official SAMMI Bridge automatic version checker ignores them.\n * In other words, the users only will be notified of release updates.\n */\n version: string;\n\n /**\n * Specify your script.ts path here.\n * In your [insert_script] section, you’re encouraged to write your own TypeScript code.\n */\n entry: string;\n\n /**\n * Specify your external.html path here.\n * Your [insert_external] section appears inside the extension’s tab in Bridge,\n * and it provides a visual interface for the extension if needed. It’s written in HTML and CSS.\n *\n * @default undefined\n */\n external?: string;\n\n /**\n * Specify your over.json path here.\n * In your [insert_over] section you simply copy and paste your deck from SAMMI Core you wish to distribute with your extension.\n * When users install your extension, the deck will be automatically added to their SAMMI Core.\n *\n * @default undefined\n */\n over?: string;\n\n /** Configuration related with the extension building. */\n out?: {\n /**\n * The path where the extension will build to.\n *\n * @default \"dist\"\n */\n dir?: string;\n\n /**\n * The file name of the final JavaScript file.\n *\n * @default \"extension.js\"\n */\n js?: string;\n\n /**\n * The file name of the final SAMMI Extension File.\n *\n * @default \"extension.sef\"\n */\n sef?: string;\n }\n}\n\n/**\n * Helper function to define a SAMMI Next extension config with type safety.\n *\n * @example\n * ```ts\n * // sammi.config.mjs\n * import { defineConfig } from 'sammi-next/config';\n *\n * export default defineConfig({\n * id: 'my-extension',\n * name: 'My Extension',\n * version: '1.0.0',\n * entry: 'src/script.ts',\n * });\n * ```\n */\nexport function defineConfig(config: ExtensionConfig): ExtensionConfig {\n return config;\n}\n\n/**\n * Resolved extension config with defaults applied.\n * Used internally by the builder.\n * @internal\n */\nexport interface ResolvedExtensionConfig extends Required<Omit<ExtensionConfig, 'out'>> {\n out: Required<NonNullable<ExtensionConfig['out']>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuGA,SAAgB,aAAa,QAA0C;AACnE,QAAO"}
|