diff --git a/docs/app/setup/bundler-options.md b/docs/app/setup/bundler-options.md index 2855a34..3279424 100644 --- a/docs/app/setup/bundler-options.md +++ b/docs/app/setup/bundler-options.md @@ -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. diff --git a/src/bundler/constants/bundler-options-defaults.config.ts b/src/bundler/constants/bundler-options-defaults.config.ts index 8d8d593..9212025 100644 --- a/src/bundler/constants/bundler-options-defaults.config.ts +++ b/src/bundler/constants/bundler-options-defaults.config.ts @@ -4,6 +4,7 @@ import type { BundlerOptions } from '../models/bundler-options.model' export const BUNDLER_DEFAULTS: Required = { assets: [], + rootAssets: [], assetsDir: 'assets', targetDir: 'esbuild', productionScripts: ['src/main/*.ts'], @@ -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}"`)) diff --git a/src/bundler/models/bundler-options.model.ts b/src/bundler/models/bundler-options.model.ts index d4151dd..7c1672f 100644 --- a/src/bundler/models/bundler-options.model.ts +++ b/src/bundler/models/bundler-options.model.ts @@ -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. diff --git a/src/bundler/services/build-workflow.service.ts b/src/bundler/services/build-workflow.service.ts index 408101c..2f603ce 100755 --- a/src/bundler/services/build-workflow.service.ts +++ b/src/bundler/services/build-workflow.service.ts @@ -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) }