From 47c07c32f386b31a8a86058f5a7f41126dd6df25 Mon Sep 17 00:00:00 2001 From: nakasyou Date: Fri, 8 Dec 2023 18:01:19 +0900 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E9=80=9F=E5=8C=96=E3=81=97=E3=81=9F..?= =?UTF-8?q?.=E3=81=AE=E3=81=8B=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/core/compile/mod.ts | 12 ++-- compiler/core/compile/transformer.ts | 82 ---------------------------- scripts/dev-compiler.ts | 2 +- 3 files changed, 9 insertions(+), 87 deletions(-) delete mode 100644 compiler/core/compile/transformer.ts diff --git a/compiler/core/compile/mod.ts b/compiler/core/compile/mod.ts index ef2f270..a28f2e6 100644 --- a/compiler/core/compile/mod.ts +++ b/compiler/core/compile/mod.ts @@ -48,6 +48,8 @@ export type CompileState = { state: 'ZIPING' } | { state: 'COMPILED' +} | { + state: 'READY' } export const compile = (chromeExtension: Extension, opts: CompilerInit): CompileResult => { @@ -74,7 +76,7 @@ export const compile = (chromeExtension: Extension, opts: CompilerInit): Compile } } const stateStream = new StateStream() - ;(async () => { + const run = async () => { const crxData = chromeExtension.getCrxData() nextStateFunc({ state: 'CRX_TO_ZIP' @@ -129,7 +131,6 @@ export const compile = (chromeExtension: Extension, opts: CompilerInit): Compile for (const plugin of plugins) { await plugin.onCompile(compileInit) } - fileTree['manifest.json'] = new TextEncoder().encode(JSON.stringify(manifestJson, null, 2)) nextStateFunc({ state: 'ZIPING' @@ -140,8 +141,11 @@ export const compile = (chromeExtension: Extension, opts: CompilerInit): Compile nextStateFunc({ state: 'COMPILED' }) - })() - + } + nextStateFunc({ + state: 'READY' + }) + run() return { compiled, stateStream: stateStream diff --git a/compiler/core/compile/transformer.ts b/compiler/core/compile/transformer.ts deleted file mode 100644 index 66c31d4..0000000 --- a/compiler/core/compile/transformer.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { z } from 'npm:zod' - -interface Manifest2 { - browser_specific_settings?: { - gecko?: { - id?: string - strict_min_version?: string - } - } - background?: { - scripts?: string[] - service_worker?: string - } - commands?: Record -} -const Manifest3 = z.object({ - browser_specific_settings: z.object({ - gecko: z.object({ - id: z.string(), - strict_min_version: z.string() - }) - }), - background: z.object({ - scripts: z.array(z.string()) - }), - commands: z.record(z.object({ - suggested_key: z.object({ - default: z.string().optional() - }) - })) -}) -type Manifest3 = z.infer - -// todo: リファクタリング -export const transformManifest = (manifest: Manifest2): Manifest3 => { - // browser_specific_settingsを埋める - if (!manifest.browser_specific_settings) { - manifest.browser_specific_settings = {} - } - if (!manifest.browser_specific_settings.gecko) { - manifest.browser_specific_settings.gecko = {} - } - if (!manifest.browser_specific_settings.gecko.id) { - manifest.browser_specific_settings.gecko.id = "example@example.com" - } - if (!manifest.browser_specific_settings.gecko.strict_min_version) { - manifest.browser_specific_settings.gecko.strict_min_version = "42.0" - } - - if (!manifest.background) { - manifest.background = {} - } - if (!manifest.background.scripts) { - manifest.background.scripts = [] - } - if (manifest.background.service_worker) { - manifest.background.scripts.push(manifest.background.service_worker) - manifest.background.service_worker = undefined - } - - if (!manifest.commands) { - manifest.commands = {} - } - for (const [key, value] of Object.entries(manifest.commands)) { - if (typeof value.suggested_key === "string") { - value.suggested_key = { - default: value.suggested_key - } - } - if (!value.suggested_key) { - value.suggested_key = {} - } - - manifest.commands[key] = value - } - - return manifest as Manifest3 -} diff --git a/scripts/dev-compiler.ts b/scripts/dev-compiler.ts index 236a4c4..e3e5d64 100644 --- a/scripts/dev-compiler.ts +++ b/scripts/dev-compiler.ts @@ -42,7 +42,7 @@ for await (const state of compileProcess.stateStream) { console.timeEnd('state') const xpiData = await compileProcess.compiled - +console.log(xpiData) await Deno.writeFile(join('tmp', Deno.args[0] + '.xpi'), xpiData) await emptyDir(join('tmp', Deno.args[0])) for (const [path, data] of Object.entries(unzipSync(xpiData))) {