Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding package cmd #304

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions cli/plasmo/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { nextNewTab } from "~features/extra/next-new-tab"
import { createParcelBuilder } from "~features/helpers/create-parcel-bundler"
import { printHeader } from "~features/helpers/print"
import { createManifest } from "~features/manifest-factory/create-manifest"
import { zipBundle } from "~features/manifest-factory/zip"

async function build() {
printHeader()
Expand All @@ -29,8 +30,7 @@ async function build() {

const plasmoManifest = await createManifest(bundleConfig)

const { distDirectory, buildDirectory, distDirectoryName } =
plasmoManifest.commonPath
const { distDirectory } = plasmoManifest.commonPath

const bundler = await createParcelBuilder(plasmoManifest.commonPath, {
mode: "production",
Expand All @@ -54,23 +54,7 @@ async function build() {
await plasmoManifest.postBuild()

if (hasFlag("--zip")) {
const { default: archiver } = await import("archiver")
const zip = archiver("zip", {
zlib: { level: 9 }
})

const zipFilePath = resolve(buildDirectory, `${distDirectoryName}.zip`)

const output = createWriteStream(zipFilePath)
output.on("close", () => {
iLog(`Zip Package size: ${zip.pointer()} bytes`)
})

zip.pipe(output)

zip.directory(distDirectory, "")

await zip.finalize()
await zipBundle(plasmoManifest.commonPath)
}
}

Expand Down
22 changes: 22 additions & 0 deletions cli/plasmo/src/commands/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { iLog } from "@plasmo/utils/logging"

import { getBundleConfig } from "~features/extension-devtools/get-bundle-config"
import { printHeader } from "~features/helpers/print"
import { createManifest } from "~features/manifest-factory/create-manifest"
import { zipBundle } from "~features/manifest-factory/zip"

async function packageCmd() {
printHeader()

process.env.NODE_ENV = "production"

iLog("Prepare to package the extension bundle...")

const bundleConfig = getBundleConfig()

const plasmoManifest = await createManifest(bundleConfig)

await zipBundle(plasmoManifest.commonPath)
}

export default packageCmd
30 changes: 30 additions & 0 deletions cli/plasmo/src/features/manifest-factory/zip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createWriteStream } from "fs"
import { resolve } from "path"

import { iLog } from "@plasmo/utils/logging"

import type { CommonPath } from "~features/extension-devtools/common-path"

export const zipBundle = async ({
distDirectory,
buildDirectory,
distDirectoryName
}: CommonPath) => {
const { default: archiver } = await import("archiver")
const zipClient = archiver("zip", {
zlib: { level: 9 }
})

const zipFilePath = resolve(buildDirectory, `${distDirectoryName}.zip`)

const output = createWriteStream(zipFilePath)
output.on("close", () => {
iLog(`Zip Package size: ${zipClient.pointer()} bytes`)
})

zipClient.pipe(output)

zipClient.directory(distDirectory, "")

await zipClient.finalize()
}