Skip to content

Commit

Permalink
Build the zip artifact in dist/ instead of dist/[browser] (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto authored Jun 29, 2024
1 parent 21ee28f commit 815371b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 11 additions & 10 deletions programs/cli/spec/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ╚═════╝╚══════╝╚═╝

import path from 'path'
import fs from 'fs'
import {ALL_TEMPLATES, DEFAULT_TEMPLATE, BROWSERS} from './fixtures/constants'
import {
extensionProgram,
Expand Down Expand Up @@ -93,22 +94,26 @@ describe('extension build', () => {
`builds and zips the source files of an extension created via "$name" template`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)
const outputPath = path.join(
__dirname,
'fixtures',
template.name,
'dist'
)

await extensionProgram(`build ${extensionPath} --zip-source`)

expect(
distFileExists(
template.name,
BROWSERS[0],
`${template.name}-1.0-source.zip`
fs.existsSync(
path.join(outputPath, `${template.name}-1.0-source.zip`)
)
).toBeTruthy()
},
50000
)

it.each([DEFAULT_TEMPLATE])(
`builds and zips the source files of an extension created via "$name" template with a custom output name using the --zip-filename flag`,
`builds and zips the distribution files of an extension created via "$name" template with a custom output name using the --zip-filename flag`,
async (template) => {
const extensionPath = path.join(__dirname, 'fixtures', template.name)

Expand All @@ -117,11 +122,7 @@ describe('extension build', () => {
)

expect(
distFileExists(
template.name,
BROWSERS[0],
`${template.name}-nice.zip`
)
distFileExists(template.name, BROWSERS[0], `${template.name}-nice.zip`)
).toBeTruthy()
},
50000
Expand Down
7 changes: 5 additions & 2 deletions programs/develop/steps/generateZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ export default function generateZip(
{browser = 'chrome', ...options}: BuildOptions
) {
try {
const outputDir = path.join(projectDir, 'dist', browser)
const distDir = path.join(projectDir, 'dist')
const outputDir = path.join(distDir, browser)
// We collect data from the projectDir if the user wants to zip the source files.
const dataDir = options.zipSource ? projectDir : outputDir
const manifest: Record<string, string> = require(
path.join(dataDir, 'manifest.json')
)
const name = getPackageName(manifest, options)
const ext = getExtensionExtension(browser)
// Dist zips are stored in dist/[browser]/[name].zip
const distZipPath = path.join(outputDir, `${name}.${ext}`)
const sourceZipPath = path.join(outputDir, `${name}-source.${ext}`)
// Source zips are stored in dist/[name]-source.zip
const sourceZipPath = path.join(distDir, `${name}-source.${ext}`)
const capitalizedBrowser = capitalizeBrowserName(browser)

if (options.zipSource) {
Expand Down

0 comments on commit 815371b

Please sign in to comment.