@sap-ux/app-config-writer 1.1.0 → 1.1.2
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/dist/cards-config/cap.d.ts +17 -0
- package/dist/cards-config/cap.js +31 -0
- package/dist/cards-config/index.js +24 -3
- package/dist/common/cap-utils.d.ts +13 -0
- package/dist/common/cap-utils.js +23 -0
- package/dist/variants-config/cap.d.ts +17 -0
- package/dist/variants-config/cap.js +31 -0
- package/dist/variants-config/generateVariantsConfig.js +25 -1
- package/package.json +4 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the `start-cards-generator-<appFolderName>` script to the CAP root `package.json`.
|
|
5
|
+
* Uses `cds watch --open "<appId><cardGeneratorPath><intent>"` so the app is opened
|
|
6
|
+
* via the CDS development server rather than a standalone UI5 tooling server.
|
|
7
|
+
*
|
|
8
|
+
* @param capRoot - path to the CAP project root
|
|
9
|
+
* @param appId - sap.app.id from the app's manifest.json (used as the URL prefix)
|
|
10
|
+
* @param appFolderName - basename of the app folder (used as the script name suffix)
|
|
11
|
+
* @param basePath - path to the UI5 app root (where ui5.yaml lives)
|
|
12
|
+
* @param fs - mem-fs-editor instance
|
|
13
|
+
* @param yamlPath - optional path to the ui5*.yaml file
|
|
14
|
+
* @param logger - optional logger
|
|
15
|
+
*/
|
|
16
|
+
export declare function updateCapRootPackageJsonForCards(capRoot: string, appId: string, appFolderName: string, basePath: string, fs: Editor, yamlPath?: string, logger?: ToolsLogger): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=cap.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { basename, join } from 'node:path';
|
|
2
|
+
import { FileName, readUi5Yaml } from '@sap-ux/project-access';
|
|
3
|
+
import { getPreviewMiddleware, getIntentFromPreviewConfig } from '../common/utils.js';
|
|
4
|
+
import { writeCdsWatchScript } from '../common/cap-utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Writes the `start-cards-generator-<appFolderName>` script to the CAP root `package.json`.
|
|
7
|
+
* Uses `cds watch --open "<appId><cardGeneratorPath><intent>"` so the app is opened
|
|
8
|
+
* via the CDS development server rather than a standalone UI5 tooling server.
|
|
9
|
+
*
|
|
10
|
+
* @param capRoot - path to the CAP project root
|
|
11
|
+
* @param appId - sap.app.id from the app's manifest.json (used as the URL prefix)
|
|
12
|
+
* @param appFolderName - basename of the app folder (used as the script name suffix)
|
|
13
|
+
* @param basePath - path to the UI5 app root (where ui5.yaml lives)
|
|
14
|
+
* @param fs - mem-fs-editor instance
|
|
15
|
+
* @param yamlPath - optional path to the ui5*.yaml file
|
|
16
|
+
* @param logger - optional logger
|
|
17
|
+
*/
|
|
18
|
+
export async function updateCapRootPackageJsonForCards(capRoot, appId, appFolderName, basePath, fs, yamlPath, logger) {
|
|
19
|
+
const capRootPackageJsonPath = join(capRoot, FileName.Package);
|
|
20
|
+
if (!fs.exists(capRootPackageJsonPath)) {
|
|
21
|
+
throw new Error(`package.json not found at CAP root: ${capRoot}`);
|
|
22
|
+
}
|
|
23
|
+
const ui5YamlFile = yamlPath ? basename(yamlPath) : FileName.Ui5Yaml;
|
|
24
|
+
const ui5YamlConfig = await readUi5Yaml(basePath, ui5YamlFile, fs);
|
|
25
|
+
const previewMiddleware = await getPreviewMiddleware(ui5YamlConfig, basePath, ui5YamlFile, fs);
|
|
26
|
+
const intent = getIntentFromPreviewConfig(previewMiddleware?.configuration) ?? '#app-preview';
|
|
27
|
+
const cardGeneratorPath = previewMiddleware?.configuration?.editors?.cardGenerator?.path ??
|
|
28
|
+
'/test/flpCardGeneratorSandbox.html';
|
|
29
|
+
writeCdsWatchScript(capRoot, `start-cards-generator-${appFolderName}`, `${appId}${cardGeneratorPath}${intent}`, fs, logger);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=cap.js.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { join, basename } from 'node:path';
|
|
2
2
|
import { create as createStorage } from 'mem-fs';
|
|
3
3
|
import { create } from 'mem-fs-editor';
|
|
4
|
-
import { getPreviewMiddleware, getIntentFromPreviewConfig, getCLIForPreview } from '../common/utils.js';
|
|
5
|
-
import { FileName, readUi5Yaml } from '@sap-ux/project-access';
|
|
4
|
+
import { getPreviewMiddleware, getIntentFromPreviewConfig, getCLIForPreview, readManifest } from '../common/utils.js';
|
|
5
|
+
import { FileName, readUi5Yaml, getProjectType, findCapProjectRoot } from '@sap-ux/project-access';
|
|
6
6
|
import { updateMiddlewaresForPreview } from '../common/ui5-yaml.js';
|
|
7
7
|
import { ensureMinUI5Version } from './prerequisites.js';
|
|
8
|
+
import { updateCapRootPackageJsonForCards } from './cap.js';
|
|
8
9
|
const DEPENDENCY_NAME = '@sap-ux/cards-editor-middleware';
|
|
9
10
|
const CARDS_GENERATOR_MIDDLEWARE = 'sap-cards-generator';
|
|
10
11
|
/**
|
|
@@ -93,10 +94,30 @@ export async function enableCardGeneratorConfig(basePath, yamlPath, logger, fs,
|
|
|
93
94
|
fs = fs ?? create(createStorage());
|
|
94
95
|
// asserts minimum UI5 version requirement before proceeding
|
|
95
96
|
await ensureMinUI5Version(basePath, fs);
|
|
97
|
+
const capRoot = await findCapProjectRoot(basePath, false, fs);
|
|
98
|
+
const projectType = await getProjectType(capRoot ?? basePath);
|
|
99
|
+
if (projectType === 'CAPJava') {
|
|
100
|
+
throw new Error('The cards-editor command is not supported for CAP Java projects.');
|
|
101
|
+
}
|
|
102
|
+
if (projectType === 'CAPNodejs' && !capRoot) {
|
|
103
|
+
throw new Error(`Could not find CAP project root for path '${basePath}'.`);
|
|
104
|
+
}
|
|
96
105
|
await updateMiddlewaresForPreview(fs, basePath, yamlPath, logger);
|
|
97
106
|
await updateMiddlewareConfigWithGeneratorPath(fs, basePath, yamlPath, logger);
|
|
98
107
|
if (updatePackage) {
|
|
99
|
-
|
|
108
|
+
if (projectType === 'CAPNodejs') {
|
|
109
|
+
const { manifest } = await readManifest(basePath, fs);
|
|
110
|
+
const appId = manifest['sap.app']?.id;
|
|
111
|
+
if (!appId) {
|
|
112
|
+
throw new Error(`The 'sap.app.id' property is missing in the manifest.json file.`);
|
|
113
|
+
}
|
|
114
|
+
// capRoot is non-null here: the early guard above throws.
|
|
115
|
+
// TypeScript cannot narrow across the intervening `if (updatePackage)` boundary, so the cast is required.
|
|
116
|
+
await updateCapRootPackageJsonForCards(capRoot, appId, basename(basePath), basePath, fs, yamlPath, logger);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
await updatePackageJson(basePath, fs, yamlPath, logger);
|
|
120
|
+
}
|
|
100
121
|
}
|
|
101
122
|
return fs;
|
|
102
123
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
/**
|
|
4
|
+
* Writes a `cds watch` script to the CAP root `package.json`.
|
|
5
|
+
*
|
|
6
|
+
* @param capRoot - path to the CAP project root
|
|
7
|
+
* @param scriptKey - key of the script to write (e.g. 'start-cards-generator-my_app')
|
|
8
|
+
* @param openPath - the path to open, relative to the CDS server root (e.g. 'ns.myapp/test/...')
|
|
9
|
+
* @param fs - mem-fs-editor instance
|
|
10
|
+
* @param logger - optional logger
|
|
11
|
+
*/
|
|
12
|
+
export declare function writeCdsWatchScript(capRoot: string, scriptKey: string, openPath: string, fs: Editor, logger?: ToolsLogger): void;
|
|
13
|
+
//# sourceMappingURL=cap-utils.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { FileName } from '@sap-ux/project-access';
|
|
3
|
+
/**
|
|
4
|
+
* Writes a `cds watch` script to the CAP root `package.json`.
|
|
5
|
+
*
|
|
6
|
+
* @param capRoot - path to the CAP project root
|
|
7
|
+
* @param scriptKey - key of the script to write (e.g. 'start-cards-generator-my_app')
|
|
8
|
+
* @param openPath - the path to open, relative to the CDS server root (e.g. 'ns.myapp/test/...')
|
|
9
|
+
* @param fs - mem-fs-editor instance
|
|
10
|
+
* @param logger - optional logger
|
|
11
|
+
*/
|
|
12
|
+
export function writeCdsWatchScript(capRoot, scriptKey, openPath, fs, logger) {
|
|
13
|
+
const packageJsonPath = join(capRoot, FileName.Package);
|
|
14
|
+
if (!fs.exists(packageJsonPath)) {
|
|
15
|
+
throw new Error(`package.json not found at CAP root: ${capRoot}`);
|
|
16
|
+
}
|
|
17
|
+
const packageJson = (fs.readJSON(packageJsonPath) ?? {});
|
|
18
|
+
packageJson.scripts ??= {};
|
|
19
|
+
packageJson.scripts[scriptKey] = `cds watch --open "${openPath}"`;
|
|
20
|
+
fs.writeJSON(packageJsonPath, packageJson);
|
|
21
|
+
logger?.debug(`Script '${scriptKey}' written to CAP root package.json.`);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=cap-utils.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Editor } from 'mem-fs-editor';
|
|
2
|
+
import type { ToolsLogger } from '@sap-ux/logger';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the `start-variants-management-<appFolderName>` script to the CAP root `package.json`.
|
|
5
|
+
* Uses `cds watch --open "<appId><rtaPath>"` so the app is opened via the CDS development
|
|
6
|
+
* server rather than a standalone UI5 tooling server.
|
|
7
|
+
*
|
|
8
|
+
* @param capRoot - path to the CAP project root
|
|
9
|
+
* @param appId - sap.app.id from the app's manifest.json (used as the URL prefix)
|
|
10
|
+
* @param appFolderName - basename of the app folder (used as the script name suffix)
|
|
11
|
+
* @param basePath - path to the UI5 app root (where ui5.yaml and the app package.json live)
|
|
12
|
+
* @param fs - mem-fs-editor instance
|
|
13
|
+
* @param yamlPath - optional path to the ui5*.yaml file
|
|
14
|
+
* @param logger - optional logger
|
|
15
|
+
*/
|
|
16
|
+
export declare function updateCapRootPackageJsonForVariants(capRoot: string, appId: string, appFolderName: string, basePath: string, fs: Editor, yamlPath?: string, logger?: ToolsLogger): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=cap.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { basename, join } from 'node:path';
|
|
2
|
+
import { FileName } from '@sap-ux/project-access';
|
|
3
|
+
import { getRTAUrl, getRTAUrlParameters } from './utils.js';
|
|
4
|
+
import { writeCdsWatchScript } from '../common/cap-utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Writes the `start-variants-management-<appFolderName>` script to the CAP root `package.json`.
|
|
7
|
+
* Uses `cds watch --open "<appId><rtaPath>"` so the app is opened via the CDS development
|
|
8
|
+
* server rather than a standalone UI5 tooling server.
|
|
9
|
+
*
|
|
10
|
+
* @param capRoot - path to the CAP project root
|
|
11
|
+
* @param appId - sap.app.id from the app's manifest.json (used as the URL prefix)
|
|
12
|
+
* @param appFolderName - basename of the app folder (used as the script name suffix)
|
|
13
|
+
* @param basePath - path to the UI5 app root (where ui5.yaml and the app package.json live)
|
|
14
|
+
* @param fs - mem-fs-editor instance
|
|
15
|
+
* @param yamlPath - optional path to the ui5*.yaml file
|
|
16
|
+
* @param logger - optional logger
|
|
17
|
+
*/
|
|
18
|
+
export async function updateCapRootPackageJsonForVariants(capRoot, appId, appFolderName, basePath, fs, yamlPath, logger) {
|
|
19
|
+
const capRootPackageJsonPath = join(capRoot, FileName.Package);
|
|
20
|
+
if (!fs.exists(capRootPackageJsonPath)) {
|
|
21
|
+
throw new Error(`package.json not found at CAP root: ${capRoot}`);
|
|
22
|
+
}
|
|
23
|
+
const appPackageJson = (fs.readJSON(join(basePath, 'package.json')) ?? {});
|
|
24
|
+
const ui5YamlFileName = yamlPath ? basename(yamlPath) : FileName.Ui5Yaml;
|
|
25
|
+
const rtaUrl = await getRTAUrl(basePath, getRTAUrlParameters(appPackageJson), ui5YamlFileName, fs);
|
|
26
|
+
if (!rtaUrl) {
|
|
27
|
+
throw new Error(`Script 'start-variants-management-${appFolderName}' cannot be written to package.json. No RTA editor specified in ui5.yaml.`);
|
|
28
|
+
}
|
|
29
|
+
writeCdsWatchScript(capRoot, `start-variants-management-${appFolderName}`, `${appId}${rtaUrl}`, fs, logger);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=cap.js.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
1
2
|
import { create } from 'mem-fs-editor';
|
|
2
3
|
import { create as createStorage } from 'mem-fs';
|
|
3
4
|
import { updateMiddlewaresForPreview } from '../common/ui5-yaml.js';
|
|
4
5
|
import { addVariantsManagementScript } from './package-json.js';
|
|
6
|
+
import { getProjectType, findCapProjectRoot } from '@sap-ux/project-access';
|
|
7
|
+
import { readManifest } from '../common/utils.js';
|
|
8
|
+
import { updateCapRootPackageJsonForVariants } from './cap.js';
|
|
5
9
|
/**
|
|
6
10
|
* Add variants configuration to an app or project.
|
|
7
11
|
*
|
|
@@ -15,8 +19,28 @@ export async function generateVariantsConfig(basePath, yamlPath, logger, fs) {
|
|
|
15
19
|
if (!fs) {
|
|
16
20
|
fs = create(createStorage());
|
|
17
21
|
}
|
|
22
|
+
const capRoot = await findCapProjectRoot(basePath, false, fs);
|
|
23
|
+
const projectType = await getProjectType(capRoot ?? basePath);
|
|
24
|
+
if (projectType === 'CAPJava') {
|
|
25
|
+
throw new Error('The variants-config command is not supported for CAP Java projects.');
|
|
26
|
+
}
|
|
27
|
+
if (projectType === 'CAPNodejs' && !capRoot) {
|
|
28
|
+
throw new Error(`Could not find CAP project root for path '${basePath}'.`);
|
|
29
|
+
}
|
|
18
30
|
await updateMiddlewaresForPreview(fs, basePath, yamlPath, logger);
|
|
19
|
-
|
|
31
|
+
if (projectType === 'CAPNodejs') {
|
|
32
|
+
const { manifest } = await readManifest(basePath, fs);
|
|
33
|
+
const appId = manifest['sap.app']?.id;
|
|
34
|
+
if (!appId) {
|
|
35
|
+
throw new Error(`The 'sap.app.id' property is missing in the manifest.json file.`);
|
|
36
|
+
}
|
|
37
|
+
// capRoot is non-null here: the early guard above throws when projectType === 'CAPNodejs' && !capRoot.
|
|
38
|
+
// TypeScript cannot narrow across the intervening function call boundary, so the cast is required.
|
|
39
|
+
await updateCapRootPackageJsonForVariants(capRoot, appId, basename(basePath), basePath, fs, yamlPath, logger);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
await addVariantsManagementScript(fs, basePath, yamlPath, logger);
|
|
43
|
+
}
|
|
20
44
|
return fs;
|
|
21
45
|
}
|
|
22
46
|
//# sourceMappingURL=generateVariantsConfig.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/app-config-writer",
|
|
3
3
|
"description": "Add or update configuration for SAP Fiori tools application",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"prompts": "2.4.2",
|
|
40
40
|
"semver": "7.7.4",
|
|
41
41
|
"cross-spawn": "7.0.6",
|
|
42
|
-
"@sap-ux/ui5-application-writer": "2.0.4",
|
|
43
42
|
"@sap-ux/axios-extension": "2.0.3",
|
|
43
|
+
"@sap-ux/ui5-application-writer": "2.0.5",
|
|
44
44
|
"@sap-ux/btp-utils": "2.0.2",
|
|
45
45
|
"@sap-ux/logger": "1.0.1",
|
|
46
|
-
"@sap-ux/project-access": "2.1.
|
|
46
|
+
"@sap-ux/project-access": "2.1.3",
|
|
47
47
|
"@sap-ux/store": "2.0.1",
|
|
48
48
|
"@sap-ux/ui5-config": "1.0.3"
|
|
49
49
|
},
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@types/cross-spawn": "6.0.6",
|
|
58
58
|
"axios": "1.16.0",
|
|
59
59
|
"nock": "14.0.11",
|
|
60
|
-
"@sap-ux/preview-middleware": "1.0.
|
|
60
|
+
"@sap-ux/preview-middleware": "1.0.29"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=22.x"
|