From b998da3f305fa637c2016ccf447559c2c77579f8 Mon Sep 17 00:00:00 2001 From: Aviv Ben Shahar Date: Thu, 15 Aug 2024 03:19:57 +0300 Subject: [PATCH 1/2] feat: support `rootAssets` option for bundler --- docs/app/setup/bundler-options.md | 18 ++++++++++++++++++ .../bundler-options-defaults.config.ts | 5 +++-- src/bundler/models/bundler-options.model.ts | 7 +++++++ src/bundler/services/build-workflow.service.ts | 4 ++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/app/setup/bundler-options.md b/docs/app/setup/bundler-options.md index 2855a34..b5e489b 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 the 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 by adding paths into 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..4dc1e64 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', `"${rootAssets}"`] as const 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) } From b1cd7a5835700764eb7802e59ad5e0deab4f73ff Mon Sep 17 00:00:00 2001 From: Aviv Ben Shahar Date: Thu, 15 Aug 2024 09:54:18 +0300 Subject: [PATCH 2/2] chore: code review - small fixes --- docs/app/setup/bundler-options.md | 4 ++-- src/bundler/constants/bundler-options-defaults.config.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/app/setup/bundler-options.md b/docs/app/setup/bundler-options.md index b5e489b..3279424 100644 --- a/docs/app/setup/bundler-options.md +++ b/docs/app/setup/bundler-options.md @@ -59,8 +59,8 @@ module.exports = { ## `rootAssets` -By default, `fast-alfred` would bundle the 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 by adding paths into the `rootAssets` property. +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 diff --git a/src/bundler/constants/bundler-options-defaults.config.ts b/src/bundler/constants/bundler-options-defaults.config.ts index 4dc1e64..9212025 100644 --- a/src/bundler/constants/bundler-options-defaults.config.ts +++ b/src/bundler/constants/bundler-options-defaults.config.ts @@ -55,4 +55,4 @@ globalThis.__dirname = _private_path.dirname(__filename); ` as const export const PACK_ENTITIES = (targetDir: string, rootAssets: string[]) => - ['*.png ', '*.plist', 'README.md', `${targetDir}/**`, 'package.json', `"${rootAssets}"`] as const + ['*.png ', '*.plist', 'README.md', `${targetDir}/**`, 'package.json'].concat(rootAssets.map((a) => `"${a}"`))