@adobe/aio-commerce-lib-app 1.7.0 → 1.8.0-beta-20260714082406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/dist/cjs/actions/app-config/index.cjs +41 -38
- package/dist/cjs/actions/app-config/index.d.cts +1 -1
- package/dist/cjs/actions/association/index.cjs +85 -0
- package/dist/cjs/actions/{registration → association}/index.d.cts +9 -13
- package/dist/cjs/actions/config/index.cjs +21 -32
- package/dist/cjs/actions/installation/index.cjs +72 -51
- package/dist/cjs/actions/installation/index.d.cts +2 -2
- package/dist/cjs/actions/scope-tree/index.cjs +18 -17
- package/dist/{es/app-DrYHK-z1.d.mts → cjs/app-D3P-Z6uY.d.cts} +1085 -1035
- package/dist/cjs/association-repository-BAs3-VkW.cjs +69 -0
- package/dist/cjs/commands/index.cjs +512 -298
- package/dist/cjs/commands/templates/admin-ui/tsconfig.json +14 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/index.css +5 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/index.html +17 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
- package/dist/cjs/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
- package/dist/cjs/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
- package/dist/cjs/commands/templates/app-management/app-config.js.template +1 -14
- package/dist/cjs/commands/templates/app-management/association.js.template +6 -0
- package/dist/cjs/commands/templates/app-management/installation.js.template +1 -13
- package/dist/cjs/commands/templates/business-configuration/config.js.template +2 -15
- package/dist/cjs/commands/templates/business-configuration/scope-tree.js.template +0 -12
- package/dist/cjs/config/index.browser.cjs +18 -0
- package/dist/cjs/config/index.browser.d.cts +16 -0
- package/dist/cjs/config/{index.cjs → index.node.cjs} +9 -8
- package/dist/cjs/config/{index.d.cts → index.node.d.cts} +954 -386
- package/dist/cjs/define-DBxAlJfN.d.cts +34 -0
- package/dist/cjs/define-hlcQw7Cv.cjs +41 -0
- package/dist/cjs/environment-B7EnozSg.cjs +135 -0
- package/dist/cjs/{index-B5gJ-q4U.d.cts → index-CzReNwbF.d.cts} +17 -12
- package/dist/cjs/index.cjs +250 -0
- package/dist/cjs/index.d.cts +217 -0
- package/dist/cjs/{config-D-s0GSep.cjs → index.node-Dz4lV4qe.cjs} +119 -35
- package/dist/cjs/{logging-BVz3weoC.cjs → logging-udPuAJPt.cjs} +2 -2
- package/dist/cjs/management/index.cjs +1 -1
- package/dist/cjs/management/index.d.cts +1 -1
- package/dist/cjs/{management-Dehz9qSJ.cjs → management-B9ItB80R.cjs} +385 -582
- package/dist/cjs/{openapi-Cux6K4ZD.cjs → openapi-CwytYdWl.cjs} +476 -600
- package/dist/cjs/{router-BOR7T6qR.cjs → router-hA_Y9gZ1.cjs} +42 -44
- package/dist/cjs/{schemas-FngDuIeo.cjs → schemas-mLxMh_ko.cjs} +2 -2
- package/dist/cjs/utils-DSCmZ_iJ.cjs +408 -0
- package/dist/cjs/{validate-oAOpyFyb.cjs → validate-BfxhZ5Wv.cjs} +20 -20
- package/dist/cjs/{webhooks-tbZy9G3p.cjs → webhooks-B5tb9NeF.cjs} +159 -151
- package/dist/es/actions/app-config/index.d.mts +1 -1
- package/dist/es/actions/app-config/index.mjs +39 -36
- package/dist/es/actions/{registration → association}/index.d.mts +9 -13
- package/dist/es/actions/association/index.mjs +82 -0
- package/dist/es/actions/config/index.mjs +17 -28
- package/dist/es/actions/installation/index.d.mts +2 -2
- package/dist/es/actions/installation/index.mjs +69 -48
- package/dist/es/actions/scope-tree/index.mjs +14 -13
- package/dist/{cjs/app-DrYHK-z1.d.cts → es/app-D3P-Z6uY.d.mts} +1085 -1035
- package/dist/es/association-repository-BbQv9WCl.mjs +52 -0
- package/dist/es/commands/index.mjs +544 -328
- package/dist/es/commands/templates/admin-ui/tsconfig.json +14 -0
- package/dist/es/commands/templates/admin-ui/web-src/index.css +5 -0
- package/dist/es/commands/templates/admin-ui/web-src/index.html +17 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/app.jsx +13 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/components/welcome.jsx +12 -0
- package/dist/es/commands/templates/admin-ui/web-src/src/pages/main-page.jsx +10 -0
- package/dist/es/commands/templates/{admin-ui-sdk/registration.js.template → admin-ui/web-src-template.d.ts} +11 -6
- package/dist/es/commands/templates/app-management/app-config.js.template +1 -14
- package/dist/es/commands/templates/app-management/association.js.template +6 -0
- package/dist/es/commands/templates/app-management/installation.js.template +1 -13
- package/dist/es/commands/templates/business-configuration/config.js.template +2 -15
- package/dist/es/commands/templates/business-configuration/scope-tree.js.template +0 -12
- package/dist/es/config/index.browser.d.mts +16 -0
- package/dist/es/config/index.browser.mjs +17 -0
- package/dist/es/config/{index.d.mts → index.node.d.mts} +954 -386
- package/dist/es/config/{index.mjs → index.node.mjs} +5 -4
- package/dist/es/define-EoYRZbpe.d.mts +34 -0
- package/dist/es/define-Z_Glf1-_.mjs +35 -0
- package/dist/es/environment-C84BPRJZ.mjs +104 -0
- package/dist/es/{index-DLMbTtKS.d.mts → index-D52xglhZ.d.mts} +17 -12
- package/dist/es/index.d.mts +217 -0
- package/dist/es/index.mjs +242 -0
- package/dist/es/{config-3I4eLyyR.mjs → index.node-CDH5gwJE.mjs} +94 -30
- package/dist/es/management/index.d.mts +1 -1
- package/dist/es/management/index.mjs +1 -1
- package/dist/es/{management-BUX-w2Ji.mjs → management-B89ApQVY.mjs} +353 -550
- package/dist/es/{openapi-B6uP0SRn.mjs → openapi-CXonvevE.mjs} +476 -600
- package/dist/es/{router-D58JJHHA.mjs → router-B_h0cvjc.mjs} +40 -42
- package/dist/es/utils-_gj8L6eN.mjs +289 -0
- package/dist/es/{validate-Dfajrp99.mjs → validate-9cRZWGrA.mjs} +17 -17
- package/dist/es/{webhooks-B5oq9ULL.mjs → webhooks-BBPbY2mb.mjs} +150 -142
- package/package.json +40 -17
- package/dist/cjs/actions/registration/index.cjs +0 -50
- package/dist/cjs/admin-ui-sdk-EU915zlR.d.cts +0 -664
- package/dist/es/actions/registration/index.mjs +0 -49
- package/dist/es/admin-ui-sdk-BwnD0xjK.d.mts +0 -664
- /package/dist/cjs/{chunk-Cozy-1ZF.cjs → rolldown-runtime-Cozy-1ZF.cjs} +0 -0
|
@@ -14,24 +14,23 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { t as stringifyError } from "../error-_RMwtrUA.mjs";
|
|
17
|
-
import { a as getExecCommand, c as
|
|
18
|
-
import { a as hasCustomInstallationSteps, d as
|
|
19
|
-
import { o as getConfigDomains, r as requiresInstallation, t as validateCommerceAppConfig, u as hasBusinessConfigSchema } from "../validate-
|
|
17
|
+
import { a as getExecCommand, c as getProjectInstallCommand, d as loadPackageJson, f as makeOutputDirFor, i as detectPackageManager, l as getProjectRootDirectory, m as readPackageJson, n as readCommerceAppConfig, o as getInstallCommand, p as mergePackageJsonDependencies, r as resolveCommerceAppConfig, s as getPackageDependencyInstallPlan, t as parseCommerceAppConfig, u as isESM } from "../index.node-CDH5gwJE.mjs";
|
|
18
|
+
import { a as hasCustomInstallationSteps, d as hasAdminUi } from "../webhooks-BBPbY2mb.mjs";
|
|
19
|
+
import { o as getConfigDomains, r as requiresInstallation, t as validateCommerceAppConfig, u as hasBusinessConfigSchema } from "../validate-9cRZWGrA.mjs";
|
|
20
20
|
import { t as inspect } from "../logging-DbJHXSKh.mjs";
|
|
21
21
|
import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
|
|
22
|
-
import consola, { consola as consola$1 } from "consola";
|
|
23
|
-
import path, { basename, dirname, extname, join, relative, resolve, sep } from "path";
|
|
24
22
|
import { hasDynamicSchema } from "@adobe/aio-commerce-lib-config";
|
|
25
|
-
import
|
|
23
|
+
import path, { basename, dirname, extname, join, relative, resolve, sep } from "path";
|
|
26
24
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
27
|
-
import { access, readFile, rm, writeFile } from "fs/promises";
|
|
25
|
+
import { access, mkdir, readFile, readdir, rm, writeFile } from "fs/promises";
|
|
26
|
+
import consola$1, { consola } from "consola";
|
|
27
|
+
import { execSync, spawnSync } from "child_process";
|
|
28
|
+
import * as prettier from "prettier";
|
|
28
29
|
import { fileURLToPath } from "url";
|
|
29
30
|
import { Document, YAMLMap, YAMLSeq, isMap, isPair, isSeq, parseDocument } from "yaml";
|
|
30
|
-
import NpmPackageJson from "@npmcli/package-json";
|
|
31
31
|
import { colorize, formatTree } from "consola/utils";
|
|
32
32
|
import { build } from "esbuild";
|
|
33
|
-
import
|
|
34
|
-
import { execSync, spawnSync } from "child_process";
|
|
33
|
+
import { stringify } from "safe-stable-stringify";
|
|
35
34
|
import config from "@adobe/aio-lib-core-config";
|
|
36
35
|
import aioIms from "@adobe/aio-lib-ims";
|
|
37
36
|
import dotenv from "dotenv";
|
|
@@ -49,12 +48,8 @@ const GENERATED_ACTIONS_PATH = `${GENERATED_PATH}/${ACTIONS_FOLDER}`;
|
|
|
49
48
|
const EXTENSIBILITY_EXTENSION_POINT_ID = "commerce/extensibility/1";
|
|
50
49
|
/** The name of the extension point for configuration. */
|
|
51
50
|
const CONFIGURATION_EXTENSION_POINT_ID = "commerce/configuration/1";
|
|
52
|
-
/** The name of the extension point for Admin UI
|
|
53
|
-
const
|
|
54
|
-
/** The name of the package containing the admin UI SDK generated actions */
|
|
55
|
-
const ADMIN_UI_SDK_PACKAGE_NAME = "admin-ui-sdk";
|
|
56
|
-
/** The path to the directory containing the generated Admin UI SDK actions. */
|
|
57
|
-
const ADMIN_UI_SDK_ACTIONS_PATH = `${GENERATED_PATH}/actions/registration`;
|
|
51
|
+
/** The name of the extension point for Admin UI. */
|
|
52
|
+
const BACKEND_UI_V2_EXTENSION_POINT_ID = "commerce/backend-ui/2";
|
|
58
53
|
/** The name of the configuration schema file */
|
|
59
54
|
const APP_MANIFEST_FILE = "app.commerce.manifest.json";
|
|
60
55
|
/** The name of the generated runtime-safe app config module (dynamic schemas only). */
|
|
@@ -81,25 +76,63 @@ function getExtensionPointFolderPath(extensionPointId) {
|
|
|
81
76
|
/** Format file content using prettier, inferring the parser from the file path. */
|
|
82
77
|
function prettierFormat(content, filepath) {
|
|
83
78
|
return prettier.format(content, {
|
|
84
|
-
semi: true,
|
|
85
|
-
quoteStyle: "double",
|
|
86
79
|
arrowParens: "always",
|
|
87
80
|
bracketSameLine: true,
|
|
88
81
|
bracketSpacing: true,
|
|
89
|
-
|
|
90
|
-
tabWidth: 2,
|
|
91
|
-
useTabs: false,
|
|
82
|
+
filepath,
|
|
92
83
|
printWidth: 80,
|
|
93
|
-
|
|
84
|
+
quoteStyle: "double",
|
|
85
|
+
semi: true,
|
|
86
|
+
tabWidth: 2,
|
|
87
|
+
trailingComma: "all",
|
|
88
|
+
useTabs: false
|
|
94
89
|
});
|
|
95
90
|
}
|
|
96
91
|
/** Load the app commerce config */
|
|
97
92
|
async function loadAppManifest() {
|
|
98
93
|
const appConfig = await parseCommerceAppConfig();
|
|
99
|
-
consola.debug("Loaded app commerce config");
|
|
94
|
+
consola$1.debug("Loaded app commerce config");
|
|
100
95
|
return appConfig;
|
|
101
96
|
}
|
|
102
97
|
/**
|
|
98
|
+
* Install the given dependencies.
|
|
99
|
+
* @param packageManager - The detected package manager.
|
|
100
|
+
* @param dependencies - Package specifiers to install; no-op when empty.
|
|
101
|
+
* @param cwd - Working directory for the install command.
|
|
102
|
+
* @param options - Install command options.
|
|
103
|
+
*/
|
|
104
|
+
function runInstall(packageManager, dependencies, cwd = process.cwd(), options = {}) {
|
|
105
|
+
if (dependencies.length === 0) return;
|
|
106
|
+
const dependencyListString = dependencies.map((dependency) => ` - ${dependency}`).join("\n");
|
|
107
|
+
consola$1.start([`Installing the following dependencies with ${packageManager}:\n${dependencyListString}\n`, "This may take a few seconds...\n"].join("\n"));
|
|
108
|
+
const { command, args } = getInstallCommand(packageManager, dependencies, options);
|
|
109
|
+
const displayCommand = [command, ...args].join(" ");
|
|
110
|
+
const result = spawnSync(command, args, {
|
|
111
|
+
cwd,
|
|
112
|
+
stdio: "inherit"
|
|
113
|
+
});
|
|
114
|
+
if (result.error || result.status !== 0) throw new Error(`Failed to install dependencies automatically. Please install manually: ${displayCommand}`, { cause: result.error ?? /* @__PURE__ */ new Error(`Install exited with code ${result.status}`) });
|
|
115
|
+
consola$1.log("");
|
|
116
|
+
consola$1.success("Dependencies installed successfully");
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Install dependencies declared in package.json.
|
|
120
|
+
* @param packageManager - The detected package manager.
|
|
121
|
+
* @param cwd - Working directory for the install command.
|
|
122
|
+
*/
|
|
123
|
+
function runProjectInstall(packageManager, cwd = process.cwd()) {
|
|
124
|
+
consola$1.start([`Installing project dependencies with ${packageManager}...`, "This may take a few seconds...\n"].join("\n"));
|
|
125
|
+
const { command, args } = getProjectInstallCommand(packageManager);
|
|
126
|
+
const displayCommand = [command, ...args].join(" ");
|
|
127
|
+
const result = spawnSync(command, args, {
|
|
128
|
+
cwd,
|
|
129
|
+
stdio: "inherit"
|
|
130
|
+
});
|
|
131
|
+
if (result.error || result.status !== 0) throw new Error(`Failed to install dependencies automatically. Please install manually: ${displayCommand}`, { cause: result.error ?? /* @__PURE__ */ new Error(`Install exited with code ${result.status}`) });
|
|
132
|
+
consola$1.log("");
|
|
133
|
+
consola$1.success("Dependencies installed successfully");
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
103
136
|
* Whether the app config contains anything that can't be JSON-serialized as-is
|
|
104
137
|
* and therefore requires generating a runtime-safe ESM config module.
|
|
105
138
|
*/
|
|
@@ -136,20 +169,6 @@ function getActionPath(extensionPointId, actionName) {
|
|
|
136
169
|
function getExtConfigPath(extensionPointId) {
|
|
137
170
|
return join(getExtensionPointFolderPath(extensionPointId), "ext.config.yaml");
|
|
138
171
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Path to an Admin UI SDK generated actions directory, relative to the project root.
|
|
141
|
-
* @param extensionPointId - The extension point ID, e.g. "commerce/backend-ui/1"
|
|
142
|
-
*/
|
|
143
|
-
function getAdminUiSdkActionsDir(extensionPointId) {
|
|
144
|
-
return join(getExtensionPointFolderPath(extensionPointId), ADMIN_UI_SDK_ACTIONS_PATH);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Path to the generated Admin UI SDK registration action file, relative to the project root.
|
|
148
|
-
* @param extensionPointId - The extension point ID, e.g. "commerce/backend-ui/1"
|
|
149
|
-
*/
|
|
150
|
-
function getAdminUiSdkRegistrationActionPath(extensionPointId) {
|
|
151
|
-
return join(getAdminUiSdkActionsDir(extensionPointId), "index.js");
|
|
152
|
-
}
|
|
153
172
|
/** Path to the generated app manifest JSON file, relative to the project root. */
|
|
154
173
|
function getManifestPath() {
|
|
155
174
|
return join(getGeneratedDir(EXTENSIBILITY_EXTENSION_POINT_ID), APP_MANIFEST_FILE);
|
|
@@ -167,8 +186,11 @@ function getSchemaPath() {
|
|
|
167
186
|
}
|
|
168
187
|
|
|
169
188
|
//#endregion
|
|
170
|
-
//#region source/commands/generate/actions/
|
|
171
|
-
|
|
189
|
+
//#region source/commands/generate/actions/constants.ts
|
|
190
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
191
|
+
/** The path to the action templates directory, sibling to this file. */
|
|
192
|
+
const TEMPLATES_DIR = join(__dirname, "templates");
|
|
193
|
+
/** The list of Commerce variables that are required for the runtime actions. */
|
|
172
194
|
const COMMERCE_VARIABLES = [
|
|
173
195
|
"AIO_COMMERCE_AUTH_IMS_CLIENT_ID",
|
|
174
196
|
"AIO_COMMERCE_AUTH_IMS_CLIENT_SECRETS",
|
|
@@ -177,27 +199,104 @@ const COMMERCE_VARIABLES = [
|
|
|
177
199
|
"AIO_COMMERCE_AUTH_IMS_ORG_ID",
|
|
178
200
|
"AIO_COMMERCE_AUTH_IMS_SCOPES"
|
|
179
201
|
];
|
|
180
|
-
/** The inputs for the generated runtime actions */
|
|
202
|
+
/** The inputs for the generated runtime actions. */
|
|
181
203
|
const COMMERCE_ACTION_INPUTS = Object.fromEntries(COMMERCE_VARIABLES.map((variable) => [variable, `$${variable}`]));
|
|
182
204
|
const CUSTOM_IMPORTS_PLACEHOLDER = "// {{CUSTOM_SCRIPTS_IMPORTS}}";
|
|
183
205
|
const CUSTOM_SCRIPTS_MAP_PLACEHOLDER = "// {{CUSTOM_SCRIPTS_MAP}}";
|
|
184
206
|
const CUSTOM_SCRIPTS_LOADER_PLACEHOLDER = "// {{CUSTOM_SCRIPTS_LOADER}}";
|
|
185
|
-
|
|
207
|
+
/** File extensions that require bundling or TypeScript web-src templates. */
|
|
208
|
+
const TYPESCRIPT_CONFIG_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
209
|
+
".ts",
|
|
210
|
+
".mts",
|
|
211
|
+
".cts"
|
|
212
|
+
]);
|
|
213
|
+
const JSX_FILE_EXTENSION = ".jsx";
|
|
214
|
+
const TSX_FILE_EXTENSION = ".tsx";
|
|
215
|
+
const APP_TITLE_PLACEHOLDER = "APP_TITLE";
|
|
216
|
+
const WEB_SOURCE_ENTRYPOINT_FILE = "index.html";
|
|
217
|
+
const WEB_SOURCE_IMPORT_ALIAS = "#web/*";
|
|
218
|
+
/** Runtime dependencies required by the generated web-src app. */
|
|
219
|
+
const WEB_SOURCE_DEPENDENCIES = [
|
|
220
|
+
{
|
|
221
|
+
name: "@adobe/aio-commerce-lib-admin-ui",
|
|
222
|
+
version: "^0.2.0-beta-20260714082406"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "react",
|
|
226
|
+
version: "^19.2.7"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "react-dom",
|
|
230
|
+
version: "^19.2.7"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: "@react-spectrum/s2",
|
|
234
|
+
version: "^1.5.1"
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
/** Development dependencies required by the generated web-src app. */
|
|
238
|
+
const WEB_SOURCE_DEV_DEPENDENCIES = [{
|
|
239
|
+
name: "@types/react",
|
|
240
|
+
version: "^19.2.17"
|
|
241
|
+
}, {
|
|
242
|
+
name: "@types/react-dom",
|
|
243
|
+
version: "^19.2.3"
|
|
244
|
+
}];
|
|
245
|
+
/** Development dependencies required only by TypeScript web-src scaffolds. */
|
|
246
|
+
const WEB_SOURCE_TS_DEV_DEPENDENCIES = [{
|
|
247
|
+
name: "@tsconfig/bases",
|
|
248
|
+
version: "latest"
|
|
249
|
+
}, {
|
|
250
|
+
name: "typescript",
|
|
251
|
+
version: "latest"
|
|
252
|
+
}];
|
|
253
|
+
/** tsconfig.json generated for TypeScript web-src scaffolds. */
|
|
254
|
+
const WEB_SOURCE_TSCONFIG_FILE = "tsconfig.json";
|
|
255
|
+
const WEB_SOURCE_TSCONFIG = {
|
|
256
|
+
compilerOptions: {
|
|
257
|
+
allowImportingTsExtensions: true,
|
|
258
|
+
allowJs: true,
|
|
259
|
+
checkJs: true,
|
|
260
|
+
jsx: "react-jsx",
|
|
261
|
+
jsxImportSource: "react",
|
|
262
|
+
module: "esnext",
|
|
263
|
+
moduleResolution: "bundler",
|
|
264
|
+
noEmit: true,
|
|
265
|
+
rewriteRelativeImportExtensions: false
|
|
266
|
+
},
|
|
267
|
+
extends: ["@tsconfig/bases/recommended"],
|
|
268
|
+
include: [
|
|
269
|
+
"src/**/*.js",
|
|
270
|
+
"src/**/*.ts",
|
|
271
|
+
"src/**/*.tsx",
|
|
272
|
+
"src/**/*.jsx"
|
|
273
|
+
]
|
|
274
|
+
};
|
|
275
|
+
/** Parcel shared bundle config required by Spectrum S2 styles. */
|
|
276
|
+
const WEB_SOURCE_SHARED_BUNDLES = [{
|
|
277
|
+
assets: ["**/@react-spectrum/s2/**", "src/commerce-backend-ui-2/web-src/*.{js,jsx,ts,tsx}"],
|
|
278
|
+
name: "s2-styles",
|
|
279
|
+
types: ["css"]
|
|
280
|
+
}];
|
|
281
|
+
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region source/commands/generate/actions/config.ts
|
|
186
284
|
/**
|
|
187
285
|
* Creates a runtime action configuration.
|
|
188
286
|
* @param actionName - The name of the action.
|
|
287
|
+
* @param config - Action generation options.
|
|
189
288
|
* @param options - Optional configuration options.
|
|
190
289
|
*/
|
|
191
290
|
function createActionDefinition(actionName, config = {}, options = {}) {
|
|
192
291
|
const def = {
|
|
193
292
|
...options,
|
|
293
|
+
annotations: {
|
|
294
|
+
final: true,
|
|
295
|
+
"require-adobe-auth": true
|
|
296
|
+
},
|
|
194
297
|
function: `${GENERATED_ACTIONS_PATH}/${actionName}.js`,
|
|
195
|
-
web: options.web ?? "yes",
|
|
196
298
|
runtime: "nodejs:24",
|
|
197
|
-
|
|
198
|
-
"require-adobe-auth": true,
|
|
199
|
-
final: true
|
|
200
|
-
}
|
|
299
|
+
web: options.web ?? "yes"
|
|
201
300
|
};
|
|
202
301
|
if (config.requiresEncryptionKey) def.inputs = {
|
|
203
302
|
...def.inputs,
|
|
@@ -208,6 +307,7 @@ function createActionDefinition(actionName, config = {}, options = {}) {
|
|
|
208
307
|
/**
|
|
209
308
|
* Gets the runtime actions to be generated from the ext.config.yaml configuration.
|
|
210
309
|
* @param extConfig - The ext.config.yaml configuration.
|
|
310
|
+
* @param dir - Directory containing the runtime action templates.
|
|
211
311
|
*/
|
|
212
312
|
function getRuntimeActions(extConfig, dir) {
|
|
213
313
|
return Object.entries(extConfig.runtimeManifest?.packages?.["app-management"]?.actions ?? {}).map(([name, _]) => ({
|
|
@@ -217,26 +317,32 @@ function getRuntimeActions(extConfig, dir) {
|
|
|
217
317
|
}
|
|
218
318
|
/**
|
|
219
319
|
* Builds the ext.config.yaml configuration for the extensibility extension.
|
|
220
|
-
* @param
|
|
320
|
+
* @param appConfig - Parsed app configuration.
|
|
221
321
|
*/
|
|
222
322
|
function buildAppManagementExtConfig(appConfig) {
|
|
223
323
|
const extConfig = {
|
|
224
324
|
hooks: { "pre-app-build": "EXTENSION=extensibility/1 $packageExec aio-commerce-lib-app hooks pre-app-build" },
|
|
225
325
|
operations: { workerProcess: [{
|
|
226
|
-
|
|
227
|
-
|
|
326
|
+
impl: `${PACKAGE_NAME}/app-config`,
|
|
327
|
+
type: "action"
|
|
328
|
+
}, {
|
|
329
|
+
impl: `${PACKAGE_NAME}/association`,
|
|
330
|
+
type: "action"
|
|
228
331
|
}] },
|
|
229
332
|
runtimeManifest: { packages: { [PACKAGE_NAME]: {
|
|
230
|
-
|
|
231
|
-
|
|
333
|
+
actions: {
|
|
334
|
+
"app-config": createActionDefinition("app-config"),
|
|
335
|
+
association: createActionDefinition("association")
|
|
336
|
+
},
|
|
337
|
+
license: "Apache-2.0"
|
|
232
338
|
} } }
|
|
233
339
|
};
|
|
234
340
|
const needsInstallAction = requiresInstallation(appConfig);
|
|
235
341
|
const hasPasswordFieldsInSchema = hasBusinessConfigSchema(appConfig) && appConfig.businessConfig.schema.some((field) => field.type === "password");
|
|
236
342
|
if (needsInstallAction) {
|
|
237
343
|
extConfig.operations.workerProcess.push({
|
|
238
|
-
|
|
239
|
-
|
|
344
|
+
impl: `${PACKAGE_NAME}/installation`,
|
|
345
|
+
type: "action"
|
|
240
346
|
});
|
|
241
347
|
extConfig.runtimeManifest.packages[PACKAGE_NAME].actions.installation = createActionDefinition("installation", { requiresEncryptionKey: hasPasswordFieldsInSchema }, {
|
|
242
348
|
inputs: {
|
|
@@ -252,8 +358,8 @@ function buildAppManagementExtConfig(appConfig) {
|
|
|
252
358
|
function buildBusinessConfigurationExtConfig() {
|
|
253
359
|
const actions = [{
|
|
254
360
|
name: "config",
|
|
255
|
-
|
|
256
|
-
|
|
361
|
+
requiresEncryptionKey: true,
|
|
362
|
+
templateFile: "config.js.template"
|
|
257
363
|
}, {
|
|
258
364
|
name: "scope-tree",
|
|
259
365
|
templateFile: "scope-tree.js.template"
|
|
@@ -261,38 +367,64 @@ function buildBusinessConfigurationExtConfig() {
|
|
|
261
367
|
return {
|
|
262
368
|
hooks: { "pre-app-build": "EXTENSION=configuration/1 $packageExec aio-commerce-lib-app hooks pre-app-build" },
|
|
263
369
|
operations: { workerProcess: actions.map((action) => ({
|
|
264
|
-
|
|
265
|
-
|
|
370
|
+
impl: `${PACKAGE_NAME}/${action.name}`,
|
|
371
|
+
type: "action"
|
|
266
372
|
})) },
|
|
267
373
|
runtimeManifest: { packages: { [PACKAGE_NAME]: {
|
|
268
|
-
|
|
269
|
-
|
|
374
|
+
actions: Object.fromEntries(actions.map((action) => [action.name, createActionDefinition(action.name, action)])),
|
|
375
|
+
license: "Apache-2.0"
|
|
270
376
|
} } }
|
|
271
377
|
};
|
|
272
378
|
}
|
|
379
|
+
/** Collects unique `runtimeAction` strings from all worker entries in an `adminUi` config. */
|
|
380
|
+
function collectUniqueRuntimeActions(adminUi) {
|
|
381
|
+
const entities = [
|
|
382
|
+
"order",
|
|
383
|
+
"product",
|
|
384
|
+
"customer"
|
|
385
|
+
].map((key) => adminUi?.[key]);
|
|
386
|
+
const gridRuntimeActions = entities.map((entity) => entity?.gridColumns?.runtimeAction).filter((action) => action !== void 0);
|
|
387
|
+
const massActionRuntimeActions = entities.flatMap((entity) => entity?.massActions ?? []).filter((action) => action.type === "worker").map((action) => action.runtimeAction);
|
|
388
|
+
const viewButtonRuntimeActions = (adminUi?.order?.viewButtons ?? []).filter((button) => button.type === "worker").map((button) => button.runtimeAction);
|
|
389
|
+
return [.../* @__PURE__ */ new Set([
|
|
390
|
+
...gridRuntimeActions,
|
|
391
|
+
...massActionRuntimeActions,
|
|
392
|
+
...viewButtonRuntimeActions
|
|
393
|
+
])];
|
|
394
|
+
}
|
|
395
|
+
/** Returns true if the `adminUi` config requires a `view` operation and `web` source in ext.config.yaml. */
|
|
396
|
+
function requiresWebSource(adminUi) {
|
|
397
|
+
if (adminUi?.menu !== void 0) return true;
|
|
398
|
+
if ((adminUi?.order?.viewButtons ?? []).some((button) => button.type === "view")) return true;
|
|
399
|
+
return [
|
|
400
|
+
"order",
|
|
401
|
+
"product",
|
|
402
|
+
"customer"
|
|
403
|
+
].map((key) => adminUi?.[key]).flatMap((entity) => entity?.massActions ?? []).some((action) => action.type === "view");
|
|
404
|
+
}
|
|
273
405
|
/**
|
|
274
|
-
* Builds the ext.config.yaml
|
|
406
|
+
* Builds the ext.config.yaml for the Admin UI v2 extension (`commerce/backend-ui/2`).
|
|
407
|
+
* Derives `workerProcess` and `view` operation declarations from `adminUi` config.
|
|
408
|
+
* Adds a `view` operation and `web` source when view-type entries or `adminUi.menu` is configured.
|
|
409
|
+
* @param appConfig - Parsed app configuration.
|
|
275
410
|
*/
|
|
276
|
-
function
|
|
411
|
+
function buildAdminUiV2ExtConfig(appConfig) {
|
|
412
|
+
const { adminUi } = appConfig;
|
|
413
|
+
const runtimeActions = collectUniqueRuntimeActions(adminUi);
|
|
414
|
+
const requiresWeb = requiresWebSource(adminUi);
|
|
277
415
|
return {
|
|
278
|
-
hooks: { "pre-app-build": "EXTENSION=backend-ui/
|
|
279
|
-
operations: {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
annotations: {
|
|
291
|
-
"require-adobe-auth": true,
|
|
292
|
-
final: true
|
|
293
|
-
}
|
|
294
|
-
} }
|
|
295
|
-
} } }
|
|
416
|
+
hooks: { "pre-app-build": "EXTENSION=backend-ui/2 $packageExec aio-commerce-lib-app hooks pre-app-build" },
|
|
417
|
+
operations: {
|
|
418
|
+
...requiresWeb && { view: [{
|
|
419
|
+
impl: "index.html",
|
|
420
|
+
type: "web"
|
|
421
|
+
}] },
|
|
422
|
+
...runtimeActions.length > 0 && { workerProcess: runtimeActions.map((impl) => ({
|
|
423
|
+
impl,
|
|
424
|
+
type: "action"
|
|
425
|
+
})) }
|
|
426
|
+
},
|
|
427
|
+
...requiresWeb && { web: "web-src" }
|
|
296
428
|
};
|
|
297
429
|
}
|
|
298
430
|
|
|
@@ -306,9 +438,9 @@ async function readYamlFile(path) {
|
|
|
306
438
|
let doc = new Document();
|
|
307
439
|
if (existsSync(path)) try {
|
|
308
440
|
doc = parseDocument(await readFile(path, "utf-8"), { keepSourceTokens: true });
|
|
309
|
-
} catch {
|
|
441
|
+
} catch (err) {
|
|
310
442
|
const file = basename(path);
|
|
311
|
-
throw new Error(`Failed to parse ${file}
|
|
443
|
+
throw new Error(`Failed to parse ${file}`, { cause: err });
|
|
312
444
|
}
|
|
313
445
|
if (doc.contents === null) doc.contents = new YAMLMap();
|
|
314
446
|
return doc;
|
|
@@ -342,8 +474,8 @@ function getOrCreateNode(doc, path, options, typeConfig) {
|
|
|
342
474
|
*/
|
|
343
475
|
function getOrCreateSeq(doc, path, options) {
|
|
344
476
|
return getOrCreateNode(doc, path, options ?? {}, {
|
|
345
|
-
typeGuard: isSeq,
|
|
346
477
|
createNode: () => new YAMLSeq(),
|
|
478
|
+
typeGuard: isSeq,
|
|
347
479
|
typeName: "sequence"
|
|
348
480
|
});
|
|
349
481
|
}
|
|
@@ -355,8 +487,8 @@ function getOrCreateSeq(doc, path, options) {
|
|
|
355
487
|
*/
|
|
356
488
|
function getOrCreateMap(doc, path, options) {
|
|
357
489
|
return getOrCreateNode(doc, path, options ?? {}, {
|
|
358
|
-
typeGuard: isMap,
|
|
359
490
|
createNode: () => new YAMLMap(),
|
|
491
|
+
typeGuard: isMap,
|
|
360
492
|
typeName: "map"
|
|
361
493
|
});
|
|
362
494
|
}
|
|
@@ -400,10 +532,9 @@ async function createOrUpdateExtConfig(path, config, doc) {
|
|
|
400
532
|
const extConfigDoc = doc ?? new Document({});
|
|
401
533
|
if (config.web !== void 0) buildWeb(extConfigDoc, config.web);
|
|
402
534
|
config.hooks ??= {};
|
|
403
|
-
config.runtimeManifest ??= { packages: {} };
|
|
404
535
|
await buildHooks(extConfigDoc, config.hooks);
|
|
405
536
|
if (config.operations !== void 0) buildOperations(extConfigDoc, config.operations);
|
|
406
|
-
buildRuntimeManifest(extConfigDoc, config.runtimeManifest);
|
|
537
|
+
if (config.runtimeManifest !== void 0) buildRuntimeManifest(extConfigDoc, config.runtimeManifest);
|
|
407
538
|
await writeExtConfig(path, extConfigDoc);
|
|
408
539
|
return extConfigDoc;
|
|
409
540
|
}
|
|
@@ -442,8 +573,8 @@ function buildActionDefinition(action, existingAction) {
|
|
|
442
573
|
...action.inputs ?? {}
|
|
443
574
|
});
|
|
444
575
|
actionDef.set("annotations", { ...action.annotations ?? {
|
|
445
|
-
|
|
446
|
-
|
|
576
|
+
final: true,
|
|
577
|
+
"require-adobe-auth": true
|
|
447
578
|
} });
|
|
448
579
|
const includes = action.include ?? [];
|
|
449
580
|
if (includes.length > 0) {
|
|
@@ -500,10 +631,11 @@ function buildOperations(extConfig, operations) {
|
|
|
500
631
|
* @param packages - The packages to build
|
|
501
632
|
*/
|
|
502
633
|
function buildRuntimeManifest(extConfig, manifest) {
|
|
634
|
+
const packages = manifest.packages ?? {};
|
|
635
|
+
if (Object.keys(packages).length === 0) return;
|
|
503
636
|
getOrCreateMap(extConfig, ["runtimeManifest"], { onBeforeCreate: (pair) => {
|
|
504
637
|
pair.key.spaceBefore = true;
|
|
505
638
|
} });
|
|
506
|
-
const packages = manifest.packages ?? {};
|
|
507
639
|
getOrCreateMap(extConfig, ["runtimeManifest", "packages"]);
|
|
508
640
|
for (const [name, pkg] of Object.entries(packages)) {
|
|
509
641
|
const packageDef = getOrCreateMap(extConfig, [
|
|
@@ -551,26 +683,15 @@ async function buildHooks(extConfig, hooks) {
|
|
|
551
683
|
*/
|
|
552
684
|
async function writeExtConfig(configPath, doc) {
|
|
553
685
|
await writeFile(configPath, doc.toString({
|
|
686
|
+
defaultStringType: "PLAIN",
|
|
554
687
|
indent: 2,
|
|
555
|
-
lineWidth: 0
|
|
556
|
-
defaultStringType: "PLAIN"
|
|
688
|
+
lineWidth: 0
|
|
557
689
|
}), "utf-8");
|
|
558
690
|
}
|
|
559
691
|
|
|
560
692
|
//#endregion
|
|
561
693
|
//#region source/commands/generate/actions/lib.ts
|
|
562
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
563
|
-
/** The path to the action templates directory, sibling to this file. */
|
|
564
|
-
const TEMPLATES_DIR = join(__dirname, "templates");
|
|
565
|
-
const TYPESCRIPT_CONFIG_EXTENSIONS = new Set([
|
|
566
|
-
".ts",
|
|
567
|
-
".mts",
|
|
568
|
-
".cts"
|
|
569
|
-
]);
|
|
570
694
|
const LEADING_DOT_SLASH_PATTERN = /^\.\//u;
|
|
571
|
-
const DYNAMIC_APP_CONFIG_IMPORT = `import appConfig from "${APP_CONFIG_IMPORT_ALIAS}";`;
|
|
572
|
-
const STATIC_APP_MANIFEST_IMPORT = "import appConfig from \"../../app.commerce.manifest.json\" with { type: \"json\" };";
|
|
573
|
-
const STATIC_CONFIG_SCHEMA_IMPORT = "import configSchema from \"../../configuration-schema.json\" with { type: \"json\" };";
|
|
574
695
|
/** Normalize a path for use as an ESM import specifier. */
|
|
575
696
|
function normalizeImportPath(path) {
|
|
576
697
|
const normalizedPath = path.split(sep).join("/");
|
|
@@ -582,7 +703,8 @@ function normalizePackageJsonPath(path) {
|
|
|
582
703
|
}
|
|
583
704
|
/** Add or update the package import alias used by dynamic generated actions. */
|
|
584
705
|
async function updateAppConfigImportAlias(projectRoot, runtimeConfigPath) {
|
|
585
|
-
const pkg = await
|
|
706
|
+
const pkg = await loadPackageJson(projectRoot);
|
|
707
|
+
if (pkg === null) throw new Error("Could not find package.json.");
|
|
586
708
|
const existingImports = typeof pkg.content.imports === "object" && pkg.content.imports !== null ? pkg.content.imports : {};
|
|
587
709
|
pkg.update({ imports: {
|
|
588
710
|
...existingImports,
|
|
@@ -590,24 +712,13 @@ async function updateAppConfigImportAlias(projectRoot, runtimeConfigPath) {
|
|
|
590
712
|
} });
|
|
591
713
|
await pkg.save();
|
|
592
714
|
}
|
|
593
|
-
/**
|
|
594
|
-
async function deleteAppConfigImportAlias(projectRoot) {
|
|
595
|
-
const pkg = await NpmPackageJson.load(projectRoot);
|
|
596
|
-
const existingImports = typeof pkg.content.imports === "object" && pkg.content.imports !== null ? pkg.content.imports : {};
|
|
597
|
-
if (!("#app.commerce.config" in existingImports)) return;
|
|
598
|
-
const imports = { ...existingImports };
|
|
599
|
-
delete imports[APP_CONFIG_IMPORT_ALIAS];
|
|
600
|
-
if (Object.keys(imports).length > 0) pkg.update({ imports });
|
|
601
|
-
else pkg.content.imports = void 0;
|
|
602
|
-
await pkg.save();
|
|
603
|
-
}
|
|
604
|
-
/** Write an ESM passthrough module for JavaScript app config files. */
|
|
715
|
+
/** Write an ESM passthrough module that re-exports an app config file. */
|
|
605
716
|
async function writeJavaScriptAppConfigModule(configFilePath, outputPath) {
|
|
606
717
|
await writeFile(outputPath, [
|
|
607
718
|
"// This file has been auto-generated by `@adobe/aio-commerce-lib-app`",
|
|
608
719
|
"// Do not modify this file directly",
|
|
609
720
|
"",
|
|
610
|
-
`import appConfig from "${normalizeImportPath(relative(dirname(outputPath), configFilePath))}";`,
|
|
721
|
+
`import appConfig from "${normalizeImportPath(relative(dirname(outputPath), configFilePath))}"${extname(configFilePath) === ".json" ? " with { type: \"json\" }" : ""};`,
|
|
611
722
|
"",
|
|
612
723
|
"export default appConfig;",
|
|
613
724
|
""
|
|
@@ -616,14 +727,14 @@ async function writeJavaScriptAppConfigModule(configFilePath, outputPath) {
|
|
|
616
727
|
/** Bundle a TypeScript app config file into runtime-safe ESM. */
|
|
617
728
|
async function bundleTypeScriptAppConfigModule(configFilePath, outputPath) {
|
|
618
729
|
await build({
|
|
619
|
-
entryPoints: [configFilePath],
|
|
620
|
-
outfile: outputPath,
|
|
621
730
|
bundle: true,
|
|
731
|
+
entryPoints: [configFilePath],
|
|
622
732
|
format: "esm",
|
|
623
|
-
|
|
624
|
-
|
|
733
|
+
logLevel: "silent",
|
|
734
|
+
outfile: outputPath,
|
|
625
735
|
packages: "external",
|
|
626
|
-
|
|
736
|
+
platform: "node",
|
|
737
|
+
target: "node22"
|
|
627
738
|
});
|
|
628
739
|
}
|
|
629
740
|
/** Generate the runtime-safe app config module used by generated runtime actions. */
|
|
@@ -634,36 +745,36 @@ async function generateRuntimeAppConfigModule() {
|
|
|
634
745
|
const outputPath = join(projectRoot, runtimeConfigPath);
|
|
635
746
|
const configFilePath = await resolveCommerceAppConfig(projectRoot);
|
|
636
747
|
if (!configFilePath) throw new Error("Dynamic list options require an app.commerce.config.* file so generated actions can import the option factories at runtime.");
|
|
637
|
-
consola
|
|
748
|
+
consola.info("Generating JS config module...");
|
|
638
749
|
if (TYPESCRIPT_CONFIG_EXTENSIONS.has(extname(configFilePath))) await bundleTypeScriptAppConfigModule(configFilePath, outputPath);
|
|
639
750
|
else await writeJavaScriptAppConfigModule(configFilePath, outputPath);
|
|
640
751
|
await updateAppConfigImportAlias(projectRoot, runtimeConfigPath);
|
|
641
|
-
consola
|
|
752
|
+
consola.success(`Generated JS config module: ${relative(process.cwd(), outputPath)}`);
|
|
642
753
|
}
|
|
643
|
-
/**
|
|
644
|
-
|
|
754
|
+
/**
|
|
755
|
+
* Write an ESM module that re-exports the static app manifest JSON so generated
|
|
756
|
+
* actions can import it via the alias without needing a JSON import attribute.
|
|
757
|
+
*/
|
|
758
|
+
async function prepareStaticAppConfigImportAlias() {
|
|
645
759
|
const projectRoot = await getProjectRootDirectory();
|
|
646
|
-
|
|
647
|
-
|
|
760
|
+
const runtimeConfigPath = getRuntimeAppConfigPath();
|
|
761
|
+
const outputPath = join(projectRoot, runtimeConfigPath);
|
|
762
|
+
await makeOutputDirFor(dirname(runtimeConfigPath));
|
|
763
|
+
await writeJavaScriptAppConfigModule(join(projectRoot, getManifestPath()), outputPath);
|
|
764
|
+
await updateAppConfigImportAlias(projectRoot, runtimeConfigPath);
|
|
648
765
|
}
|
|
649
766
|
/**
|
|
650
767
|
* Prepare runtime-side config artifacts consumed by generated actions: the
|
|
651
768
|
* bundled ESM module and its `#app.commerce.config` package import alias.
|
|
652
769
|
*
|
|
653
|
-
*
|
|
770
|
+
* Dynamic schemas use the source config file, while static schemas use the generated JSON manifest.
|
|
654
771
|
*/
|
|
655
772
|
async function prepareRuntimeAppConfigModule(appManifest) {
|
|
656
773
|
if (hasDynamicAppConfig(appManifest)) {
|
|
657
774
|
await generateRuntimeAppConfigModule();
|
|
658
775
|
return;
|
|
659
776
|
}
|
|
660
|
-
await
|
|
661
|
-
}
|
|
662
|
-
/** Switch static JSON imports to the generated runtime config module for dynamic schemas. */
|
|
663
|
-
function applyRuntimeAppConfigImport(template, actionName) {
|
|
664
|
-
if (actionName === "app-config" || actionName === "installation") return template.replace(STATIC_APP_MANIFEST_IMPORT, DYNAMIC_APP_CONFIG_IMPORT);
|
|
665
|
-
if (actionName === "config") return template.replace(STATIC_CONFIG_SCHEMA_IMPORT, DYNAMIC_APP_CONFIG_IMPORT).replace("const args = { configSchema };", "const args = { configSchema: appConfig.businessConfig.schema };");
|
|
666
|
-
return template;
|
|
777
|
+
await prepareStaticAppConfigImportAlias();
|
|
667
778
|
}
|
|
668
779
|
/**
|
|
669
780
|
* Read an extension point's ext.config.yaml file and return it as a JS object.
|
|
@@ -673,8 +784,8 @@ async function readExtConfig(extensionPointId) {
|
|
|
673
784
|
const extConfigPath = join(await getProjectRootDirectory(), getExtConfigPath(extensionPointId));
|
|
674
785
|
try {
|
|
675
786
|
return {
|
|
676
|
-
|
|
677
|
-
|
|
787
|
+
doc: await readYamlFile(extConfigPath),
|
|
788
|
+
path: extConfigPath
|
|
678
789
|
};
|
|
679
790
|
} catch (error) {
|
|
680
791
|
const reason = error instanceof Error ? error.message : "Unexpected error while reading the file.";
|
|
@@ -682,12 +793,12 @@ async function readExtConfig(extensionPointId) {
|
|
|
682
793
|
`Could not read ext.config.yaml for ${extensionPointId} at ${extConfigPath}.`,
|
|
683
794
|
`Make sure the file exists and is valid YAML. You can regenerate it with "aio-commerce-lib-app generate actions".`,
|
|
684
795
|
`Reason: ${reason}`
|
|
685
|
-
].join("\n"));
|
|
796
|
+
].join("\n"), { cause: error });
|
|
686
797
|
}
|
|
687
798
|
}
|
|
688
799
|
/** Update the ext.config.yaml file */
|
|
689
800
|
async function updateExtConfig(appConfig, extensionPointId) {
|
|
690
|
-
consola
|
|
801
|
+
consola.info(`Updating ext.config.yaml for ${extensionPointId}...`);
|
|
691
802
|
await makeOutputDirFor(getExtensionPointFolderPath(extensionPointId));
|
|
692
803
|
const { path: extConfigPath, doc: extConfigDoc } = await readExtConfig(extensionPointId);
|
|
693
804
|
let extConfig;
|
|
@@ -698,33 +809,164 @@ async function updateExtConfig(appConfig, extensionPointId) {
|
|
|
698
809
|
case CONFIGURATION_EXTENSION_POINT_ID:
|
|
699
810
|
extConfig = buildBusinessConfigurationExtConfig();
|
|
700
811
|
break;
|
|
701
|
-
case
|
|
702
|
-
extConfig =
|
|
812
|
+
case BACKEND_UI_V2_EXTENSION_POINT_ID:
|
|
813
|
+
extConfig = buildAdminUiV2ExtConfig(appConfig);
|
|
703
814
|
break;
|
|
704
815
|
}
|
|
705
816
|
await createOrUpdateExtConfig(extConfigPath, extConfig, extConfigDoc);
|
|
706
817
|
return extConfig;
|
|
707
818
|
}
|
|
819
|
+
/**
|
|
820
|
+
* Resolve the generated web-src entrypoint path from an extension config.
|
|
821
|
+
* @param extConfig - Extension config containing the view operation.
|
|
822
|
+
* @param extensionPointId - Extension point that owns the web source folder.
|
|
823
|
+
*/
|
|
824
|
+
function getWebSourceEntrypoint(extConfig, extensionPointId) {
|
|
825
|
+
const viewEntrypoint = extConfig.operations?.view?.[0]?.impl;
|
|
826
|
+
if (viewEntrypoint === void 0) return null;
|
|
827
|
+
return join(getExtensionPointFolderPath(extensionPointId), extConfig.web ?? "web-src", viewEntrypoint);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Ensure package.json has the dependencies and Parcel config needed by web-src.
|
|
831
|
+
* @param projectRoot - Project root containing the package.json to update.
|
|
832
|
+
*/
|
|
833
|
+
async function prepareWebSourcePackage(projectRoot, extension) {
|
|
834
|
+
const pkg = await loadPackageJson(projectRoot);
|
|
835
|
+
if (pkg === null) throw new Error("Could not find package.json.");
|
|
836
|
+
const requiredDevDependencies = [...WEB_SOURCE_DEV_DEPENDENCIES, ...extension === "tsx" ? WEB_SOURCE_TS_DEV_DEPENDENCIES : []];
|
|
837
|
+
const installPlan = await getPackageDependencyInstallPlan([...WEB_SOURCE_DEPENDENCIES, ...requiredDevDependencies], projectRoot);
|
|
838
|
+
if (installPlan.incompatible.length > 0) {
|
|
839
|
+
const incompatibleDependencies = installPlan.incompatible.map(({ name, version, installedVersion }) => `${name}@${installedVersion} does not satisfy ${version}`).join("\n");
|
|
840
|
+
throw new Error(`Cannot scaffold web-src because installed dependencies are incompatible:\n${incompatibleDependencies}`);
|
|
841
|
+
}
|
|
842
|
+
const dependencies = pkg.content.dependencies ?? {};
|
|
843
|
+
const devDependencies = pkg.content.devDependencies ?? {};
|
|
844
|
+
const dependencyMaps = [dependencies, devDependencies];
|
|
845
|
+
const declaredDependencyNames = new Set(dependencyMaps.flatMap((depMap) => Object.keys(depMap)));
|
|
846
|
+
const dependenciesToDeclare = [...WEB_SOURCE_DEPENDENCIES, ...requiredDevDependencies].filter(({ name }) => !declaredDependencyNames.has(name));
|
|
847
|
+
if (dependenciesToDeclare.length > 0) {
|
|
848
|
+
consola.info("Adding web-src dependencies in package.json:");
|
|
849
|
+
consola.log.raw(formatTree(dependenciesToDeclare.map(({ name, version }) => ` ${name}@${version}`)));
|
|
850
|
+
} else consola.info("web-src dependencies are already declared in package.json.");
|
|
851
|
+
pkg.update({
|
|
852
|
+
"@parcel/bundler-default": {
|
|
853
|
+
...pkg.content["@parcel/bundler-default"],
|
|
854
|
+
manualSharedBundles: WEB_SOURCE_SHARED_BUNDLES
|
|
855
|
+
},
|
|
856
|
+
"@parcel/resolver-default": {
|
|
857
|
+
...pkg.content["@parcel/resolver-default"],
|
|
858
|
+
packageExports: true
|
|
859
|
+
},
|
|
860
|
+
dependencies: mergePackageJsonDependencies(dependencies, WEB_SOURCE_DEPENDENCIES, dependencyMaps),
|
|
861
|
+
devDependencies: mergePackageJsonDependencies(devDependencies, requiredDevDependencies, dependencyMaps)
|
|
862
|
+
});
|
|
863
|
+
await pkg.save();
|
|
864
|
+
if (installPlan.missing.length === 0) {
|
|
865
|
+
consola.info("web-src dependencies are already installed.");
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
consola.info("Installing missing web-src dependencies from package.json:");
|
|
869
|
+
consola.log.raw(formatTree(installPlan.missing.map(({ name, version }) => ` ${name}@${version}`)));
|
|
870
|
+
runProjectInstall(await detectPackageManager(projectRoot), projectRoot);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Add the package import alias for an existing or generated web-src.
|
|
874
|
+
* @param extConfig - Extension config containing the view operation.
|
|
875
|
+
*/
|
|
876
|
+
async function prepareWebSourceImportAlias(extConfig) {
|
|
877
|
+
const entrypoint = getWebSourceEntrypoint(extConfig, BACKEND_UI_V2_EXTENSION_POINT_ID);
|
|
878
|
+
if (entrypoint === null) return;
|
|
879
|
+
const pkg = await loadPackageJson(await getProjectRootDirectory());
|
|
880
|
+
if (pkg === null) throw new Error("Could not find package.json.");
|
|
881
|
+
const existingImports = typeof pkg.content.imports === "object" && pkg.content.imports !== null ? pkg.content.imports : {};
|
|
882
|
+
const webSourceSrcPath = join(dirname(entrypoint), "src");
|
|
883
|
+
pkg.update({ imports: {
|
|
884
|
+
...existingImports,
|
|
885
|
+
[WEB_SOURCE_IMPORT_ALIAS]: `${normalizePackageJsonPath(webSourceSrcPath)}/*`
|
|
886
|
+
} });
|
|
887
|
+
await pkg.save();
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Resolve the generated web-src file extension from the app config file type.
|
|
891
|
+
* @param projectRoot - Project root used to find the commerce app config file.
|
|
892
|
+
*/
|
|
893
|
+
async function resolveWebSourceExtension(projectRoot) {
|
|
894
|
+
const configFilePath = await resolveCommerceAppConfig(projectRoot);
|
|
895
|
+
return configFilePath !== null && TYPESCRIPT_CONFIG_EXTENSIONS.has(extname(configFilePath)) ? "tsx" : "jsx";
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Resolve the destination path for a web-src template file.
|
|
899
|
+
* @param templatePath - Template file path relative to its source directory.
|
|
900
|
+
* @param extension - Web source extension to generate.
|
|
901
|
+
*/
|
|
902
|
+
function getWebSourceTemplateTargetPath(templatePath, extension) {
|
|
903
|
+
if (extension === "jsx" || !templatePath.endsWith(".jsx")) return templatePath;
|
|
904
|
+
return `${templatePath.slice(0, -JSX_FILE_EXTENSION.length)}${TSX_FILE_EXTENSION}`;
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Copy web-src templates directly to the final file extension and entrypoint.
|
|
908
|
+
* @param sourceDir - Template web-src directory.
|
|
909
|
+
* @param targetDir - Generated web-src directory.
|
|
910
|
+
* @param extension - Web source extension to generate.
|
|
911
|
+
*/
|
|
912
|
+
async function copyWebSourceTemplates(sourceDir, targetDir, extension, appTitle) {
|
|
913
|
+
await mkdir(targetDir, { recursive: true });
|
|
914
|
+
const entries = await readdir(sourceDir, { withFileTypes: true });
|
|
915
|
+
return (await Promise.all(entries.map(async (entry) => {
|
|
916
|
+
const sourcePath = join(sourceDir, entry.name);
|
|
917
|
+
const targetPath = join(targetDir, getWebSourceTemplateTargetPath(entry.name, extension));
|
|
918
|
+
if (entry.isDirectory()) return await copyWebSourceTemplates(sourcePath, targetPath, extension, appTitle);
|
|
919
|
+
let content = await readFile(sourcePath, "utf-8");
|
|
920
|
+
if (extension === "tsx") content = content.replaceAll(`${JSX_FILE_EXTENSION}"`, `${TSX_FILE_EXTENSION}"`);
|
|
921
|
+
if (targetPath.endsWith("index.html")) content = content.replaceAll(APP_TITLE_PLACEHOLDER, appTitle);
|
|
922
|
+
await writeFile(targetPath, content, {
|
|
923
|
+
encoding: "utf-8",
|
|
924
|
+
flag: "wx"
|
|
925
|
+
});
|
|
926
|
+
return ` ${relative(process.cwd(), targetPath)}`;
|
|
927
|
+
}))).flat();
|
|
928
|
+
}
|
|
929
|
+
/** Generate the web source scaffold for iframe-based Admin UI extensions. */
|
|
930
|
+
async function generateWebSrc(extConfig, extensionPointId, appName, templatesDir = TEMPLATES_DIR) {
|
|
931
|
+
const entrypoint = getWebSourceEntrypoint(extConfig, extensionPointId);
|
|
932
|
+
if (entrypoint === null) return;
|
|
933
|
+
const projectRoot = await getProjectRootDirectory();
|
|
934
|
+
const entrypointPath = join(projectRoot, entrypoint);
|
|
935
|
+
if (existsSync(entrypointPath)) {
|
|
936
|
+
consola.info(`web-src entrypoint already exists, skipping scaffold: ${relative(process.cwd(), entrypointPath)}`);
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
consola.start(`Scaffolding web-src for ${extensionPointId}...`);
|
|
940
|
+
const sourceDir = join(templatesDir, "admin-ui", "web-src");
|
|
941
|
+
const targetDir = dirname(entrypointPath);
|
|
942
|
+
const extension = await resolveWebSourceExtension(projectRoot);
|
|
943
|
+
const outputFiles = await copyWebSourceTemplates(sourceDir, targetDir, extension, appName);
|
|
944
|
+
if (extension === "tsx") {
|
|
945
|
+
const tsconfigPath = join(targetDir, WEB_SOURCE_TSCONFIG_FILE);
|
|
946
|
+
await writeFile(tsconfigPath, JSON.stringify(WEB_SOURCE_TSCONFIG, null, 2), "utf-8");
|
|
947
|
+
outputFiles.push(` ${relative(process.cwd(), tsconfigPath)}`);
|
|
948
|
+
}
|
|
949
|
+
await prepareWebSourcePackage(projectRoot, extension);
|
|
950
|
+
consola.success(`Scaffolded ${relative(process.cwd(), targetDir)}`);
|
|
951
|
+
consola.log.raw(formatTree(outputFiles));
|
|
952
|
+
}
|
|
708
953
|
/** Generate the action files */
|
|
709
954
|
async function generateActionFiles(appManifest, actions, extensionPointId, templatesDir) {
|
|
710
|
-
consola
|
|
955
|
+
consola.start("Generating runtime actions...");
|
|
711
956
|
await makeOutputDirFor(getActionsDir(extensionPointId));
|
|
712
957
|
const projectRoot = await getProjectRootDirectory();
|
|
713
|
-
const outputFiles =
|
|
714
|
-
const useDynamicImports = hasDynamicAppConfig(appManifest);
|
|
715
|
-
for (const action of actions) {
|
|
958
|
+
const outputFiles = await Promise.all(actions.map(async (action) => {
|
|
716
959
|
let template = await readFile(join(templatesDir, action.templateFile), "utf-8");
|
|
717
|
-
if (useDynamicImports) template = applyRuntimeAppConfigImport(template, action.name);
|
|
718
960
|
if (action.name === "installation") {
|
|
719
961
|
const scriptsTemplate = await generateCustomScriptsTemplate(await readFile(join(templatesDir, "app-management", "custom-scripts.js.template"), "utf-8"), appManifest);
|
|
720
962
|
template = applyCustomScripts(template, scriptsTemplate);
|
|
721
963
|
}
|
|
722
964
|
const actionPath = join(projectRoot, getActionPath(extensionPointId, action.name));
|
|
723
965
|
await writeFile(actionPath, template, "utf-8");
|
|
724
|
-
|
|
725
|
-
}
|
|
726
|
-
consola
|
|
727
|
-
consola
|
|
966
|
+
return ` ${relative(process.cwd(), actionPath)}`;
|
|
967
|
+
}));
|
|
968
|
+
consola.success(`Generated ${actions.length} action(s)`);
|
|
969
|
+
consola.log.raw(formatTree(outputFiles));
|
|
728
970
|
}
|
|
729
971
|
/**
|
|
730
972
|
* Applies the given custom scripts template code to the given installation template.
|
|
@@ -733,7 +975,7 @@ async function generateActionFiles(appManifest, actions, extensionPointId, templ
|
|
|
733
975
|
*/
|
|
734
976
|
function applyCustomScripts(installationTemplate, customScriptsTemplate) {
|
|
735
977
|
if (customScriptsTemplate !== null) return installationTemplate.replace(CUSTOM_SCRIPTS_LOADER_PLACEHOLDER, customScriptsTemplate).replace("const args = { appConfig };", "const args = { appConfig, customScriptsLoader };");
|
|
736
|
-
consola
|
|
978
|
+
consola.debug("No custom installation steps found, skipping custom-scripts.js generation...");
|
|
737
979
|
return installationTemplate.replace(CUSTOM_SCRIPTS_LOADER_PLACEHOLDER, "// No custom installation scripts configured");
|
|
738
980
|
}
|
|
739
981
|
/**
|
|
@@ -745,7 +987,8 @@ async function generateCustomScriptsTemplate(template, appManifest) {
|
|
|
745
987
|
const installationActionDir = join(projectRoot, getActionsDir(EXTENSIBILITY_EXTENSION_POINT_ID));
|
|
746
988
|
const customSteps = appManifest.installation.customInstallationSteps;
|
|
747
989
|
const importStatements = customSteps.map((step, index) => {
|
|
748
|
-
|
|
990
|
+
const absoluteScriptPath = join(projectRoot, step.script);
|
|
991
|
+
let relativeImportPath = relative(installationActionDir, absoluteScriptPath);
|
|
749
992
|
if (!relativeImportPath.startsWith(".")) relativeImportPath = `./${relativeImportPath}`;
|
|
750
993
|
relativeImportPath = relativeImportPath.replace(/\\/g, "/");
|
|
751
994
|
return `import * as ${`customScript${index}`} from "${relativeImportPath}";`;
|
|
@@ -756,23 +999,6 @@ async function generateCustomScriptsTemplate(template, appManifest) {
|
|
|
756
999
|
}).join("\n");
|
|
757
1000
|
return template.replace(CUSTOM_IMPORTS_PLACEHOLDER, importStatements).replace(CUSTOM_SCRIPTS_MAP_PLACEHOLDER, scriptMap);
|
|
758
1001
|
}
|
|
759
|
-
/**
|
|
760
|
-
* Generates `registration/index.js` with the Admin UI SDK registration config
|
|
761
|
-
* inlined as a JS object literal.
|
|
762
|
-
* @param appManifest - The validated app config; must satisfy `hasAdminUiSdk`.
|
|
763
|
-
* @param extensionPointId - The extension point ID that owns the registration action.
|
|
764
|
-
* @param templatesDir - The root directory containing the action templates.
|
|
765
|
-
*/
|
|
766
|
-
async function generateRegistrationActionFile(appManifest, extensionPointId, templatesDir = TEMPLATES_DIR) {
|
|
767
|
-
consola$1.start("Generating Admin UI SDK registration action...");
|
|
768
|
-
await makeOutputDirFor(getAdminUiSdkActionsDir(extensionPointId));
|
|
769
|
-
const projectRoot = await getProjectRootDirectory();
|
|
770
|
-
const template = await readFile(join(templatesDir, "admin-ui-sdk", "registration.js.template"), "utf-8");
|
|
771
|
-
const { registration } = appManifest.adminUiSdk;
|
|
772
|
-
const actionPath = join(projectRoot, getAdminUiSdkRegistrationActionPath(extensionPointId));
|
|
773
|
-
await writeFile(actionPath, await prettierFormat(template.replace(REGISTRATION_JSON_PLACEHOLDER, `const registration = ${stringify(registration)};`), actionPath), "utf-8");
|
|
774
|
-
consola$1.success(`Generated registration action at ${relative(process.cwd(), actionPath)}`);
|
|
775
|
-
}
|
|
776
1002
|
|
|
777
1003
|
//#endregion
|
|
778
1004
|
//#region source/commands/generate/actions/main.ts
|
|
@@ -785,9 +1011,12 @@ async function run$5(appManifest, templatesDir = TEMPLATES_DIR) {
|
|
|
785
1011
|
await prepareRuntimeAppConfigModule(appManifest);
|
|
786
1012
|
await generateActionFiles(appManifest, getRuntimeActions(await updateExtConfig(appManifest, EXTENSIBILITY_EXTENSION_POINT_ID), "app-management"), EXTENSIBILITY_EXTENSION_POINT_ID, templatesDir);
|
|
787
1013
|
if (hasBusinessConfigSchema(appManifest)) await generateActionFiles(appManifest, getRuntimeActions(await updateExtConfig(appManifest, CONFIGURATION_EXTENSION_POINT_ID), "business-configuration"), CONFIGURATION_EXTENSION_POINT_ID, templatesDir);
|
|
788
|
-
if (
|
|
789
|
-
await updateExtConfig(appManifest,
|
|
790
|
-
|
|
1014
|
+
if (hasAdminUi(appManifest)) {
|
|
1015
|
+
const extConfig = await updateExtConfig(appManifest, BACKEND_UI_V2_EXTENSION_POINT_ID);
|
|
1016
|
+
if (extConfig.operations?.view) {
|
|
1017
|
+
await prepareWebSourceImportAlias(extConfig);
|
|
1018
|
+
await generateWebSrc(extConfig, BACKEND_UI_V2_EXTENSION_POINT_ID, appManifest.metadata.displayName, templatesDir);
|
|
1019
|
+
}
|
|
791
1020
|
}
|
|
792
1021
|
}
|
|
793
1022
|
/** Run the generate actions command */
|
|
@@ -795,8 +1024,8 @@ async function exec$5() {
|
|
|
795
1024
|
try {
|
|
796
1025
|
await run$5(await loadAppManifest());
|
|
797
1026
|
} catch (error) {
|
|
798
|
-
if (error instanceof CommerceSdkValidationError) consola
|
|
799
|
-
else consola
|
|
1027
|
+
if (error instanceof CommerceSdkValidationError) consola.error(error.display());
|
|
1028
|
+
else consola.error(error);
|
|
800
1029
|
process.exit(1);
|
|
801
1030
|
}
|
|
802
1031
|
}
|
|
@@ -808,22 +1037,22 @@ async function run$4(appConfig) {
|
|
|
808
1037
|
const stalePath = join(await getProjectRootDirectory(), getManifestPath());
|
|
809
1038
|
if (await access(stalePath).then(() => true, () => false)) {
|
|
810
1039
|
await rm(stalePath, { force: true });
|
|
811
|
-
consola
|
|
1040
|
+
consola.success(`Removed stale ${APP_MANIFEST_FILE}`);
|
|
812
1041
|
}
|
|
813
1042
|
return;
|
|
814
1043
|
}
|
|
815
|
-
consola
|
|
816
|
-
const contents = stringify
|
|
1044
|
+
consola.info("Generating app manifest...");
|
|
1045
|
+
const contents = stringify(appConfig, null, 2);
|
|
817
1046
|
await writeFile(join(await makeOutputDirFor(getGeneratedDir(EXTENSIBILITY_EXTENSION_POINT_ID)), APP_MANIFEST_FILE), contents, "utf-8");
|
|
818
|
-
consola
|
|
1047
|
+
consola.success(`Generated ${APP_MANIFEST_FILE}\n`);
|
|
819
1048
|
}
|
|
820
1049
|
/** Run the generate manifest command */
|
|
821
1050
|
async function exec$4() {
|
|
822
1051
|
try {
|
|
823
1052
|
await run$4(await loadAppManifest());
|
|
824
1053
|
} catch (error) {
|
|
825
|
-
if (error instanceof CommerceSdkValidationError) consola
|
|
826
|
-
else consola
|
|
1054
|
+
if (error instanceof CommerceSdkValidationError) consola.error(error.display());
|
|
1055
|
+
else consola.error(error);
|
|
827
1056
|
process.exit(1);
|
|
828
1057
|
}
|
|
829
1058
|
}
|
|
@@ -844,7 +1073,7 @@ async function touch(filePath) {
|
|
|
844
1073
|
//#region source/commands/generate/schema/main.ts
|
|
845
1074
|
async function run$3(appConfig) {
|
|
846
1075
|
if (!hasBusinessConfigSchema(appConfig)) {
|
|
847
|
-
consola
|
|
1076
|
+
consola.debug("Business configuration schema not found in application configuration. Nothing to do.");
|
|
848
1077
|
return;
|
|
849
1078
|
}
|
|
850
1079
|
const projectDir = await getProjectRootDirectory();
|
|
@@ -860,23 +1089,23 @@ async function run$3(appConfig) {
|
|
|
860
1089
|
const stalePath = join(projectDir, getSchemaPath());
|
|
861
1090
|
if (await access(stalePath).then(() => true, () => false)) {
|
|
862
1091
|
await rm(stalePath, { force: true });
|
|
863
|
-
consola
|
|
1092
|
+
consola.success(`Removed stale ${CONFIG_SCHEMA_FILE_NAME}`);
|
|
864
1093
|
}
|
|
865
1094
|
return;
|
|
866
1095
|
}
|
|
867
|
-
consola
|
|
1096
|
+
consola.info("Generating configuration schema...");
|
|
868
1097
|
const outputDir = await makeOutputDirFor(getGeneratedDir(CONFIGURATION_EXTENSION_POINT_ID));
|
|
869
|
-
const contents = stringify
|
|
1098
|
+
const contents = stringify(appConfig.businessConfig.schema, null, 2);
|
|
870
1099
|
await writeFile(join(outputDir, CONFIG_SCHEMA_FILE_NAME), contents, "utf-8");
|
|
871
|
-
consola
|
|
1100
|
+
consola.success(`Generated ${CONFIG_SCHEMA_FILE_NAME}\n`);
|
|
872
1101
|
}
|
|
873
1102
|
/** Run the generate schema command */
|
|
874
1103
|
async function exec$3() {
|
|
875
1104
|
try {
|
|
876
1105
|
await run$3(await loadAppManifest());
|
|
877
1106
|
} catch (error) {
|
|
878
|
-
if (error instanceof CommerceSdkValidationError) consola
|
|
879
|
-
else consola
|
|
1107
|
+
if (error instanceof CommerceSdkValidationError) consola.error(error.display());
|
|
1108
|
+
else consola.error(error);
|
|
880
1109
|
process.exit(1);
|
|
881
1110
|
}
|
|
882
1111
|
}
|
|
@@ -890,12 +1119,12 @@ async function run$2(appManifest, templatesDir) {
|
|
|
890
1119
|
}
|
|
891
1120
|
/** Runs the postinstall hook */
|
|
892
1121
|
async function exec$2() {
|
|
893
|
-
consola.debug("Running lib-app postinstall hook");
|
|
1122
|
+
consola$1.debug("Running lib-app postinstall hook");
|
|
894
1123
|
try {
|
|
895
1124
|
await run$2(await loadAppManifest());
|
|
896
1125
|
} catch (error) {
|
|
897
|
-
if (error instanceof CommerceSdkValidationError) consola.error(error.display());
|
|
898
|
-
else consola.error(error);
|
|
1126
|
+
if (error instanceof CommerceSdkValidationError) consola$1.error(error.display());
|
|
1127
|
+
else consola$1.error(error);
|
|
899
1128
|
process.exit(1);
|
|
900
1129
|
}
|
|
901
1130
|
}
|
|
@@ -910,10 +1139,10 @@ const { context } = aioIms;
|
|
|
910
1139
|
const IMS_KEYS = {
|
|
911
1140
|
client_id: "AIO_COMMERCE_AUTH_IMS_CLIENT_ID",
|
|
912
1141
|
client_secrets: "AIO_COMMERCE_AUTH_IMS_CLIENT_SECRETS",
|
|
913
|
-
|
|
914
|
-
technical_account_id: "AIO_COMMERCE_AUTH_IMS_TECHNICAL_ACCOUNT_ID",
|
|
1142
|
+
ims_org_id: "AIO_COMMERCE_AUTH_IMS_ORG_ID",
|
|
915
1143
|
scopes: "AIO_COMMERCE_AUTH_IMS_SCOPES",
|
|
916
|
-
|
|
1144
|
+
technical_account_email: "AIO_COMMERCE_AUTH_IMS_TECHNICAL_ACCOUNT_EMAIL",
|
|
1145
|
+
technical_account_id: "AIO_COMMERCE_AUTH_IMS_TECHNICAL_ACCOUNT_ID"
|
|
917
1146
|
};
|
|
918
1147
|
/**
|
|
919
1148
|
* Replaces or creates an environment variable in a .env file
|
|
@@ -945,7 +1174,7 @@ function resolveEnvPath() {
|
|
|
945
1174
|
}
|
|
946
1175
|
/** Resolves the IMS server to server context from the project workspace credentials. */
|
|
947
1176
|
function resolveImsS2SContext() {
|
|
948
|
-
const [credential] = (config.get("project.workspace.details.credentials") ?? []).filter(({ integration_type }) => integration_type === "oauth_server_to_server").map(({ name }) => name)
|
|
1177
|
+
const [credential] = (config.get("project.workspace.details.credentials") ?? []).filter(({ integration_type }) => integration_type === "oauth_server_to_server").map(({ name }) => name);
|
|
949
1178
|
if (!credential) return Promise.resolve(null);
|
|
950
1179
|
return context.get(credential);
|
|
951
1180
|
}
|
|
@@ -988,7 +1217,7 @@ async function run$1(extension, templatesDir = TEMPLATES_DIR) {
|
|
|
988
1217
|
const { doc: extensibilityExtConfig } = await readExtConfig(EXTENSIBILITY_EXTENSION_POINT_ID);
|
|
989
1218
|
await run$4(appManifest);
|
|
990
1219
|
await generateActionFiles(appManifest, getRuntimeActions(extensibilityExtConfig.toJS(), "app-management"), EXTENSIBILITY_EXTENSION_POINT_ID, templatesDir);
|
|
991
|
-
consola.info("Syncing IMS credentials...");
|
|
1220
|
+
consola$1.info("Syncing IMS credentials...");
|
|
992
1221
|
await syncImsCredentials();
|
|
993
1222
|
return;
|
|
994
1223
|
}
|
|
@@ -998,22 +1227,28 @@ async function run$1(extension, templatesDir = TEMPLATES_DIR) {
|
|
|
998
1227
|
await generateActionFiles(appManifest, getRuntimeActions(businessConfigExtConfig.toJS(), "business-configuration"), CONFIGURATION_EXTENSION_POINT_ID, templatesDir);
|
|
999
1228
|
return;
|
|
1000
1229
|
}
|
|
1001
|
-
if (extension === "backend-ui/
|
|
1002
|
-
if (
|
|
1230
|
+
if (extension === "backend-ui/2") {
|
|
1231
|
+
if (hasAdminUi(appManifest)) {
|
|
1232
|
+
const extConfig = await updateExtConfig(appManifest, BACKEND_UI_V2_EXTENSION_POINT_ID);
|
|
1233
|
+
if (extConfig.operations?.view) {
|
|
1234
|
+
await prepareWebSourceImportAlias(extConfig);
|
|
1235
|
+
await generateWebSrc(extConfig, BACKEND_UI_V2_EXTENSION_POINT_ID, appManifest.metadata.displayName, templatesDir);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1003
1238
|
return;
|
|
1004
1239
|
}
|
|
1005
1240
|
throw new Error(`Unsupported extension: ${extension}`);
|
|
1006
1241
|
}
|
|
1007
1242
|
/** Runs the pre-app-build hook */
|
|
1008
1243
|
async function exec$1() {
|
|
1009
|
-
consola.debug("Running lib-app pre-app-build hook");
|
|
1010
|
-
const
|
|
1244
|
+
consola$1.debug("Running lib-app pre-app-build hook");
|
|
1245
|
+
const rawExtension = process.env.EXTENSION;
|
|
1011
1246
|
try {
|
|
1012
|
-
if (!
|
|
1013
|
-
await run$1(
|
|
1247
|
+
if (!rawExtension) throw new Error("EXTENSION environment variable is not set");
|
|
1248
|
+
await run$1(rawExtension);
|
|
1014
1249
|
} catch (error) {
|
|
1015
|
-
if (error instanceof CommerceSdkValidationError) consola.error(error.display());
|
|
1016
|
-
else consola.error(error);
|
|
1250
|
+
if (error instanceof CommerceSdkValidationError) consola$1.error(error.display());
|
|
1251
|
+
else consola$1.error(error);
|
|
1017
1252
|
process.exit(1);
|
|
1018
1253
|
}
|
|
1019
1254
|
}
|
|
@@ -1023,77 +1258,77 @@ async function exec$1() {
|
|
|
1023
1258
|
/** The default values for the features of the commerce app config. */
|
|
1024
1259
|
const DOMAIN_DEFAULTS = {
|
|
1025
1260
|
businessConfig: { schema: [{
|
|
1026
|
-
type: "list",
|
|
1027
|
-
name: "sampleList",
|
|
1028
|
-
label: "Sample List",
|
|
1029
|
-
selectionMode: "multiple",
|
|
1030
1261
|
default: ["a"],
|
|
1262
|
+
label: "Sample List",
|
|
1263
|
+
name: "sampleList",
|
|
1031
1264
|
options: [{
|
|
1032
1265
|
label: "Option A",
|
|
1033
1266
|
value: "a"
|
|
1034
1267
|
}, {
|
|
1035
1268
|
label: "Option B",
|
|
1036
1269
|
value: "b"
|
|
1037
|
-
}]
|
|
1270
|
+
}],
|
|
1271
|
+
selectionMode: "multiple",
|
|
1272
|
+
type: "list"
|
|
1038
1273
|
}, {
|
|
1039
|
-
|
|
1040
|
-
name: "sampleText",
|
|
1274
|
+
default: "Hello, world!",
|
|
1041
1275
|
label: "Sample Text",
|
|
1042
|
-
|
|
1276
|
+
name: "sampleText",
|
|
1277
|
+
type: "text"
|
|
1043
1278
|
}] },
|
|
1044
1279
|
"eventing.commerce": [{
|
|
1045
|
-
provider: {
|
|
1046
|
-
label: "Commerce Events Provider",
|
|
1047
|
-
description: "A description for your Commerce Events provider."
|
|
1048
|
-
},
|
|
1049
1280
|
events: [{
|
|
1050
|
-
|
|
1281
|
+
description: "Use case description for the event.",
|
|
1051
1282
|
fields: [{ name: "*" }],
|
|
1052
1283
|
label: "Sample Event",
|
|
1053
|
-
|
|
1284
|
+
name: "plugin.sample_event",
|
|
1054
1285
|
runtimeActions: ["my-package/handle-sample-event"]
|
|
1055
|
-
}]
|
|
1286
|
+
}],
|
|
1287
|
+
provider: {
|
|
1288
|
+
description: "A description for your Commerce Events provider.",
|
|
1289
|
+
label: "Commerce Events Provider"
|
|
1290
|
+
}
|
|
1056
1291
|
}],
|
|
1057
1292
|
"eventing.external": [{
|
|
1058
|
-
provider: {
|
|
1059
|
-
label: "External Events Provider",
|
|
1060
|
-
description: "A description for your External Events provider."
|
|
1061
|
-
},
|
|
1062
1293
|
events: [{
|
|
1063
|
-
name: "be-observer.sample_event",
|
|
1064
|
-
label: "Sample Event",
|
|
1065
1294
|
description: "Use case description for the event.",
|
|
1295
|
+
label: "Sample Event",
|
|
1296
|
+
name: "be-observer.sample_event",
|
|
1066
1297
|
runtimeActions: ["my-package/handle-sample-event"]
|
|
1067
|
-
}]
|
|
1298
|
+
}],
|
|
1299
|
+
provider: {
|
|
1300
|
+
description: "A description for your External Events provider.",
|
|
1301
|
+
label: "External Events Provider"
|
|
1302
|
+
}
|
|
1068
1303
|
}],
|
|
1069
1304
|
"installation.customInstallationSteps": [{
|
|
1070
|
-
name: "sample-step",
|
|
1071
1305
|
description: "Use case description for the step.",
|
|
1306
|
+
name: "sample-step",
|
|
1072
1307
|
script: "./path/to/script.js"
|
|
1073
1308
|
}],
|
|
1074
1309
|
webhooks: [{
|
|
1075
|
-
|
|
1310
|
+
category: "modification",
|
|
1076
1311
|
description: "A sample Commerce Webhook handler.",
|
|
1312
|
+
label: "Sample Webhook",
|
|
1077
1313
|
runtimeAction: "my-package/handle-webhook",
|
|
1078
|
-
category: "modification",
|
|
1079
1314
|
webhook: {
|
|
1080
|
-
webhook_method: "plugin.sample.event",
|
|
1081
|
-
webhook_type: "after",
|
|
1082
1315
|
batch_name: "my_app",
|
|
1083
1316
|
hook_name: "sample_hook",
|
|
1084
|
-
method: "POST"
|
|
1317
|
+
method: "POST",
|
|
1318
|
+
webhook_method: "plugin.sample.event",
|
|
1319
|
+
webhook_type: "after"
|
|
1085
1320
|
}
|
|
1086
1321
|
}, {
|
|
1087
|
-
label: "Sample Webhook with URL",
|
|
1088
|
-
description: "A sample Commerce Webhook handler using an explicit URL.",
|
|
1089
1322
|
category: "modification",
|
|
1323
|
+
description: "A sample Commerce Webhook handler using an explicit URL.",
|
|
1324
|
+
label: "Sample Webhook with URL",
|
|
1090
1325
|
webhook: {
|
|
1091
|
-
webhook_method: "plugin.sample.event",
|
|
1092
|
-
webhook_type: "after",
|
|
1093
1326
|
batch_name: "my_app",
|
|
1094
1327
|
hook_name: "sample_hook_url",
|
|
1095
1328
|
method: "POST",
|
|
1096
|
-
url: "https://example.com/webhook"
|
|
1329
|
+
url: "https://example.com/webhook",
|
|
1330
|
+
webhook_method: "plugin.sample.event",
|
|
1331
|
+
webhook_type: "after"
|
|
1097
1332
|
}
|
|
1098
1333
|
}]
|
|
1099
1334
|
};
|
|
@@ -1115,31 +1350,29 @@ function initFlagsToScaffoldAppAnswers(flags) {
|
|
|
1115
1350
|
}
|
|
1116
1351
|
/** Prompt the user to scaffold a new Commerce App configuration. When options are provided, prompts are skipped. */
|
|
1117
1352
|
async function promptForCommerceAppConfig() {
|
|
1118
|
-
const configFormat = await consola.prompt("What format do you want to use for the config file?", {
|
|
1119
|
-
|
|
1353
|
+
const configFormat = await consola$1.prompt("What format do you want to use for the config file?", {
|
|
1354
|
+
cancel: "reject",
|
|
1120
1355
|
default: "ts",
|
|
1121
1356
|
initial: "ts",
|
|
1122
|
-
cancel: "reject",
|
|
1123
1357
|
options: [{
|
|
1358
|
+
hint: "Recommended",
|
|
1124
1359
|
label: "TypeScript",
|
|
1125
|
-
value: "ts"
|
|
1126
|
-
hint: "Recommended"
|
|
1360
|
+
value: "ts"
|
|
1127
1361
|
}, {
|
|
1128
1362
|
label: "JavaScript",
|
|
1129
1363
|
value: "js"
|
|
1130
|
-
}]
|
|
1364
|
+
}],
|
|
1365
|
+
type: "select"
|
|
1131
1366
|
});
|
|
1132
|
-
const appName = await consola.prompt("What is the name of your app?", {
|
|
1133
|
-
|
|
1134
|
-
placeholder: "Application Display Name",
|
|
1367
|
+
const appName = await consola$1.prompt("What is the name of your app?", {
|
|
1368
|
+
cancel: "reject",
|
|
1135
1369
|
default: "My Application",
|
|
1136
|
-
|
|
1370
|
+
placeholder: "Application Display Name",
|
|
1371
|
+
type: "text"
|
|
1137
1372
|
});
|
|
1138
|
-
const featuresToAdd = await consola.prompt(`What features do you want to add to your app? ${colorize("gray", "Space to select/deselect, Enter to submit")}`, {
|
|
1139
|
-
type: "multiselect",
|
|
1140
|
-
initial: [],
|
|
1141
|
-
required: true,
|
|
1373
|
+
const featuresToAdd = await consola$1.prompt(`What features do you want to add to your app? ${colorize("gray", "Space to select/deselect, Enter to submit")}`, {
|
|
1142
1374
|
cancel: "reject",
|
|
1375
|
+
initial: [],
|
|
1143
1376
|
options: [
|
|
1144
1377
|
{
|
|
1145
1378
|
label: "Business Configuration",
|
|
@@ -1161,16 +1394,18 @@ async function promptForCommerceAppConfig() {
|
|
|
1161
1394
|
label: "Custom Installation Steps",
|
|
1162
1395
|
value: "installation.customInstallationSteps"
|
|
1163
1396
|
}
|
|
1164
|
-
]
|
|
1397
|
+
],
|
|
1398
|
+
required: true,
|
|
1399
|
+
type: "multiselect"
|
|
1165
1400
|
});
|
|
1166
1401
|
const configFile = `${COMMERCE_APP_CONFIG_FILE}.${configFormat}`;
|
|
1167
1402
|
const domains = new Set(featuresToAdd);
|
|
1168
|
-
consola.log("");
|
|
1403
|
+
consola$1.log("");
|
|
1169
1404
|
return {
|
|
1170
1405
|
appName,
|
|
1171
1406
|
configFile,
|
|
1172
|
-
|
|
1173
|
-
|
|
1407
|
+
configFormat,
|
|
1408
|
+
domains
|
|
1174
1409
|
};
|
|
1175
1410
|
}
|
|
1176
1411
|
/** Create the default commerce app config file content */
|
|
@@ -1179,10 +1414,10 @@ async function getDefaultCommerceAppConfig(cwd, { appName, configFormat, domains
|
|
|
1179
1414
|
const exportKeyword = needsESM ? "export default" : "module.exports =";
|
|
1180
1415
|
const importStatement = needsESM ? "import { defineConfig } from \"@adobe/aio-commerce-lib-app/config\";" : "const { defineConfig } = require(\"@adobe/aio-commerce-lib-app/config\");";
|
|
1181
1416
|
const defaultConfig = { metadata: {
|
|
1182
|
-
|
|
1417
|
+
description: "A custom Adobe Commerce application. Fill description for your app.",
|
|
1183
1418
|
displayName: appName,
|
|
1184
|
-
|
|
1185
|
-
|
|
1419
|
+
id: appName.toLowerCase().replace(/ /g, "-"),
|
|
1420
|
+
version: "1.0.0"
|
|
1186
1421
|
} };
|
|
1187
1422
|
if (domains.has("businessConfig.schema")) defaultConfig.businessConfig = { schema: DOMAIN_DEFAULTS.businessConfig.schema };
|
|
1188
1423
|
if (domains.has("eventing.commerce")) defaultConfig.eventing = {
|
|
@@ -1222,10 +1457,10 @@ async function addExtensionPointToAppConfig(extensionPointId, rootDirectory, com
|
|
|
1222
1457
|
extensionPointId,
|
|
1223
1458
|
"$include"
|
|
1224
1459
|
]) === includePath) {
|
|
1225
|
-
consola.success(`Extension "${extensionPointId}" already configured in ${APP_CONFIG_FILE}`);
|
|
1460
|
+
consola$1.success(`Extension "${extensionPointId}" already configured in ${APP_CONFIG_FILE}`);
|
|
1226
1461
|
return;
|
|
1227
1462
|
}
|
|
1228
|
-
consola.info(`Adding extension "${extensionPointId}" to ${APP_CONFIG_FILE}...`);
|
|
1463
|
+
consola$1.info(`Adding extension "${extensionPointId}" to ${APP_CONFIG_FILE}...`);
|
|
1229
1464
|
const extensions = getOrCreateMap(doc, ["extensions"], { onBeforeCreate: (pair) => {
|
|
1230
1465
|
pair.key.spaceBefore = true;
|
|
1231
1466
|
} });
|
|
@@ -1255,10 +1490,10 @@ async function addExtensionPointToInstallYaml(extensionPointId, rootDirectory, c
|
|
|
1255
1490
|
throw new Error(`Failed to parse ${INSTALL_YAML_FILE}. \nPlease add manually: \n\n${fallbackContent}`, { cause: error });
|
|
1256
1491
|
}
|
|
1257
1492
|
if (extensions.items.some((item) => isMap(item) && item.get("extensionPointId") === extensionPointId)) {
|
|
1258
|
-
consola.success(`Extension "${extensionPointId}" already configured in ${INSTALL_YAML_FILE}`);
|
|
1493
|
+
consola$1.success(`Extension "${extensionPointId}" already configured in ${INSTALL_YAML_FILE}`);
|
|
1259
1494
|
return;
|
|
1260
1495
|
}
|
|
1261
|
-
consola.info(`Adding extension "${extensionPointId}" to ${INSTALL_YAML_FILE}...`);
|
|
1496
|
+
consola$1.info(`Adding extension "${extensionPointId}" to ${INSTALL_YAML_FILE}...`);
|
|
1262
1497
|
const extension = doc.createPair("extensionPointId", extensionPointId);
|
|
1263
1498
|
extension.key.spaceBefore = extensions.items.length > 0;
|
|
1264
1499
|
extension.key.commentBefore = commentBefore;
|
|
@@ -1276,7 +1511,7 @@ async function ensureCommerceAppConfig(cwd = process.cwd(), formatConfig = true,
|
|
|
1276
1511
|
} catch {}
|
|
1277
1512
|
if (config) try {
|
|
1278
1513
|
const validatedConfig = validateCommerceAppConfig(config);
|
|
1279
|
-
consola
|
|
1514
|
+
consola.success(`${COMMERCE_APP_CONFIG_FILE} found and is valid. Continuing...`);
|
|
1280
1515
|
return {
|
|
1281
1516
|
config: validatedConfig,
|
|
1282
1517
|
domains: getConfigDomains(validatedConfig)
|
|
@@ -1285,24 +1520,24 @@ async function ensureCommerceAppConfig(cwd = process.cwd(), formatConfig = true,
|
|
|
1285
1520
|
throw new Error(`${COMMERCE_APP_CONFIG_FILE} is invalid`, { cause: error });
|
|
1286
1521
|
}
|
|
1287
1522
|
if (!flags) {
|
|
1288
|
-
consola
|
|
1289
|
-
if (!await consola
|
|
1290
|
-
|
|
1523
|
+
consola.warn(`${COMMERCE_APP_CONFIG_FILE} not found.`);
|
|
1524
|
+
if (!await consola.prompt(`Do you want to create a ${"app.commerce.config"} file? (y/n)`, {
|
|
1525
|
+
default: false,
|
|
1291
1526
|
initial: true,
|
|
1292
|
-
|
|
1527
|
+
type: "confirm"
|
|
1293
1528
|
})) throw new Error("Initialization cancelled.");
|
|
1294
1529
|
}
|
|
1295
1530
|
const answers = flags ? initFlagsToScaffoldAppAnswers(flags) : await promptForCommerceAppConfig();
|
|
1296
1531
|
try {
|
|
1297
1532
|
const configContent = await getDefaultCommerceAppConfig(cwd, answers);
|
|
1298
1533
|
const path = join(await getProjectRootDirectory(cwd), answers.configFile);
|
|
1299
|
-
consola
|
|
1534
|
+
consola.info(`Creating ${answers.configFile}...`);
|
|
1300
1535
|
if (formatConfig) await writeFile(path, await prettierFormat(configContent, path), "utf-8");
|
|
1301
1536
|
else await writeFile(path, configContent, "utf-8");
|
|
1302
|
-
const
|
|
1303
|
-
consola
|
|
1537
|
+
const createdConfig = await parseCommerceAppConfig(cwd);
|
|
1538
|
+
consola.success(`Created ${answers.configFile}`);
|
|
1304
1539
|
return {
|
|
1305
|
-
config,
|
|
1540
|
+
config: createdConfig,
|
|
1306
1541
|
domains: answers.domains
|
|
1307
1542
|
};
|
|
1308
1543
|
} catch (error) {
|
|
@@ -1318,21 +1553,20 @@ async function ensurePackageJson(cwd = process.cwd()) {
|
|
|
1318
1553
|
let packageJson;
|
|
1319
1554
|
if (existing) packageJson = existing;
|
|
1320
1555
|
else {
|
|
1321
|
-
consola
|
|
1556
|
+
consola.warn("package.json not found. Creating one...");
|
|
1322
1557
|
packageJson = {
|
|
1323
1558
|
name: "my-commerce-app",
|
|
1324
|
-
|
|
1325
|
-
|
|
1559
|
+
private: true,
|
|
1560
|
+
version: "1.0.0"
|
|
1326
1561
|
};
|
|
1327
1562
|
await writeFile(join(resolve(cwd), PACKAGE_JSON_FILE), JSON.stringify(packageJson, null, 2), "utf-8");
|
|
1328
|
-
consola
|
|
1563
|
+
consola.success("Wrote package.json");
|
|
1329
1564
|
}
|
|
1330
1565
|
const packageManager = await detectPackageManager(cwd);
|
|
1331
|
-
const execCommand = getExecCommand(packageManager);
|
|
1332
1566
|
return {
|
|
1567
|
+
execCommand: getExecCommand(packageManager),
|
|
1333
1568
|
packageJson,
|
|
1334
|
-
packageManager
|
|
1335
|
-
execCommand
|
|
1569
|
+
packageManager
|
|
1336
1570
|
};
|
|
1337
1571
|
}
|
|
1338
1572
|
/**
|
|
@@ -1342,50 +1576,31 @@ async function ensurePackageJson(cwd = process.cwd()) {
|
|
|
1342
1576
|
*/
|
|
1343
1577
|
async function writePostinstallHook(execCommand, cwd = process.cwd()) {
|
|
1344
1578
|
const postinstallScript = `${execCommand} aio-commerce-lib-app hooks postinstall`;
|
|
1345
|
-
const pkg = await
|
|
1579
|
+
const pkg = await loadPackageJson(cwd);
|
|
1580
|
+
if (pkg === null) throw new Error("Could not find package.json.");
|
|
1346
1581
|
const existing = pkg.content.scripts?.postinstall;
|
|
1347
1582
|
if (existing === postinstallScript || existing?.includes(postinstallScript)) {
|
|
1348
|
-
consola
|
|
1583
|
+
consola.success(`postinstall script already configured in ${PACKAGE_JSON_FILE}`);
|
|
1349
1584
|
return;
|
|
1350
1585
|
}
|
|
1351
1586
|
const nextPostinstall = existing ? `${existing} && ${postinstallScript}` : postinstallScript;
|
|
1352
|
-
if (existing) consola
|
|
1353
|
-
else consola
|
|
1587
|
+
if (existing) consola.warn(`${PACKAGE_JSON_FILE} already has a postinstall script. Adding a new one...`);
|
|
1588
|
+
else consola.info(`Adding postinstall script to ${PACKAGE_JSON_FILE}...`);
|
|
1354
1589
|
pkg.update({ scripts: {
|
|
1355
1590
|
...pkg.content.scripts,
|
|
1356
1591
|
postinstall: nextPostinstall
|
|
1357
1592
|
} });
|
|
1358
1593
|
await pkg.save();
|
|
1359
|
-
consola
|
|
1594
|
+
consola.success(`Added postinstall script to ${PACKAGE_JSON_FILE}`);
|
|
1360
1595
|
}
|
|
1361
1596
|
/** Ensure app.config.yaml has the extension reference */
|
|
1362
1597
|
async function ensureAppConfig(domains, cwd = process.cwd()) {
|
|
1363
1598
|
const rootDirectory = await getProjectRootDirectory(cwd);
|
|
1364
1599
|
if (domains.has("businessConfig.schema")) await addExtensionPointToAppConfig(CONFIGURATION_EXTENSION_POINT_ID, rootDirectory, " This extension is required for business configuration. Do not remove.");
|
|
1365
|
-
if (domains.has("
|
|
1600
|
+
if (domains.has("adminUi")) await addExtensionPointToAppConfig(BACKEND_UI_V2_EXTENSION_POINT_ID, rootDirectory, " This extension is required for Admin UI. Do not remove.");
|
|
1366
1601
|
await addExtensionPointToAppConfig(EXTENSIBILITY_EXTENSION_POINT_ID, rootDirectory, " This extension is required for app management. Do not remove.");
|
|
1367
1602
|
}
|
|
1368
1603
|
/**
|
|
1369
|
-
* Install the given dependencies.
|
|
1370
|
-
* @param packageManager - The detected package manager
|
|
1371
|
-
* @param dependencies - Package specifiers to install; no-op when empty
|
|
1372
|
-
* @param cwd - Working directory for the install command
|
|
1373
|
-
*/
|
|
1374
|
-
function runInstall(packageManager, dependencies, cwd = process.cwd()) {
|
|
1375
|
-
if (dependencies.length === 0) return;
|
|
1376
|
-
const dependencyListString = dependencies.map((dependency) => ` - ${dependency}`).join("\n");
|
|
1377
|
-
consola$1.start([`Installing the following dependencies with ${packageManager}:\n${dependencyListString}\n`, "This may take a few seconds...\n"].join("\n"));
|
|
1378
|
-
const { command, args } = getInstallCommand(packageManager, dependencies);
|
|
1379
|
-
const displayCommand = [command, ...args].join(" ");
|
|
1380
|
-
const result = spawnSync(command, args, {
|
|
1381
|
-
cwd,
|
|
1382
|
-
stdio: "inherit"
|
|
1383
|
-
});
|
|
1384
|
-
if (result.error || result.status !== 0) throw new Error(`Failed to install dependencies automatically. Please install manually: ${displayCommand}`, { cause: result.error ?? /* @__PURE__ */ new Error(`Install exited with code ${result.status}`) });
|
|
1385
|
-
consola$1.log("");
|
|
1386
|
-
consola$1.success("Dependencies installed successfully");
|
|
1387
|
-
}
|
|
1388
|
-
/**
|
|
1389
1604
|
* Install the domain-specific dependencies derived from the selected domains.
|
|
1390
1605
|
* @param packageManager - The detected package manager
|
|
1391
1606
|
* @param domains - Domains enabled in the commerce app config
|
|
@@ -1393,9 +1608,9 @@ function runInstall(packageManager, dependencies, cwd = process.cwd()) {
|
|
|
1393
1608
|
*/
|
|
1394
1609
|
function installDependencies(packageManager, domains, cwd = process.cwd()) {
|
|
1395
1610
|
const packages = [];
|
|
1396
|
-
if (domains.has("businessConfig.schema")) packages.push(`@adobe/aio-commerce-lib-config@^1.
|
|
1611
|
+
if (domains.has("businessConfig.schema")) packages.push(`@adobe/aio-commerce-lib-config@^1.6.0-beta-20260714082406`);
|
|
1397
1612
|
if (packages.length === 0) {
|
|
1398
|
-
consola
|
|
1613
|
+
consola.info("No additional domain dependencies to install.");
|
|
1399
1614
|
return;
|
|
1400
1615
|
}
|
|
1401
1616
|
runInstall(packageManager, packages, cwd);
|
|
@@ -1414,33 +1629,34 @@ async function runGeneration(appConfig, execCommand) {
|
|
|
1414
1629
|
async function ensureInstallYaml(domains, cwd = process.cwd()) {
|
|
1415
1630
|
const rootDirectory = await getProjectRootDirectory(cwd);
|
|
1416
1631
|
if (domains.has("businessConfig.schema")) await addExtensionPointToInstallYaml(CONFIGURATION_EXTENSION_POINT_ID, rootDirectory, " This extension is required for business configuration. Do not remove.");
|
|
1417
|
-
if (domains.has("
|
|
1632
|
+
if (domains.has("adminUi")) await addExtensionPointToInstallYaml(BACKEND_UI_V2_EXTENSION_POINT_ID, rootDirectory, " This extension is required for Admin UI. Do not remove.");
|
|
1418
1633
|
await addExtensionPointToInstallYaml(EXTENSIBILITY_EXTENSION_POINT_ID, rootDirectory, " This extension is required for app management. Do not remove.");
|
|
1419
1634
|
}
|
|
1420
1635
|
|
|
1421
1636
|
//#endregion
|
|
1422
1637
|
//#region source/commands/init/main.ts
|
|
1423
|
-
const REQUIRED_DEPENDENCIES = ["@adobe/aio-commerce-sdk", `@adobe/aio-commerce-lib-app@1.
|
|
1638
|
+
const REQUIRED_DEPENDENCIES = ["@adobe/aio-commerce-sdk", `@adobe/aio-commerce-lib-app@1.8.0-beta-20260714082406`];
|
|
1424
1639
|
/** Initialize the project */
|
|
1425
1640
|
async function run(flags, extraOptions) {
|
|
1426
|
-
consola
|
|
1641
|
+
consola.start("Initializing app...");
|
|
1427
1642
|
const { execCommand, packageManager } = await ensurePackageJson();
|
|
1428
1643
|
runInstall(packageManager, REQUIRED_DEPENDENCIES);
|
|
1429
1644
|
const { config, domains } = await ensureCommerceAppConfig(process.cwd(), extraOptions?.formatConfig ?? true, flags);
|
|
1430
1645
|
installDependencies(packageManager, domains);
|
|
1431
|
-
const pkg = await
|
|
1646
|
+
const pkg = await loadPackageJson(process.cwd());
|
|
1647
|
+
if (pkg === null) throw new Error("Could not find package.json.");
|
|
1432
1648
|
pkg.update({
|
|
1649
|
+
description: config.metadata.description,
|
|
1433
1650
|
name: config.metadata.id,
|
|
1434
|
-
version: config.metadata.version
|
|
1435
|
-
description: config.metadata.description
|
|
1651
|
+
version: config.metadata.version
|
|
1436
1652
|
});
|
|
1437
1653
|
await pkg.save();
|
|
1438
1654
|
await runGeneration(config, execCommand);
|
|
1439
1655
|
await ensureAppConfig(domains);
|
|
1440
1656
|
await ensureInstallYaml(domains);
|
|
1441
1657
|
await writePostinstallHook(execCommand);
|
|
1442
|
-
consola
|
|
1443
|
-
consola
|
|
1658
|
+
consola.success("Initialization complete!");
|
|
1659
|
+
consola.box([
|
|
1444
1660
|
"Next steps:",
|
|
1445
1661
|
" - Review and customize app.commerce.config.*",
|
|
1446
1662
|
" - Build and deploy your app"
|
|
@@ -1451,8 +1667,8 @@ async function exec() {
|
|
|
1451
1667
|
try {
|
|
1452
1668
|
await run();
|
|
1453
1669
|
} catch (error) {
|
|
1454
|
-
if (error instanceof CommerceSdkValidationError) consola
|
|
1455
|
-
else consola
|
|
1670
|
+
if (error instanceof CommerceSdkValidationError) consola.error(error.display());
|
|
1671
|
+
else consola.error(error);
|
|
1456
1672
|
process.exit(1);
|
|
1457
1673
|
}
|
|
1458
1674
|
}
|
|
@@ -1490,17 +1706,17 @@ async function generateAll() {
|
|
|
1490
1706
|
}
|
|
1491
1707
|
/** Command handlers registry mapping command names to their subcommand handlers */
|
|
1492
1708
|
const COMMANDS = {
|
|
1493
|
-
init: exec,
|
|
1494
|
-
hooks: {
|
|
1495
|
-
"pre-app-build": exec$1,
|
|
1496
|
-
postinstall: exec$2
|
|
1497
|
-
},
|
|
1498
1709
|
generate: {
|
|
1499
1710
|
actions: exec$5,
|
|
1711
|
+
all: generateAll,
|
|
1500
1712
|
manifest: exec$4,
|
|
1501
|
-
schema: exec$3
|
|
1502
|
-
|
|
1503
|
-
|
|
1713
|
+
schema: exec$3
|
|
1714
|
+
},
|
|
1715
|
+
hooks: {
|
|
1716
|
+
postinstall: exec$2,
|
|
1717
|
+
"pre-app-build": exec$1
|
|
1718
|
+
},
|
|
1719
|
+
init: exec
|
|
1504
1720
|
};
|
|
1505
1721
|
/**
|
|
1506
1722
|
* Generic command handler that dispatches to specific command implementations
|
|
@@ -1510,8 +1726,8 @@ const COMMANDS = {
|
|
|
1510
1726
|
*/
|
|
1511
1727
|
async function handleCommand(commandName, target, handlers) {
|
|
1512
1728
|
function invalidTargetError(message) {
|
|
1513
|
-
consola.error(message);
|
|
1514
|
-
consola.info(`Available targets: ${Object.keys(handlers).join(" | ")}`);
|
|
1729
|
+
consola$1.error(message);
|
|
1730
|
+
consola$1.info(`Available targets: ${Object.keys(handlers).join(" | ")}`);
|
|
1515
1731
|
process.exit(1);
|
|
1516
1732
|
}
|
|
1517
1733
|
if (!target) invalidTargetError(`No ${commandName} target specified`);
|
|
@@ -1521,14 +1737,14 @@ async function handleCommand(commandName, target, handlers) {
|
|
|
1521
1737
|
}
|
|
1522
1738
|
async function main() {
|
|
1523
1739
|
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
1524
|
-
consola.log.raw(USAGE);
|
|
1740
|
+
consola$1.log.raw(USAGE);
|
|
1525
1741
|
process.exit(0);
|
|
1526
1742
|
}
|
|
1527
1743
|
try {
|
|
1528
1744
|
const handlers = COMMANDS[command];
|
|
1529
1745
|
if (!handlers) {
|
|
1530
|
-
consola.error(`Unknown command: ${command}`);
|
|
1531
|
-
consola.log.raw(USAGE);
|
|
1746
|
+
consola$1.error(`Unknown command: ${command}`);
|
|
1747
|
+
consola$1.log.raw(USAGE);
|
|
1532
1748
|
process.exit(1);
|
|
1533
1749
|
}
|
|
1534
1750
|
if (typeof handlers === "function") {
|
|
@@ -1537,7 +1753,7 @@ async function main() {
|
|
|
1537
1753
|
}
|
|
1538
1754
|
await handleCommand(command, subcommand, handlers);
|
|
1539
1755
|
} catch (error) {
|
|
1540
|
-
consola.error(stringifyError(error));
|
|
1756
|
+
consola$1.error(stringifyError(error));
|
|
1541
1757
|
}
|
|
1542
1758
|
}
|
|
1543
1759
|
main();
|