@sap-ux/cap-config-writer 0.10.26 → 0.11.0
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/cap-config/index.d.ts +1 -0
- package/dist/cap-config/index.js +1 -0
- package/dist/cap-config/types.d.ts +9 -0
- package/dist/cap-writer/package-json.d.ts +3 -5
- package/dist/cap-writer/package-json.js +56 -20
- package/dist/cap-writer/updates.d.ts +2 -3
- package/dist/cap-writer/updates.js +6 -7
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
2
|
/**
|
|
3
3
|
* Enable workspace and cds-plugin-ui5 for given CAP project.
|
|
4
|
+
* If the minimum required version for @sap/cds is not met, it will update to the minimum required for cds-plugin-ui5.
|
|
4
5
|
*
|
|
5
6
|
* @param basePath - root path of the CAP project, where package.json is located
|
|
6
7
|
* @param [fs] - optional: the memfs editor instance
|
package/dist/cap-config/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const mem_fs_editor_1 = require("mem-fs-editor");
|
|
|
7
7
|
const package_json_1 = require("./package-json");
|
|
8
8
|
/**
|
|
9
9
|
* Enable workspace and cds-plugin-ui5 for given CAP project.
|
|
10
|
+
* If the minimum required version for @sap/cds is not met, it will update to the minimum required for cds-plugin-ui5.
|
|
10
11
|
*
|
|
11
12
|
* @param basePath - root path of the CAP project, where package.json is located
|
|
12
13
|
* @param [fs] - optional: the memfs editor instance
|
|
@@ -39,7 +39,16 @@ export interface CapProjectSettings {
|
|
|
39
39
|
packageName: string;
|
|
40
40
|
appId: string;
|
|
41
41
|
sapux?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated
|
|
44
|
+
* Indicates if NPM workspaces will be enabled.
|
|
45
|
+
* If cds-ui5-plugin is added or `enableCdsUi5Plugin` is true then npm workspaces is enabled.
|
|
46
|
+
*/
|
|
42
47
|
enableNPMWorkspaces?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Indicates if the CDS UI5 plugin will be added.
|
|
50
|
+
* If true, npm workspaces will also be automatically enabled.
|
|
51
|
+
*/
|
|
43
52
|
enableCdsUi5Plugin?: boolean;
|
|
44
53
|
enableTypescript?: boolean;
|
|
45
54
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Editor } from 'mem-fs-editor';
|
|
2
1
|
import type { CapServiceCdsInfo } from '../cap-config/types';
|
|
3
|
-
import type {
|
|
2
|
+
import type { Editor } from 'mem-fs-editor';
|
|
4
3
|
/**
|
|
5
4
|
* Retrieves the CDS watch script for the CAP app.
|
|
6
5
|
*
|
|
@@ -22,11 +21,10 @@ export declare function getCDSWatchScript(projectName: string, appId?: string):
|
|
|
22
21
|
* @param {boolean} sapux - Whether to add the app name to the sapux array.
|
|
23
22
|
* @param {CapServiceCdsInfo} capService - The CAP service instance.
|
|
24
23
|
* @param {string} appId - The application's ID, including its namespace and the module name.
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {boolean} [enableNPMWorkspaces] - Whether to enable npm workspaces.
|
|
24
|
+
* @param {boolean} addCdsUi5Plugin - whether to add the cds ui5 plugin.
|
|
27
25
|
* @returns {Promise<void>} A Promise that resolves once the root package.json is updated.
|
|
28
26
|
*/
|
|
29
|
-
export declare function updateRootPackageJson(fs: Editor, projectName: string, sapux: boolean, capService: CapServiceCdsInfo, appId: string,
|
|
27
|
+
export declare function updateRootPackageJson(fs: Editor, projectName: string, sapux: boolean, capService: CapServiceCdsInfo, appId: string, addCdsUi5Plugin?: boolean): Promise<void>;
|
|
30
28
|
/**
|
|
31
29
|
* Updates the package.json file of a CAP project app by removing the sapux property
|
|
32
30
|
* and start scripts, as well as the 'int-test' script.
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getCDSWatchScript = getCDSWatchScript;
|
|
4
4
|
exports.updateRootPackageJson = updateRootPackageJson;
|
|
5
5
|
exports.updateAppPackageJson = updateAppPackageJson;
|
|
6
|
+
const fs_1 = require("fs");
|
|
6
7
|
const project_access_1 = require("@sap-ux/project-access");
|
|
7
8
|
const path_1 = require("path");
|
|
8
9
|
const cap_config_1 = require("../cap-config");
|
|
@@ -34,28 +35,63 @@ function getCDSWatchScript(projectName, appId) {
|
|
|
34
35
|
function updatePackageJsonWithScripts(fs, packageJsonPath, scripts) {
|
|
35
36
|
fs.extendJSON(packageJsonPath, { scripts });
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns updated watch scripts for the package.json.
|
|
40
|
+
*
|
|
41
|
+
* @param fs - the file system editor
|
|
42
|
+
* @param projectPath - the path to the cap project
|
|
43
|
+
* @param appsPath - the path to the apps directory
|
|
44
|
+
* @param packageJson - the package.json object
|
|
45
|
+
* @returns - the watch scripts for existing applications
|
|
46
|
+
*/
|
|
47
|
+
async function updateExistingWatchScripts(fs, projectPath, appsPath, packageJson) {
|
|
48
|
+
const cdsScripts = {};
|
|
49
|
+
if (!packageJson?.scripts) {
|
|
50
|
+
return cdsScripts;
|
|
51
|
+
}
|
|
52
|
+
for (const script in packageJson.scripts) {
|
|
53
|
+
if (script.startsWith('watch-') && packageJson?.scripts?.[script]?.includes('/webapp/')) {
|
|
54
|
+
const appName = script.split('-')[1];
|
|
55
|
+
const appPath = (0, path_1.join)(projectPath, appsPath, appName);
|
|
56
|
+
if ((0, fs_1.existsSync)(appPath)) {
|
|
57
|
+
const manifestPath = (0, path_1.join)(await (0, project_access_1.getWebappPath)(appPath), project_access_1.FileName.Manifest);
|
|
58
|
+
const manifest = fs.readJSON(manifestPath);
|
|
59
|
+
const appId = manifest['sap.app']?.id;
|
|
60
|
+
if (appId) {
|
|
61
|
+
Object.assign(cdsScripts, getCDSWatchScript(appName, appId));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return cdsScripts;
|
|
67
|
+
}
|
|
37
68
|
/**
|
|
38
69
|
* Updates the scripts in the package json file for a CAP project.
|
|
39
70
|
*
|
|
40
71
|
* @param {Editor} fs - The file system editor.
|
|
41
|
-
* @param {
|
|
42
|
-
* @param
|
|
43
|
-
* @param {string}
|
|
44
|
-
* @param {
|
|
72
|
+
* @param {Package} packageJson - The package.json object to be updated.
|
|
73
|
+
* @param project - project details.
|
|
74
|
+
* @param {string} project.projectPath - the path to the CAP project.
|
|
75
|
+
* @param {string} project.projectName - the project name.
|
|
76
|
+
* @param {string} project.appsPath - the path to the apps directory in the cap project
|
|
77
|
+
* @param {string} project.appId - The application's ID, including its namespace and the module name.
|
|
78
|
+
* @param {boolean} addCdsUi5Plugin - whether to add cds ui5 plugin.
|
|
45
79
|
* @returns {Promise<void>} A Promise that resolves once the scripts are updated.
|
|
46
80
|
*/
|
|
47
|
-
async function updateScripts(fs,
|
|
48
|
-
|
|
49
|
-
let cdsScript;
|
|
81
|
+
async function updateScripts(fs, packageJson, { projectPath, projectName, appsPath, appId }, addCdsUi5Plugin) {
|
|
82
|
+
let cdsScripts = {};
|
|
50
83
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
51
|
-
if (
|
|
52
|
-
// If the project
|
|
53
|
-
|
|
84
|
+
if (addCdsUi5Plugin) {
|
|
85
|
+
// If the project has the cds-plugin-ui5 then the project is served using the appId
|
|
86
|
+
// Update existing watch scripts if they exist
|
|
87
|
+
Object.assign(cdsScripts, await updateExistingWatchScripts(fs, projectPath, appsPath, packageJson));
|
|
88
|
+
// Add the watch script for the new app
|
|
89
|
+
Object.assign(cdsScripts, getCDSWatchScript(projectName, appId));
|
|
54
90
|
}
|
|
55
91
|
else {
|
|
56
|
-
|
|
92
|
+
cdsScripts = getCDSWatchScript(projectName);
|
|
57
93
|
}
|
|
58
|
-
updatePackageJsonWithScripts(fs,
|
|
94
|
+
updatePackageJsonWithScripts(fs, (0, path_1.join)(projectPath, 'package.json'), cdsScripts);
|
|
59
95
|
}
|
|
60
96
|
/**
|
|
61
97
|
* Updates the root package.json file of CAP projects with the following changes:
|
|
@@ -67,22 +103,22 @@ async function updateScripts(fs, packageJsonPath, projectName, appId, enableNPMW
|
|
|
67
103
|
* @param {boolean} sapux - Whether to add the app name to the sapux array.
|
|
68
104
|
* @param {CapServiceCdsInfo} capService - The CAP service instance.
|
|
69
105
|
* @param {string} appId - The application's ID, including its namespace and the module name.
|
|
70
|
-
* @param {
|
|
71
|
-
* @param {boolean} [enableNPMWorkspaces] - Whether to enable npm workspaces.
|
|
106
|
+
* @param {boolean} addCdsUi5Plugin - whether to add the cds ui5 plugin.
|
|
72
107
|
* @returns {Promise<void>} A Promise that resolves once the root package.json is updated.
|
|
73
108
|
*/
|
|
74
|
-
async function updateRootPackageJson(fs, projectName, sapux, capService, appId,
|
|
109
|
+
async function updateRootPackageJson(fs, projectName, sapux, capService, appId, addCdsUi5Plugin) {
|
|
75
110
|
const packageJsonPath = (0, path_1.join)(capService.projectPath, 'package.json');
|
|
76
111
|
const packageJson = (fs.readJSON(packageJsonPath) ?? {});
|
|
77
112
|
const capNodeType = 'Node.js';
|
|
78
|
-
|
|
79
|
-
await (0, cap_config_1.enableCdsUi5Plugin)(capService.projectPath, fs);
|
|
80
|
-
}
|
|
113
|
+
const appsPath = (await (0, project_access_1.getCapCustomPaths)(capService.projectPath)).app;
|
|
81
114
|
if (capService?.capType === capNodeType) {
|
|
82
|
-
|
|
115
|
+
if (addCdsUi5Plugin) {
|
|
116
|
+
await (0, cap_config_1.enableCdsUi5Plugin)(capService.projectPath, fs);
|
|
117
|
+
}
|
|
118
|
+
await updateScripts(fs, packageJson, { projectPath: capService.projectPath, projectName, appsPath, appId }, addCdsUi5Plugin);
|
|
83
119
|
}
|
|
84
120
|
if (sapux) {
|
|
85
|
-
const dirPath = (0, path_1.join)(capService.appPath ??
|
|
121
|
+
const dirPath = (0, path_1.join)(capService.appPath ?? appsPath, projectName);
|
|
86
122
|
// Converts a directory path to a POSIX-style path.
|
|
87
123
|
const capProjectPath = (0, path_1.normalize)(dirPath).split(/[\\/]/g).join(path_1.posix.sep);
|
|
88
124
|
const sapuxExt = Array.isArray(packageJson?.sapux) ? [...packageJson.sapux, capProjectPath] : [capProjectPath];
|
|
@@ -12,9 +12,8 @@ import type { Logger } from '@sap-ux/logger';
|
|
|
12
12
|
* @param {string} capProjectSettings.packageName - The name of the package.
|
|
13
13
|
* @param {string} capProjectSettings.appId - The application's ID, including its namespace and the module name.
|
|
14
14
|
* @param {boolean} capProjectSettings.sapux - Indicates if SAP UX is enabled.
|
|
15
|
-
* @param {boolean} capProjectSettings.
|
|
16
|
-
* @param {boolean} capProjectSettings.
|
|
17
|
-
* @param {boolean} [capProjectSettings.enableTypescript] - Indicates if TypeScript is enabled.
|
|
15
|
+
* @param {boolean} capProjectSettings.enableCdsUi5Plugin - Indicates if cds ui5 plugin should be added (default is true). The cds ui5 plugin will only be added if the minimum cds version that supports it is present.
|
|
16
|
+
* @param {boolean} capProjectSettings.enableTypescript - Indicates if TypeScript is enabled.
|
|
18
17
|
* @param {Logger} [log] - logger for logging information.
|
|
19
18
|
* @returns {Promise<void>} A promise that resolves when the updates are applied.
|
|
20
19
|
*/
|
|
@@ -17,16 +17,15 @@ const path_1 = require("path");
|
|
|
17
17
|
* @param {string} capProjectSettings.packageName - The name of the package.
|
|
18
18
|
* @param {string} capProjectSettings.appId - The application's ID, including its namespace and the module name.
|
|
19
19
|
* @param {boolean} capProjectSettings.sapux - Indicates if SAP UX is enabled.
|
|
20
|
-
* @param {boolean} capProjectSettings.
|
|
21
|
-
* @param {boolean} capProjectSettings.
|
|
22
|
-
* @param {boolean} [capProjectSettings.enableTypescript] - Indicates if TypeScript is enabled.
|
|
20
|
+
* @param {boolean} capProjectSettings.enableCdsUi5Plugin - Indicates if cds ui5 plugin should be added (default is true). The cds ui5 plugin will only be added if the minimum cds version that supports it is present.
|
|
21
|
+
* @param {boolean} capProjectSettings.enableTypescript - Indicates if TypeScript is enabled.
|
|
23
22
|
* @param {Logger} [log] - logger for logging information.
|
|
24
23
|
* @returns {Promise<void>} A promise that resolves when the updates are applied.
|
|
25
24
|
*/
|
|
26
25
|
async function applyCAPUpdates(fs, capService, capProjectSettings, log) {
|
|
27
|
-
const { appRoot, packageName, appId, sapux = false,
|
|
26
|
+
const { appRoot, packageName, appId, sapux = false, enableCdsUi5Plugin = true, enableTypescript = false } = capProjectSettings;
|
|
28
27
|
// update root package.json
|
|
29
|
-
await (0, package_json_1.updateRootPackageJson)(fs, packageName, sapux, capService, appId,
|
|
28
|
+
await (0, package_json_1.updateRootPackageJson)(fs, packageName, sapux, capService, appId, enableCdsUi5Plugin);
|
|
30
29
|
if (capService.capType === 'Java') {
|
|
31
30
|
const capProjectPath = capService.projectPath;
|
|
32
31
|
const capCustomPaths = (0, fiori_generator_shared_1.getCapFolderPathsSync)(capProjectPath);
|
|
@@ -45,8 +44,8 @@ async function applyCAPUpdates(fs, capService, capProjectSettings, log) {
|
|
|
45
44
|
// update tsconfig.json if TypeScript is enabled
|
|
46
45
|
(0, tsconfig_and_yaml_1.updateTsConfig)(fs, appRoot);
|
|
47
46
|
}
|
|
48
|
-
if (
|
|
49
|
-
// update app package.json if CDS UI5 plugin is enabled
|
|
47
|
+
if (capService.capType === 'Node.js' && enableCdsUi5Plugin) {
|
|
48
|
+
// update app package.json if CDS UI5 plugin is enabled
|
|
50
49
|
(0, package_json_1.updateAppPackageJson)(fs, appRoot);
|
|
51
50
|
}
|
|
52
51
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/cap-config-writer",
|
|
3
3
|
"description": "Add or update configuration for SAP CAP projects",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"semver": "7.5.4",
|
|
26
26
|
"xml-js": "1.6.11",
|
|
27
27
|
"@sap-ux/logger": "0.7.0",
|
|
28
|
-
"@sap-ux/project-access": "1.30.
|
|
28
|
+
"@sap-ux/project-access": "1.30.12",
|
|
29
29
|
"@sap-ux/yaml": "0.17.0",
|
|
30
|
-
"@sap-ux/fiori-generator-shared": "0.13.
|
|
30
|
+
"@sap-ux/fiori-generator-shared": "0.13.9"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/mem-fs": "1.1.2",
|