@sap-ux/cap-config-writer 0.5.7 → 0.6.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/cap-config/index.js +34 -46
- package/dist/cap-config/package-json.js +28 -49
- package/dist/cap-writer/package-json.js +41 -54
- package/dist/cap-writer/pom-xml.js +11 -13
- package/dist/cap-writer/tsconfig-and-yaml.js +15 -26
- package/dist/cap-writer/utils.js +1 -1
- package/dist/i18n.js +11 -22
- package/package.json +5 -5
package/dist/cap-config/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.minCdsVersion = exports.checkCdsUi5PluginEnabled = exports.enableCdsUi5Plugin = exports.satisfiesMinCdsVersion = void 0;
|
|
13
4
|
const path_1 = require("path");
|
|
@@ -25,20 +16,17 @@ const semver_1 = require("semver");
|
|
|
25
16
|
* @param [fs] - optional: the memfs editor instance
|
|
26
17
|
* @returns Promise<Editor> - memfs editor instance with updated files
|
|
27
18
|
*/
|
|
28
|
-
function enableCdsUi5Plugin(basePath, fs) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
fs.writeJSON(packageJsonPath, packageJson);
|
|
40
|
-
return fs;
|
|
41
|
-
});
|
|
19
|
+
async function enableCdsUi5Plugin(basePath, fs) {
|
|
20
|
+
if (!fs) {
|
|
21
|
+
fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
|
|
22
|
+
}
|
|
23
|
+
const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
|
|
24
|
+
const packageJson = (fs.readJSON(packageJsonPath) ?? {});
|
|
25
|
+
(0, package_json_1.ensureMinCdsVersion)(packageJson);
|
|
26
|
+
await (0, package_json_1.enableWorkspaces)(basePath, packageJson);
|
|
27
|
+
(0, package_json_1.addCdsPluginUi5)(packageJson);
|
|
28
|
+
fs.writeJSON(packageJsonPath, packageJson);
|
|
29
|
+
return fs;
|
|
42
30
|
}
|
|
43
31
|
exports.enableCdsUi5Plugin = enableCdsUi5Plugin;
|
|
44
32
|
/**
|
|
@@ -52,29 +40,29 @@ exports.enableCdsUi5Plugin = enableCdsUi5Plugin;
|
|
|
52
40
|
* @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info or true if
|
|
53
41
|
* cds-plugin-ui5 and all prerequisites are fulfilled
|
|
54
42
|
*/
|
|
55
|
-
function checkCdsUi5PluginEnabled(basePath, fs, moreInfo, cdsVersionInfo) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
async function checkCdsUi5PluginEnabled(basePath, fs, moreInfo, cdsVersionInfo) {
|
|
44
|
+
if (!fs) {
|
|
45
|
+
fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
|
|
46
|
+
}
|
|
47
|
+
const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
|
|
48
|
+
if (!fs.exists(packageJsonPath)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const packageJson = fs.readJSON(packageJsonPath);
|
|
52
|
+
const { workspaceEnabled } = await (0, package_json_1.getWorkspaceInfo)(basePath, packageJson);
|
|
53
|
+
const cdsInfo = {
|
|
54
|
+
// Below line checks if 'cdsVersionInfo' is available and contains version information.
|
|
55
|
+
// If it does, it uses that version information to determine if it satisfies the minimum CDS version required.
|
|
56
|
+
// If 'cdsVersionInfo' is not available or does not contain version information,it falls back to check the version specified in the package.json file.
|
|
57
|
+
hasMinCdsVersion: cdsVersionInfo?.version
|
|
58
|
+
? (0, semver_1.satisfies)(cdsVersionInfo?.version, `>=${package_json_1.minCdsVersion}`)
|
|
59
|
+
: (0, package_json_1.satisfiesMinCdsVersion)(packageJson),
|
|
60
|
+
isWorkspaceEnabled: workspaceEnabled,
|
|
61
|
+
hasCdsUi5Plugin: (0, package_json_1.hasCdsPluginUi5)(packageJson),
|
|
62
|
+
isCdsUi5PluginEnabled: false
|
|
63
|
+
};
|
|
64
|
+
cdsInfo.isCdsUi5PluginEnabled = cdsInfo.hasMinCdsVersion && cdsInfo.isWorkspaceEnabled && cdsInfo.hasCdsUi5Plugin;
|
|
65
|
+
return moreInfo ? cdsInfo : cdsInfo.isCdsUi5PluginEnabled;
|
|
78
66
|
}
|
|
79
67
|
exports.checkCdsUi5PluginEnabled = checkCdsUi5PluginEnabled;
|
|
80
68
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.hasCdsPluginUi5 = exports.getWorkspaceInfo = exports.satisfiesMinCdsVersion = exports.hasMinCdsVersion = exports.addCdsPluginUi5 = exports.enableWorkspaces = exports.ensureMinCdsVersion = exports.minCdsVersion = void 0;
|
|
13
4
|
const semver_1 = require("semver");
|
|
@@ -20,9 +11,8 @@ const minCdsPluginUi5Version = '0.9.3';
|
|
|
20
11
|
* @param packageJson - the parsed package.json
|
|
21
12
|
*/
|
|
22
13
|
function ensureMinCdsVersion(packageJson) {
|
|
23
|
-
var _a;
|
|
24
14
|
if (!hasMinCdsVersion(packageJson)) {
|
|
25
|
-
|
|
15
|
+
packageJson.dependencies ??= {};
|
|
26
16
|
packageJson.dependencies['@sap/cds'] = `^${exports.minCdsVersion}`;
|
|
27
17
|
}
|
|
28
18
|
}
|
|
@@ -33,26 +23,23 @@ exports.ensureMinCdsVersion = ensureMinCdsVersion;
|
|
|
33
23
|
* @param basePath - root path of the CAP project, where package.json is located
|
|
34
24
|
* @param packageJson - the parsed package.json
|
|
35
25
|
*/
|
|
36
|
-
function enableWorkspaces(basePath, packageJson) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
async function enableWorkspaces(basePath, packageJson) {
|
|
27
|
+
const { appWorkspace, workspaceEnabled } = await getWorkspaceInfo(basePath, packageJson);
|
|
28
|
+
if (workspaceEnabled) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let workspacePackages = getWorkspacePackages(packageJson);
|
|
32
|
+
if (!workspacePackages) {
|
|
33
|
+
packageJson.workspaces ??= [];
|
|
34
|
+
if (Array.isArray(packageJson.workspaces)) {
|
|
35
|
+
workspacePackages = packageJson.workspaces;
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (Array.isArray(packageJson.workspaces)) {
|
|
47
|
-
workspacePackages = packageJson.workspaces;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
packageJson.workspaces.packages = [];
|
|
51
|
-
workspacePackages = packageJson.workspaces.packages;
|
|
52
|
-
}
|
|
37
|
+
else {
|
|
38
|
+
packageJson.workspaces.packages = [];
|
|
39
|
+
workspacePackages = packageJson.workspaces.packages;
|
|
53
40
|
}
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
}
|
|
42
|
+
workspacePackages.push(appWorkspace);
|
|
56
43
|
}
|
|
57
44
|
exports.enableWorkspaces = enableWorkspaces;
|
|
58
45
|
/**
|
|
@@ -61,9 +48,8 @@ exports.enableWorkspaces = enableWorkspaces;
|
|
|
61
48
|
* @param packageJson - the parsed package.json
|
|
62
49
|
*/
|
|
63
50
|
function addCdsPluginUi5(packageJson) {
|
|
64
|
-
var _a;
|
|
65
51
|
if (!hasCdsPluginUi5(packageJson)) {
|
|
66
|
-
|
|
52
|
+
packageJson.devDependencies ??= {};
|
|
67
53
|
packageJson.devDependencies['cds-plugin-ui5'] = `^${minCdsPluginUi5Version}`;
|
|
68
54
|
}
|
|
69
55
|
}
|
|
@@ -76,8 +62,7 @@ exports.addCdsPluginUi5 = addCdsPluginUi5;
|
|
|
76
62
|
* @returns - true: min cds version is present; false: cds version needs update
|
|
77
63
|
*/
|
|
78
64
|
function hasMinCdsVersion(packageJson) {
|
|
79
|
-
|
|
80
|
-
return (0, semver_1.gte)((_b = (0, semver_1.coerce)((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['@sap/cds'])) !== null && _b !== void 0 ? _b : '0.0.0', exports.minCdsVersion);
|
|
65
|
+
return (0, semver_1.gte)((0, semver_1.coerce)(packageJson.dependencies?.['@sap/cds']) ?? '0.0.0', exports.minCdsVersion);
|
|
81
66
|
}
|
|
82
67
|
exports.hasMinCdsVersion = hasMinCdsVersion;
|
|
83
68
|
/**
|
|
@@ -87,8 +72,7 @@ exports.hasMinCdsVersion = hasMinCdsVersion;
|
|
|
87
72
|
* @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version
|
|
88
73
|
*/
|
|
89
74
|
function satisfiesMinCdsVersion(packageJson) {
|
|
90
|
-
|
|
91
|
-
return hasMinCdsVersion(packageJson) || (0, semver_1.satisfies)(exports.minCdsVersion, (_b = (_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['@sap/cds']) !== null && _b !== void 0 ? _b : '0.0.0');
|
|
75
|
+
return hasMinCdsVersion(packageJson) || (0, semver_1.satisfies)(exports.minCdsVersion, packageJson.dependencies?.['@sap/cds'] ?? '0.0.0');
|
|
92
76
|
}
|
|
93
77
|
exports.satisfiesMinCdsVersion = satisfiesMinCdsVersion;
|
|
94
78
|
/**
|
|
@@ -98,15 +82,12 @@ exports.satisfiesMinCdsVersion = satisfiesMinCdsVersion;
|
|
|
98
82
|
* @param packageJson - the parsed package.json
|
|
99
83
|
* @returns - appWorkspace containing the path to the appWorkspace including wildcard; workspaceEnabled: boolean that states whether workspace for apps are enabled
|
|
100
84
|
*/
|
|
101
|
-
function getWorkspaceInfo(basePath, packageJson) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const workspaceEnabled = workspacePackages.includes(appWorkspace);
|
|
108
|
-
return { appWorkspace, workspaceEnabled };
|
|
109
|
-
});
|
|
85
|
+
async function getWorkspaceInfo(basePath, packageJson) {
|
|
86
|
+
const capPaths = await (0, project_access_1.getCapCustomPaths)(basePath);
|
|
87
|
+
const appWorkspace = capPaths.app.endsWith('/') ? `${capPaths.app}*` : `${capPaths.app}/*`;
|
|
88
|
+
const workspacePackages = getWorkspacePackages(packageJson) ?? [];
|
|
89
|
+
const workspaceEnabled = workspacePackages.includes(appWorkspace);
|
|
90
|
+
return { appWorkspace, workspaceEnabled };
|
|
110
91
|
}
|
|
111
92
|
exports.getWorkspaceInfo = getWorkspaceInfo;
|
|
112
93
|
/**
|
|
@@ -118,13 +99,12 @@ exports.getWorkspaceInfo = getWorkspaceInfo;
|
|
|
118
99
|
* @returns ref to the packages in workspaces or undefined
|
|
119
100
|
*/
|
|
120
101
|
function getWorkspacePackages(packageJson) {
|
|
121
|
-
var _a, _b;
|
|
122
102
|
let workspacePackages;
|
|
123
103
|
if (Array.isArray(packageJson.workspaces)) {
|
|
124
104
|
workspacePackages = packageJson.workspaces;
|
|
125
105
|
}
|
|
126
|
-
else if (Array.isArray(
|
|
127
|
-
workspacePackages =
|
|
106
|
+
else if (Array.isArray(packageJson.workspaces?.packages)) {
|
|
107
|
+
workspacePackages = packageJson.workspaces?.packages;
|
|
128
108
|
}
|
|
129
109
|
return workspacePackages;
|
|
130
110
|
}
|
|
@@ -135,8 +115,7 @@ function getWorkspacePackages(packageJson) {
|
|
|
135
115
|
* @returns true: devDependency to cds-plugin-ui5 exists; false: devDependency to cds-plugin-ui5 does not exist
|
|
136
116
|
*/
|
|
137
117
|
function hasCdsPluginUi5(packageJson) {
|
|
138
|
-
|
|
139
|
-
return !!((_a = packageJson.devDependencies) === null || _a === void 0 ? void 0 : _a['cds-plugin-ui5']);
|
|
118
|
+
return !!packageJson.devDependencies?.['cds-plugin-ui5'];
|
|
140
119
|
}
|
|
141
120
|
exports.hasCdsPluginUi5 = hasCdsPluginUi5;
|
|
142
121
|
//# sourceMappingURL=package-json.js.map
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.updateAppPackageJson = exports.updateRootPackageJson = exports.getCDSWatchScript = void 0;
|
|
36
27
|
const project_access_1 = require("@sap-ux/project-access");
|
|
@@ -48,7 +39,7 @@ const i18n_1 = require("../i18n");
|
|
|
48
39
|
function getCDSWatchScript(projectName, appId) {
|
|
49
40
|
const DisableCacheParam = 'sap-ui-xx-viewCache=false';
|
|
50
41
|
// projects by default are served base on the folder name in the app/ folder
|
|
51
|
-
const project = appId
|
|
42
|
+
const project = appId ?? projectName + '/webapp';
|
|
52
43
|
const watchScript = {
|
|
53
44
|
[`watch-${projectName}`]: `cds watch --open ${project}/index.html?${DisableCacheParam}${appId ? ' --livereload false' : ''}`
|
|
54
45
|
};
|
|
@@ -78,30 +69,30 @@ function updatePackageJsonWithScripts(fs, packageJsonPath, scripts) {
|
|
|
78
69
|
* @param {Logger} [log] - The logger instance for logging warnings.
|
|
79
70
|
* @returns {Promise<void>} A Promise that resolves once the scripts are updated.
|
|
80
71
|
*/
|
|
81
|
-
function updateScripts(fs, packageJsonPath, projectName, appId, enableNPMWorkspaces, cdsUi5PluginInfo, log) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
else
|
|
98
|
-
cdsScript = getCDSWatchScript(projectName);
|
|
99
|
-
updatePackageJsonWithScripts(fs, packageJsonPath, cdsScript);
|
|
72
|
+
async function updateScripts(fs, packageJsonPath, projectName, appId, enableNPMWorkspaces, cdsUi5PluginInfo, log) {
|
|
73
|
+
const packageJson = (fs.readJSON(packageJsonPath) ?? {});
|
|
74
|
+
const hasNPMworkspaces = await (0, cap_config_1.checkCdsUi5PluginEnabled)(packageJsonPath, fs);
|
|
75
|
+
// Determine whether to add cds watch scripts for the app based on the availability of minimum CDS version information.
|
|
76
|
+
// If 'cdsUi5PluginInfo' contains version information and it satisfies the minimum required CDS version,
|
|
77
|
+
// or if 'cdsUi5PluginInfo' is not available and the version specified in 'package.json' satisfies the minimum required version,
|
|
78
|
+
// then set 'addScripts' to true. Otherwise, set it to false.
|
|
79
|
+
const addScripts = cdsUi5PluginInfo?.hasMinCdsVersion
|
|
80
|
+
? cdsUi5PluginInfo.hasMinCdsVersion
|
|
81
|
+
: (0, cap_config_1.satisfiesMinCdsVersion)(packageJson);
|
|
82
|
+
let cdsScript;
|
|
83
|
+
if (addScripts) {
|
|
84
|
+
if (enableNPMWorkspaces ?? hasNPMworkspaces) {
|
|
85
|
+
// If the project uses npm workspaces (and specifically cds-plugin-ui5 ) then the project is served using the appId
|
|
86
|
+
cdsScript = getCDSWatchScript(projectName, appId);
|
|
100
87
|
}
|
|
101
88
|
else {
|
|
102
|
-
|
|
89
|
+
cdsScript = getCDSWatchScript(projectName);
|
|
103
90
|
}
|
|
104
|
-
|
|
91
|
+
updatePackageJsonWithScripts(fs, packageJsonPath, cdsScript);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
log?.warn((0, i18n_1.t)('warn.cdsDKNotInstalled', { minCdsVersion: cap_config_1.minCdsVersion }));
|
|
95
|
+
}
|
|
105
96
|
}
|
|
106
97
|
/**
|
|
107
98
|
* Updates the root package.json file of CAP projects with the following changes:
|
|
@@ -117,26 +108,23 @@ function updateScripts(fs, packageJsonPath, projectName, appId, enableNPMWorkspa
|
|
|
117
108
|
* @param {boolean} [enableNPMWorkspaces] - Whether to enable npm workspaces.
|
|
118
109
|
* @returns {Promise<void>} A Promise that resolves once the root package.json is updated.
|
|
119
110
|
*/
|
|
120
|
-
function updateRootPackageJson(fs, projectName, sapux, capService, appId, log, enableNPMWorkspaces) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
fs.extendJSON(packageJsonPath, { sapux: sapuxExt });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
111
|
+
async function updateRootPackageJson(fs, projectName, sapux, capService, appId, log, enableNPMWorkspaces) {
|
|
112
|
+
const packageJsonPath = (0, path_1.join)(capService.projectPath, 'package.json');
|
|
113
|
+
const packageJson = (fs.readJSON(packageJsonPath) ?? {});
|
|
114
|
+
const capNodeType = 'Node.js';
|
|
115
|
+
if (enableNPMWorkspaces && packageJson) {
|
|
116
|
+
await (0, cap_config_1.enableCdsUi5Plugin)(capService.projectPath, fs);
|
|
117
|
+
}
|
|
118
|
+
if (capService?.capType === capNodeType) {
|
|
119
|
+
await updateScripts(fs, packageJsonPath, projectName, appId, enableNPMWorkspaces, capService.cdsUi5PluginInfo, log);
|
|
120
|
+
}
|
|
121
|
+
if (sapux) {
|
|
122
|
+
const dirPath = (0, path_1.join)(capService.appPath ?? (await (0, project_access_1.getCapCustomPaths)(capService.projectPath)).app, projectName);
|
|
123
|
+
// Converts a directory path to a POSIX-style path.
|
|
124
|
+
const capProjectPath = path_1.default.normalize(dirPath).split(/[\\/]/g).join(path_1.default.posix.sep);
|
|
125
|
+
const sapuxExt = Array.isArray(packageJson?.sapux) ? [...packageJson.sapux, capProjectPath] : [capProjectPath];
|
|
126
|
+
fs.extendJSON(packageJsonPath, { sapux: sapuxExt });
|
|
127
|
+
}
|
|
140
128
|
}
|
|
141
129
|
exports.updateRootPackageJson = updateRootPackageJson;
|
|
142
130
|
/**
|
|
@@ -147,11 +135,10 @@ exports.updateRootPackageJson = updateRootPackageJson;
|
|
|
147
135
|
* @param {string} appRoot The root directory of the application.
|
|
148
136
|
*/
|
|
149
137
|
function updateAppPackageJson(fs, appRoot) {
|
|
150
|
-
var _a;
|
|
151
138
|
const packageJsonPath = (0, path_1.join)(appRoot, 'package.json');
|
|
152
|
-
const packageJson = (
|
|
139
|
+
const packageJson = (fs.readJSON(packageJsonPath) ?? {});
|
|
153
140
|
delete packageJson.sapux;
|
|
154
|
-
if (packageJson
|
|
141
|
+
if (packageJson?.scripts) {
|
|
155
142
|
delete packageJson.scripts['int-test'];
|
|
156
143
|
}
|
|
157
144
|
for (const script in packageJson.scripts) {
|
|
@@ -10,7 +10,7 @@ const xml_js_1 = require("xml-js");
|
|
|
10
10
|
* @returns {boolean} Returns true if the name exists in the array, otherwise false.
|
|
11
11
|
*/
|
|
12
12
|
function checkIfNameExists(data, name) {
|
|
13
|
-
return data
|
|
13
|
+
return data?.some((obj) => obj.name === name);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Adds a workspace element to the provided data if it doesn't already exist.
|
|
@@ -19,7 +19,7 @@ function checkIfNameExists(data, name) {
|
|
|
19
19
|
* @returns {boolean} Returns true if the workspace element was successfully added, otherwise false.
|
|
20
20
|
*/
|
|
21
21
|
function addWorkspaceElement(data) {
|
|
22
|
-
if (!
|
|
22
|
+
if (!data?.elements || checkIfNameExists(data.elements, 'workingDirectory')) {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
data.elements.push({ type: 'element', name: 'workingDirectory', elements: [{ type: 'text', text: '..' }] });
|
|
@@ -57,7 +57,6 @@ function writePomXml(fs, pomPath, pomContentsJson) {
|
|
|
57
57
|
* @returns {void}
|
|
58
58
|
*/
|
|
59
59
|
function updatePomXml(fs, pomPath, logger) {
|
|
60
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
61
60
|
try {
|
|
62
61
|
const pomContents = readPomXml(fs, pomPath);
|
|
63
62
|
const pomContentsJson = (0, xml_js_1.xml2js)(pomContents, { compact: false, ignoreComment: false });
|
|
@@ -66,22 +65,21 @@ function updatePomXml(fs, pomPath, logger) {
|
|
|
66
65
|
return;
|
|
67
66
|
}
|
|
68
67
|
// find the spring-boot-maven-plugin in the pom.xml
|
|
69
|
-
const pomPlugin =
|
|
70
|
-
.filter((element) => element.name === 'project')
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})) === null || _e === void 0 ? void 0 : _e[0].elements) === null || _f === void 0 ? void 0 : _f.filter((element) => element.name === 'configuration')) === null || _g === void 0 ? void 0 : _g[0];
|
|
68
|
+
const pomPlugin = pomContentsJson.elements
|
|
69
|
+
.filter((element) => element.name === 'project')?.[0]
|
|
70
|
+
.elements.filter((element) => element.name === 'build')?.[0]
|
|
71
|
+
.elements.filter((element) => element.name === 'plugins')?.[0]
|
|
72
|
+
.elements.filter((element) => element.name === 'plugin')
|
|
73
|
+
?.filter((obj) => obj?.elements?.some((element) => element.name === 'artifactId' &&
|
|
74
|
+
(element.elements ?? []).some((element) => element.text === springBootMavenPlugin)))?.[0]
|
|
75
|
+
.elements?.filter((element) => element.name === 'configuration')?.[0];
|
|
78
76
|
if (pomPlugin) {
|
|
79
77
|
addWorkspaceElement(pomPlugin);
|
|
80
78
|
writePomXml(fs, pomPath, pomContentsJson);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
catch (error) {
|
|
84
|
-
logger
|
|
82
|
+
logger?.error(error);
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
exports.updatePomXml = updatePomXml;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.updateStaticLocationsInApplicationYaml = exports.updateTsConfig = void 0;
|
|
13
4
|
const project_access_1 = require("@sap-ux/project-access");
|
|
@@ -49,24 +40,22 @@ exports.updateTsConfig = updateTsConfig;
|
|
|
49
40
|
* @param {Logger} [logger] The logger instance for logging errors.
|
|
50
41
|
* @returns {void}
|
|
51
42
|
*/
|
|
52
|
-
function updateStaticLocationsInApplicationYaml(fs, applicationYamlPath, capCustomPathsApp, logger) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
fs.write(applicationYamlPath, (0, yaml_1.yamlDocumentToYamlString)(applicationYamlFirstDocument));
|
|
64
|
-
}
|
|
43
|
+
async function updateStaticLocationsInApplicationYaml(fs, applicationYamlPath, capCustomPathsApp, logger) {
|
|
44
|
+
try {
|
|
45
|
+
const applicationYamlDocuments = fs.read(applicationYamlPath).toString();
|
|
46
|
+
const yamlDoc = await yaml_1.YamlDocument.newInstance(applicationYamlDocuments);
|
|
47
|
+
const stringifiedYaml = JSON.stringify(yamlDoc);
|
|
48
|
+
const parsedApplicationYamlDocuments = JSON.parse(stringifiedYaml).documents;
|
|
49
|
+
if (parsedApplicationYamlDocuments.length === 1 &&
|
|
50
|
+
parsedApplicationYamlDocuments[0].spring['web.resources.static-locations'] === undefined) {
|
|
51
|
+
const applicationYamlFirstDocument = parsedApplicationYamlDocuments[0];
|
|
52
|
+
applicationYamlFirstDocument.spring['web.resources.static-locations'] = `file:./${capCustomPathsApp}`;
|
|
53
|
+
fs.write(applicationYamlPath, (0, yaml_1.yamlDocumentToYamlString)(applicationYamlFirstDocument));
|
|
65
54
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
logger?.error((0, i18n_1.t)('error.updateApplicationYaml', { error: error }));
|
|
58
|
+
}
|
|
70
59
|
}
|
|
71
60
|
exports.updateStaticLocationsInApplicationYaml = updateStaticLocationsInApplicationYaml;
|
|
72
61
|
//# sourceMappingURL=tsconfig-and-yaml.js.map
|
package/dist/cap-writer/utils.js
CHANGED
|
@@ -11,7 +11,7 @@ const i18n_1 = require("../i18n");
|
|
|
11
11
|
* @returns The URL for launching the project.
|
|
12
12
|
*/
|
|
13
13
|
function getCapUrl(capType, projectName, appId) {
|
|
14
|
-
const projectPath = appId
|
|
14
|
+
const projectPath = appId ?? projectName + '/webapp';
|
|
15
15
|
if (capType === 'Java') {
|
|
16
16
|
// For Java projects
|
|
17
17
|
return `http://localhost:8080/${projectName}/webapp/index.html`;
|
package/dist/i18n.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -19,19 +10,17 @@ const NS = 'cap-config-writer';
|
|
|
19
10
|
/**
|
|
20
11
|
* Initialize i18next with the translations for this module.
|
|
21
12
|
*/
|
|
22
|
-
function initI18n() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
ns: [NS]
|
|
34
|
-
});
|
|
13
|
+
async function initI18n() {
|
|
14
|
+
await i18next_1.default.init({
|
|
15
|
+
resources: {
|
|
16
|
+
en: {
|
|
17
|
+
[NS]: cap_config_writer_i18n_json_1.default
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
lng: 'en',
|
|
21
|
+
fallbackLng: 'en',
|
|
22
|
+
defaultNS: NS,
|
|
23
|
+
ns: [NS]
|
|
35
24
|
});
|
|
36
25
|
}
|
|
37
26
|
exports.initI18n = initI18n;
|
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.6.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"mem-fs-editor": "9.4.0",
|
|
25
25
|
"semver": "7.5.4",
|
|
26
26
|
"xml-js": "1.6.11",
|
|
27
|
-
"@sap-ux/logger": "0.
|
|
28
|
-
"@sap-ux/project-access": "1.
|
|
29
|
-
"@sap-ux/odata-service-inquirer": "0.
|
|
30
|
-
"@sap-ux/yaml": "0.
|
|
27
|
+
"@sap-ux/logger": "0.6.0",
|
|
28
|
+
"@sap-ux/project-access": "1.24.0",
|
|
29
|
+
"@sap-ux/odata-service-inquirer": "0.4.2",
|
|
30
|
+
"@sap-ux/yaml": "0.16.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/mem-fs": "1.1.2",
|