Skip to content

Commit

Permalink
Merge pull request #10 from Avivbens/support-root-assets
Browse files Browse the repository at this point in the history
feat: support `rootAssets` option for bundler
  • Loading branch information
Avivbens authored Aug 15, 2024
2 parents a0cae1f + b1cd7a5 commit 3718a70
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
18 changes: 18 additions & 0 deletions docs/app/setup/bundler-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ module.exports = {
}
```

## `rootAssets`

By default, `fast-alfred` would bundle a few files from the root of the project, like the `package.json` and the `README.md`.
You can add more assets to be bundled at the root, instead of the `assets` directory, by adding paths to the `rootAssets` property.

##### Example

```javascript
/**
* @type {import('fast-alfred').FastAlfredConfig}
*/
module.exports = {
bundlerOptions: {
rootAssets: ['List Filter Images'], // All files under the `List Filter Images` directory, as well as the directory itself, would be bundled as assets
},
}
```

## `assetsDir`

By default, `fast-alfred` would place all assets under the `assets` directory in the output directory.
Expand Down
5 changes: 3 additions & 2 deletions src/bundler/constants/bundler-options-defaults.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { BundlerOptions } from '../models/bundler-options.model'

export const BUNDLER_DEFAULTS: Required<BundlerOptions> = {
assets: [],
rootAssets: [],
assetsDir: 'assets',
targetDir: 'esbuild',
productionScripts: ['src/main/*.ts'],
Expand Down Expand Up @@ -53,5 +54,5 @@ globalThis.__dirname = _private_path.dirname(__filename);
*/
` as const

export const PACK_ENTITIES = (targetDir: string) =>
['*.png ', '*.plist', 'README.md', `${targetDir}/**`, 'package.json'] as const
export const PACK_ENTITIES = (targetDir: string, rootAssets: string[]) =>
['*.png ', '*.plist', 'README.md', `${targetDir}/**`, 'package.json'].concat(rootAssets.map((a) => `"${a}"`))
7 changes: 7 additions & 0 deletions src/bundler/models/bundler-options.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export interface BundlerOptions {
*/
assets?: string[]

/**
* @description
* Additional assets to be included in the root of the bundle.
* Would be located on the workflow root directory.
*/
rootAssets?: string[]

/**
* @description
* The directory where the assets would be copied to.
Expand Down
4 changes: 2 additions & 2 deletions src/bundler/services/build-workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export async function buildWorkflow() {

export async function packWorkflow() {
const { name } = await readWorkflowPackageJson()
const { targetDir } = await buildOptions()
const { targetDir, rootAssets } = await buildOptions()
const targetDirName = basename(targetDir)

if (!name || !targetDir) {
throw new Error('Missing workflow name or targetDir!')
}

const zipCommand = `zip -9 -r "${targetDir}/${name}.alfredworkflow" ${PACK_ENTITIES(targetDirName).join(' ')}`
const zipCommand = `zip -9 -r "${targetDir}/${name}.alfredworkflow" ${PACK_ENTITIES(targetDirName, rootAssets).join(' ')}`
await execPromise(zipCommand)
}

0 comments on commit 3718a70

Please sign in to comment.