diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c84ba2..c4030314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [4.4.0-stage.1](https://github.com/aziontech/bundler/compare/v4.3.0...v4.4.0-stage.1) (2025-01-13) + + +### Features + +* transform json manifest into js command ([#417](https://github.com/aziontech/bundler/issues/417)) ([391b30d](https://github.com/aziontech/bundler/commit/391b30df01114aa0da55630e23147a6f9cfe797e)) + ## [4.3.0](https://github.com/aziontech/bundler/compare/v4.2.1...v4.3.0) (2024-12-13) diff --git a/lib/commands/index.js b/lib/commands/index.js index e2b50117..fca0c1d7 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -2,5 +2,12 @@ import buildCommand from './build.commands.js'; import devCommand from './dev.commands.js'; import initCommand from './init.commands.js'; import presetsCommand from './presets.commands.js'; +import manifestCommand from './manifest.commands.js'; -export { buildCommand, devCommand, initCommand, presetsCommand }; +export { + buildCommand, + devCommand, + initCommand, + presetsCommand, + manifestCommand, +}; diff --git a/lib/commands/manifest.commands.js b/lib/commands/manifest.commands.js new file mode 100644 index 00000000..a234c623 --- /dev/null +++ b/lib/commands/manifest.commands.js @@ -0,0 +1,68 @@ +import { readFileSync, writeFileSync } from 'fs'; +import { resolve, extname } from 'path'; +import { feedback, debug } from '#utils'; +import { Messages } from '#constants'; +import { convertJsonConfigToObject } from 'azion'; + +import { Commands } from '#namespaces'; +/** + * @function manifestCommand + * @memberof Commands + * @description + * transforms a JSON manifest file to a JavaScript module. + * + * Usage: + * ```bash + * az manifest transform -o + * ``` + * + * Example: + * ```bash + * az manifest transform .edge/manifest.json -o azion.config.js + * ``` + * @param {string} command - The operation to perform (only 'transform' for now) + * @param {string} entry - Path to the input JSON file + * @param {object} options - Command options + * @param {string} options.output - Output file path for JS module + */ +async function manifestCommand(command, entry, options) { + try { + if (command !== 'transform') { + feedback.error('Only transform command is supported'); + process.exit(1); + } + + if (!entry) { + feedback.error('Input file path is required'); + process.exit(1); + } + + if (!options.output) { + feedback.error('Output file path is required (--output)'); + process.exit(1); + } + + const fileExtension = extname(entry).toLowerCase(); + if (fileExtension !== '.json') { + feedback.error('Input file must be .json'); + process.exit(1); + } + + const absolutePath = resolve(process.cwd(), entry); + const jsonString = readFileSync(absolutePath, 'utf8'); + const config = convertJsonConfigToObject(jsonString); + + const jsContent = `export default ${JSON.stringify(config, null, 2)};`; + writeFileSync(options.output, jsContent); + + feedback.success( + `Azion Platform configuration transformed into JavaScript module at ${options.output}`, + ); + } catch (error) { + debug.error(error); + feedback.error(Messages.errors.unknown_error); + process.exit(1); + } +} + +export default manifestCommand; diff --git a/lib/main.js b/lib/main.js index 437440fd..c1a1be25 100755 --- a/lib/main.js +++ b/lib/main.js @@ -219,13 +219,25 @@ function startVulcanProgram() { program .command('presets ') .description( - 'Create or list defined project presets for Edge', + 'Create or list defined project presets for Azion', ) .action(async (command) => { const { presetsCommand } = await import('#commands'); await presetsCommand(command); }); + program + .command('manifest ') + .description( + 'Trasnform or validate manifest files for Azion', + ) + .argument('[entry]', 'Path to the input file') + .option('-o, --output ', 'Output file path for convert command') + .action(async (command, entry, options) => { + const { manifestCommand } = await import('#commands'); + await manifestCommand(command, entry, convertOptions(options)); + }); + program.parse(process.argv); } diff --git a/package.json b/package.json index f3b66fdf..f3ad100d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "edge-functions", "type": "module", - "version": "4.3.0", + "version": "4.4.0-stage.1", "description": "Tool to launch and build JavaScript/Frameworks. This tool automates polyfills for Edge Computing and assists in creating Workers, notably for the Azion platform.", "main": "lib/main.js", "bin": { @@ -55,7 +55,7 @@ "ajv-errors": "^3.0.0", "ajv-keywords": "^5.1.0", "assert": "^2.0.0", - "azion": "^1.10.0", + "azion": "^1.12.0", "babel-loader": "^9.2.1", "bottleneck": "^2.19.5", "browserify-zlib": "^0.2.0", diff --git a/yarn.lock b/yarn.lock index 6f0beec1..06340ec3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2493,10 +2493,10 @@ axios@^1.6.1: form-data "^4.0.0" proxy-from-env "^1.1.0" -azion@^1.10.0: - version "1.10.0" - resolved "https://registry.yarnpkg.com/azion/-/azion-1.10.0.tgz#547e21a2fa9e696176e068d6167a5aea49a54990" - integrity sha512-UE6BCaq6DbAUUUmiIIFZko0QhpX9A9qhMD/HCbyqVQK0b19+JmCLwPVsJ6RkL6OvYvUIWvOFfzFaB4qvEbitpA== +azion@^1.12.0: + version "1.12.0" + resolved "https://registry.yarnpkg.com/azion/-/azion-1.12.0.tgz#74d85b3cd406b6e20b61d984dc98aeaee417eb23" + integrity sha512-J9upHyyqi40xIhEIM15Wi9/G0RH24OEfTiskSQKK42wyazALtPTKQ0VmFI0l+Uy44cR1vNEo0/eS9NOCI6v12A== dependencies: chalk "^5.3.0" progress "^2.0.3"