@sap-ux/project-access 1.24.0 → 1.25.1
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/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/project/index.d.ts +1 -1
- package/dist/project/index.js +2 -1
- package/dist/project/info.js +13 -10
- package/dist/project/module-loader.d.ts +8 -0
- package/dist/project/module-loader.js +16 -5
- package/dist/project/search.js +3 -0
- package/dist/project/specification.d.ts +12 -0
- package/dist/project/specification.js +90 -19
- package/dist/types/info/index.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { FileName, DirName, FioriToolsSettings } from './constants';
|
|
2
2
|
export { getFilePaths } from './file';
|
|
3
|
-
export { addPackageDevDependency, clearCdsModuleCache, createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, getSpecification, getI18nPropertiesPaths, getMinUI5VersionFromManifest, getMinUI5VersionAsArray, getMinimumUI5Version, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapProject, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml, refreshSpecificationDistTags, toReferenceUri, filterDataSourcesByType, updatePackageScript } from './project';
|
|
3
|
+
export { addPackageDevDependency, clearCdsModuleCache, createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, getSpecification, getSpecificationPath, getI18nPropertiesPaths, getMinUI5VersionFromManifest, getMinUI5VersionAsArray, getMinimumUI5Version, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapProject, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml, refreshSpecificationDistTags, toReferenceUri, filterDataSourcesByType, updatePackageScript } from './project';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export * from './library';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.updatePackageScript = exports.filterDataSourcesByType = exports.toReferenceUri = exports.refreshSpecificationDistTags = exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getWebappPath = exports.getProjectType = exports.getProject = exports.getNodeModulesPath = exports.getMtaPath = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getI18nPropertiesPaths = exports.getSpecification = exports.getCapI18nFolderNames = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapEnvironment = exports.getCapCustomPaths = exports.getAppType = exports.getAppProgrammingLanguage = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.createProjectAccess = exports.createApplicationAccess = exports.clearCdsModuleCache = exports.addPackageDevDependency = exports.getFilePaths = exports.FioriToolsSettings = exports.DirName = exports.FileName = void 0;
|
|
17
|
+
exports.updatePackageScript = exports.filterDataSourcesByType = exports.toReferenceUri = exports.refreshSpecificationDistTags = exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getWebappPath = exports.getProjectType = exports.getProject = exports.getNodeModulesPath = exports.getMtaPath = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getI18nPropertiesPaths = exports.getSpecificationPath = exports.getSpecification = exports.getCapI18nFolderNames = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapEnvironment = exports.getCapCustomPaths = exports.getAppType = exports.getAppProgrammingLanguage = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.createProjectAccess = exports.createApplicationAccess = exports.clearCdsModuleCache = exports.addPackageDevDependency = exports.getFilePaths = exports.FioriToolsSettings = exports.DirName = exports.FileName = void 0;
|
|
18
18
|
var constants_1 = require("./constants");
|
|
19
19
|
Object.defineProperty(exports, "FileName", { enumerable: true, get: function () { return constants_1.FileName; } });
|
|
20
20
|
Object.defineProperty(exports, "DirName", { enumerable: true, get: function () { return constants_1.DirName; } });
|
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "getCdsRoots", { enumerable: true, get: function
|
|
|
42
42
|
Object.defineProperty(exports, "getCdsServices", { enumerable: true, get: function () { return project_1.getCdsServices; } });
|
|
43
43
|
Object.defineProperty(exports, "getCapI18nFolderNames", { enumerable: true, get: function () { return project_1.getCapI18nFolderNames; } });
|
|
44
44
|
Object.defineProperty(exports, "getSpecification", { enumerable: true, get: function () { return project_1.getSpecification; } });
|
|
45
|
+
Object.defineProperty(exports, "getSpecificationPath", { enumerable: true, get: function () { return project_1.getSpecificationPath; } });
|
|
45
46
|
Object.defineProperty(exports, "getI18nPropertiesPaths", { enumerable: true, get: function () { return project_1.getI18nPropertiesPaths; } });
|
|
46
47
|
Object.defineProperty(exports, "getMinUI5VersionFromManifest", { enumerable: true, get: function () { return project_1.getMinUI5VersionFromManifest; } });
|
|
47
48
|
Object.defineProperty(exports, "getMinUI5VersionAsArray", { enumerable: true, get: function () { return project_1.getMinUI5VersionAsArray; } });
|
package/dist/project/index.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export { getWebappPath, readUi5Yaml } from './ui5-config';
|
|
|
9
9
|
export { getMtaPath } from './mta';
|
|
10
10
|
export { createApplicationAccess, createProjectAccess } from './access';
|
|
11
11
|
export { updatePackageScript } from './script';
|
|
12
|
-
export { getSpecification, refreshSpecificationDistTags } from './specification';
|
|
12
|
+
export { getSpecification, getSpecificationPath, refreshSpecificationDistTags } from './specification';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/project/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refreshSpecificationDistTags = exports.getSpecification = exports.updatePackageScript = exports.createProjectAccess = exports.createApplicationAccess = exports.getMtaPath = exports.readUi5Yaml = exports.getWebappPath = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.loadModuleFromProject = exports.getProjectType = exports.getProject = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getAppType = exports.getAppProgrammingLanguage = exports.getI18nPropertiesPaths = exports.getCapI18nFolderNames = exports.getNodeModulesPath = exports.addPackageDevDependency = exports.filterDataSourcesByType = exports.clearCdsModuleCache = exports.toReferenceUri = exports.readCapServiceMetadataEdmx = exports.getCapEnvironment = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapCustomPaths = void 0;
|
|
3
|
+
exports.refreshSpecificationDistTags = exports.getSpecificationPath = exports.getSpecification = exports.updatePackageScript = exports.createProjectAccess = exports.createApplicationAccess = exports.getMtaPath = exports.readUi5Yaml = exports.getWebappPath = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.loadModuleFromProject = exports.getProjectType = exports.getProject = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getAppType = exports.getAppProgrammingLanguage = exports.getI18nPropertiesPaths = exports.getCapI18nFolderNames = exports.getNodeModulesPath = exports.addPackageDevDependency = exports.filterDataSourcesByType = exports.clearCdsModuleCache = exports.toReferenceUri = exports.readCapServiceMetadataEdmx = exports.getCapEnvironment = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapCustomPaths = void 0;
|
|
4
4
|
var cap_1 = require("./cap");
|
|
5
5
|
Object.defineProperty(exports, "getCapCustomPaths", { enumerable: true, get: function () { return cap_1.getCapCustomPaths; } });
|
|
6
6
|
Object.defineProperty(exports, "getCapModelAndServices", { enumerable: true, get: function () { return cap_1.getCapModelAndServices; } });
|
|
@@ -51,5 +51,6 @@ var script_1 = require("./script");
|
|
|
51
51
|
Object.defineProperty(exports, "updatePackageScript", { enumerable: true, get: function () { return script_1.updatePackageScript; } });
|
|
52
52
|
var specification_1 = require("./specification");
|
|
53
53
|
Object.defineProperty(exports, "getSpecification", { enumerable: true, get: function () { return specification_1.getSpecification; } });
|
|
54
|
+
Object.defineProperty(exports, "getSpecificationPath", { enumerable: true, get: function () { return specification_1.getSpecificationPath; } });
|
|
54
55
|
Object.defineProperty(exports, "refreshSpecificationDistTags", { enumerable: true, get: function () { return specification_1.refreshSpecificationDistTags; } });
|
|
55
56
|
//# sourceMappingURL=index.js.map
|
package/dist/project/info.js
CHANGED
|
@@ -17,10 +17,12 @@ const semver_1 = require("semver");
|
|
|
17
17
|
* @returns - project structure with project info like project type, apps, root folder
|
|
18
18
|
*/
|
|
19
19
|
async function getProject(root) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
20
|
+
if (!(await (0, file_1.fileExists)((0, path_1.join)(root, constants_1.FileName.Package)))) {
|
|
21
|
+
throw new Error(`The project root folder '${root}' is not a Fiori project. No 'package.json' found.`);
|
|
22
|
+
}
|
|
23
|
+
const capProjectType = await (0, cap_1.getCapProjectType)(root);
|
|
24
|
+
const projectType = capProjectType ?? 'EDMXBackend';
|
|
25
|
+
const appFolders = await getAppFolders(root);
|
|
24
26
|
const apps = await getApps(root, appFolders);
|
|
25
27
|
return {
|
|
26
28
|
root,
|
|
@@ -30,17 +32,16 @@ async function getProject(root) {
|
|
|
30
32
|
}
|
|
31
33
|
exports.getProject = getProject;
|
|
32
34
|
/**
|
|
33
|
-
* Returns the
|
|
35
|
+
* Returns the applications for the project. For single app
|
|
34
36
|
* projects, this is just an array with one empty string. For CAP projects, this is an
|
|
35
37
|
* array of operating system specific relative paths to the apps.
|
|
36
38
|
*
|
|
37
|
-
* @param
|
|
39
|
+
* @param root - project root folder
|
|
38
40
|
* @returns - array of operating specific application folders
|
|
39
41
|
*/
|
|
40
|
-
function getAppFolders(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
: [''];
|
|
42
|
+
async function getAppFolders(root) {
|
|
43
|
+
const apps = await (0, search_1.findAllApps)([root]);
|
|
44
|
+
return apps.length > 0 ? apps.map((app) => (0, path_1.relative)(root, app.appRoot)) : [''];
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Get the application structure for each application in the project.
|
|
@@ -69,6 +70,7 @@ async function getApps(root, appFolders) {
|
|
|
69
70
|
async function getApplicationStructure(root, appFolder) {
|
|
70
71
|
const appRoot = (0, path_1.join)(root, appFolder);
|
|
71
72
|
const absoluteWebappPath = await (0, ui5_config_1.getWebappPath)(appRoot);
|
|
73
|
+
const appType = (await getAppType(appRoot));
|
|
72
74
|
const manifest = (0, path_1.join)(absoluteWebappPath, constants_1.FileName.Manifest);
|
|
73
75
|
if (!(await (0, file_1.fileExists)(manifest))) {
|
|
74
76
|
return undefined;
|
|
@@ -80,6 +82,7 @@ async function getApplicationStructure(root, appFolder) {
|
|
|
80
82
|
const services = await (0, service_1.getServicesAndAnnotations)(manifest, manifestObject);
|
|
81
83
|
return {
|
|
82
84
|
appRoot,
|
|
85
|
+
appType,
|
|
83
86
|
manifest,
|
|
84
87
|
changes,
|
|
85
88
|
i18n,
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { Logger } from '@sap-ux/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Get the module path from project or app. Throws error if module is not installed.
|
|
4
|
+
*
|
|
5
|
+
* @param projectRoot - root path of the project/app.
|
|
6
|
+
* @param moduleName - name of the node module.
|
|
7
|
+
* @returns - path to module.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getModulePath(projectRoot: string, moduleName: string): Promise<string>;
|
|
2
10
|
/**
|
|
3
11
|
* Load module from project or app. Throws error if module is not installed.
|
|
4
12
|
*
|
|
@@ -23,13 +23,27 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.deleteModule = exports.getModule = exports.loadModuleFromProject = void 0;
|
|
26
|
+
exports.deleteModule = exports.getModule = exports.loadModuleFromProject = exports.getModulePath = void 0;
|
|
27
27
|
const fs_1 = require("fs");
|
|
28
28
|
const promises_1 = require("fs/promises");
|
|
29
29
|
const path_1 = require("path");
|
|
30
30
|
const dependencies_1 = require("./dependencies");
|
|
31
31
|
const constants_1 = require("../constants");
|
|
32
32
|
const command_1 = require("../command");
|
|
33
|
+
/**
|
|
34
|
+
* Get the module path from project or app. Throws error if module is not installed.
|
|
35
|
+
*
|
|
36
|
+
* @param projectRoot - root path of the project/app.
|
|
37
|
+
* @param moduleName - name of the node module.
|
|
38
|
+
* @returns - path to module.
|
|
39
|
+
*/
|
|
40
|
+
async function getModulePath(projectRoot, moduleName) {
|
|
41
|
+
if (!(0, dependencies_1.getNodeModulesPath)(projectRoot, moduleName)) {
|
|
42
|
+
throw Error('Path to module not found.');
|
|
43
|
+
}
|
|
44
|
+
return require.resolve(moduleName, { paths: [projectRoot] });
|
|
45
|
+
}
|
|
46
|
+
exports.getModulePath = getModulePath;
|
|
33
47
|
/**
|
|
34
48
|
* Load module from project or app. Throws error if module is not installed.
|
|
35
49
|
*
|
|
@@ -46,10 +60,7 @@ const command_1 = require("../command");
|
|
|
46
60
|
async function loadModuleFromProject(projectRoot, moduleName) {
|
|
47
61
|
let module;
|
|
48
62
|
try {
|
|
49
|
-
|
|
50
|
-
throw Error('Path to module not found.');
|
|
51
|
-
}
|
|
52
|
-
const modulePath = require.resolve(moduleName, { paths: [projectRoot] });
|
|
63
|
+
const modulePath = await getModulePath(projectRoot, moduleName);
|
|
53
64
|
module = (await Promise.resolve(`${modulePath}`).then(s => __importStar(require(s))));
|
|
54
65
|
}
|
|
55
66
|
catch (error) {
|
package/dist/project/search.js
CHANGED
|
@@ -194,6 +194,9 @@ async function findRootsForPath(path) {
|
|
|
194
194
|
*/
|
|
195
195
|
async function findCapProjectRoot(path) {
|
|
196
196
|
try {
|
|
197
|
+
if (!(0, path_1.isAbsolute)(path)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
197
200
|
const { root } = (0, path_1.parse)(path);
|
|
198
201
|
let projectRoot = (0, path_1.dirname)(path);
|
|
199
202
|
while (projectRoot !== root) {
|
|
@@ -21,4 +21,16 @@ export declare function getSpecification<T>(root: string, options?: {
|
|
|
21
21
|
export declare function refreshSpecificationDistTags(options?: {
|
|
22
22
|
logger?: Logger;
|
|
23
23
|
}): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the path to the specification used.
|
|
26
|
+
* Can be path to node_modules in project, or cache.
|
|
27
|
+
*
|
|
28
|
+
* @param root - root path of the project/app
|
|
29
|
+
* @param [options] - optional options
|
|
30
|
+
* @param [options.logger] - optional logger instance
|
|
31
|
+
* @returns - path to specification
|
|
32
|
+
*/
|
|
33
|
+
export declare function getSpecificationPath(root: string, options?: {
|
|
34
|
+
logger?: Logger;
|
|
35
|
+
}): Promise<string>;
|
|
24
36
|
//# sourceMappingURL=specification.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refreshSpecificationDistTags = exports.getSpecification = void 0;
|
|
3
|
+
exports.getSpecificationPath = exports.refreshSpecificationDistTags = exports.getSpecification = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -13,29 +13,14 @@ const file_1 = require("../file");
|
|
|
13
13
|
const command_1 = require("../command");
|
|
14
14
|
const specificationDistTagPath = (0, path_1.join)(constants_1.fioriToolsDirectory, constants_1.FileName.SpecificationDistTags);
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* 1. if package.json contains devDependency to specification, attempts to load from project.
|
|
18
|
-
* 2. if not in package.json of project, attempts to load from cache.
|
|
16
|
+
* Gets the dist-tag for the provided project/app and returns it.
|
|
19
17
|
*
|
|
20
18
|
* @param root - root path of the project/app
|
|
21
19
|
* @param [options] - optional options
|
|
22
20
|
* @param [options.logger] - logger instance
|
|
23
21
|
* @returns - specification instance
|
|
24
22
|
*/
|
|
25
|
-
async function
|
|
26
|
-
let specification;
|
|
27
|
-
const logger = options?.logger;
|
|
28
|
-
try {
|
|
29
|
-
const packageJson = await (0, file_1.readJSON)((0, path_1.join)(root, constants_1.FileName.Package));
|
|
30
|
-
if (packageJson.devDependencies?.['@sap/ux-specification']) {
|
|
31
|
-
logger?.debug(`Specification found in devDependencies of project '${root}', trying to load`);
|
|
32
|
-
// Early return with load module from project. If it throws an error it is not handled here.
|
|
33
|
-
return (0, module_loader_1.loadModuleFromProject)(root, '@sap/ux-specification');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
logger?.debug(`Specification not found in project '${root}', trying to load from cache`);
|
|
38
|
-
}
|
|
23
|
+
async function getProjectDistTag(root, options) {
|
|
39
24
|
let distTag = 'latest';
|
|
40
25
|
try {
|
|
41
26
|
const webappPath = await (0, ui5_config_1.getWebappPath)(root);
|
|
@@ -47,8 +32,32 @@ async function getSpecification(root, options) {
|
|
|
47
32
|
}
|
|
48
33
|
}
|
|
49
34
|
catch (error) {
|
|
50
|
-
logger?.error(`Failed to get minimum UI5 version from manifest: ${error} using 'latest'`);
|
|
35
|
+
options?.logger?.error(`Failed to get minimum UI5 version from manifest: ${error} using 'latest'`);
|
|
51
36
|
}
|
|
37
|
+
return distTag;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks if package.json contains dev dependency to specification.
|
|
41
|
+
*
|
|
42
|
+
* @param root - root path of the project/app
|
|
43
|
+
* @returns If dev dependency to specification is found in package.json
|
|
44
|
+
*/
|
|
45
|
+
async function hasSpecificationDevDependency(root) {
|
|
46
|
+
const packageJson = await (0, file_1.readJSON)((0, path_1.join)(root, constants_1.FileName.Package));
|
|
47
|
+
return !!packageJson.devDependencies?.['@sap/ux-specification'];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Loads the specification module from cache and returns it.
|
|
51
|
+
*
|
|
52
|
+
* @param root - root path of the project/app
|
|
53
|
+
* @param [options] - optional options
|
|
54
|
+
* @param [options.logger] - logger instance
|
|
55
|
+
* @returns - specification instance
|
|
56
|
+
*/
|
|
57
|
+
async function getSpecificationModule(root, options) {
|
|
58
|
+
const logger = options?.logger;
|
|
59
|
+
let specification;
|
|
60
|
+
const distTag = await getProjectDistTag(root, { logger });
|
|
52
61
|
try {
|
|
53
62
|
specification = await getSpecificationByDistTag(distTag, { logger });
|
|
54
63
|
logger?.debug(`Specification loaded from cache using dist-tag '${distTag}'`);
|
|
@@ -59,6 +68,30 @@ async function getSpecification(root, options) {
|
|
|
59
68
|
}
|
|
60
69
|
return specification;
|
|
61
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Loads and return specification from project or cache.
|
|
73
|
+
* 1. if package.json contains devDependency to specification, attempts to load from project.
|
|
74
|
+
* 2. if not in package.json of project, attempts to load from cache.
|
|
75
|
+
*
|
|
76
|
+
* @param root - root path of the project/app
|
|
77
|
+
* @param [options] - optional options
|
|
78
|
+
* @param [options.logger] - logger instance
|
|
79
|
+
* @returns - specification instance
|
|
80
|
+
*/
|
|
81
|
+
async function getSpecification(root, options) {
|
|
82
|
+
const logger = options?.logger;
|
|
83
|
+
try {
|
|
84
|
+
if (await hasSpecificationDevDependency(root)) {
|
|
85
|
+
logger?.debug(`Specification found in devDependencies of project '${root}', trying to load`);
|
|
86
|
+
// Early return with load module from project. If it throws an error it is not handled here.
|
|
87
|
+
return (0, module_loader_1.loadModuleFromProject)(root, '@sap/ux-specification');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
logger?.debug(`Specification not found in project '${root}', trying to load from cache`);
|
|
92
|
+
}
|
|
93
|
+
return await getSpecificationModule(root, { logger });
|
|
94
|
+
}
|
|
62
95
|
exports.getSpecification = getSpecification;
|
|
63
96
|
/**
|
|
64
97
|
* Refreshes the specification dist-tags cache. Also cleans specification modules in cache that are not required anymore.
|
|
@@ -126,4 +159,42 @@ async function convertDistTagToVersion(distTag, options) {
|
|
|
126
159
|
const version = specificationDistTags[distTag] ?? specificationDistTags.latest;
|
|
127
160
|
return version;
|
|
128
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets the dist-tag of a project specification and returns the version from it.
|
|
164
|
+
*
|
|
165
|
+
* @param root - root path of the project/app
|
|
166
|
+
* @param [options] - optional options
|
|
167
|
+
* @param [options.logger] - optional logger instance
|
|
168
|
+
* @returns - version of specification
|
|
169
|
+
*/
|
|
170
|
+
async function getSpecificationVersion(root, options) {
|
|
171
|
+
const logger = options?.logger;
|
|
172
|
+
const distTag = await getProjectDistTag(root, { logger });
|
|
173
|
+
return await convertDistTagToVersion(distTag, { logger });
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Returns the path to the specification used.
|
|
177
|
+
* Can be path to node_modules in project, or cache.
|
|
178
|
+
*
|
|
179
|
+
* @param root - root path of the project/app
|
|
180
|
+
* @param [options] - optional options
|
|
181
|
+
* @param [options.logger] - optional logger instance
|
|
182
|
+
* @returns - path to specification
|
|
183
|
+
*/
|
|
184
|
+
async function getSpecificationPath(root, options) {
|
|
185
|
+
const logger = options?.logger;
|
|
186
|
+
const moduleName = '@sap/ux-specification';
|
|
187
|
+
if (await hasSpecificationDevDependency(root)) {
|
|
188
|
+
const modulePath = await (0, module_loader_1.getModulePath)(root, moduleName);
|
|
189
|
+
logger?.debug(`Specification root found in project '${root}'`);
|
|
190
|
+
return modulePath.slice(0, modulePath.lastIndexOf(moduleName) + moduleName.length);
|
|
191
|
+
}
|
|
192
|
+
logger?.debug(`Specification not found in project '${root}', trying to find in cache`);
|
|
193
|
+
await getSpecificationModule(root, { logger });
|
|
194
|
+
const version = await getSpecificationVersion(root, { logger });
|
|
195
|
+
const moduleRoot = (0, path_1.join)(constants_1.moduleCacheRoot, moduleName, version);
|
|
196
|
+
const modulePath = await (0, module_loader_1.getModulePath)(moduleRoot, moduleName);
|
|
197
|
+
return modulePath.slice(0, modulePath.lastIndexOf(moduleName) + moduleName.length);
|
|
198
|
+
}
|
|
199
|
+
exports.getSpecificationPath = getSpecificationPath;
|
|
129
200
|
//# sourceMappingURL=specification.js.map
|