@sap-ux/fiori-generator-shared 0.3.21 → 0.5.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.
@@ -0,0 +1,17 @@
1
+ import type { PackageJsonScripts, PackageScriptsOptions } from './types';
2
+ /**
3
+ * Get an object reflecting the scripts that need to be added to the package.json.
4
+ *
5
+ * @param options Collection of mostly optional settings.
6
+ * @param options.localOnly no server available
7
+ * @param options.addMock add a script for using the mockserver
8
+ * @param options.addTest add a script for executing OPA tests
9
+ * @param options.sapClient SAP client required for connecting to the backend
10
+ * @param options.flpAppId local FLP id
11
+ * @param options.startFile path that should be opened with the start script
12
+ * @param options.localStartFile path that should be opend with the start-local script
13
+ * @param options.generateIndex exclude the start-noflp script
14
+ * @returns package.json scripts
15
+ */
16
+ export declare function getPackageScripts({ localOnly, addMock, addTest, sapClient, flpAppId, startFile, localStartFile, generateIndex }: PackageScriptsOptions): PackageJsonScripts;
17
+ //# sourceMappingURL=getPackageScripts.d.ts.map
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageScripts = void 0;
4
+ const i18n_1 = require("./i18n");
5
+ /**
6
+ * Builds the command for the `start-noflp` script in `package.json`.
7
+ *
8
+ * This command is used to start the application without the FLP configuration.
9
+ *
10
+ * @param {boolean} localOnly - Indicates whether only a local server is available. If `true`,
11
+ * a warning message is returned instead of a command.
12
+ * @param {URLSearchParams} searchParams - The search parameters to be included in the command URL.
13
+ * @returns {string} - The command to be used in the `start-noflp` script. If `localOnly` is `true`,
14
+ * returns a warning message. Otherwise, returns a `fiori run` command with the
15
+ * appropriate parameters.
16
+ */
17
+ function buildStartNoFLPCommand(localOnly, searchParams) {
18
+ const searchParamString = searchParams.toString();
19
+ const searchParam = searchParamString ? `?${searchParamString}` : '';
20
+ if (localOnly) {
21
+ return `echo \\"${(0, i18n_1.t)('info.mockOnlyWarning')}\\"`;
22
+ }
23
+ return `fiori run --open "index.html${searchParam}"`;
24
+ }
25
+ /**
26
+ * Constructs a `URLSearchParams` object with the specified query parameters.
27
+ *
28
+ * This function creates a `URLSearchParams` instance and appends the `sap-client` parameter if provided,
29
+ * along with a default `sap-ui-xx-viewCache` parameter set to `false`.
30
+ *
31
+ * @param {string} [sapClient] - The SAP client value to be included as a query parameter.
32
+ * @returns {URLSearchParams} - The `URLSearchParams` object containing the specified query parameters.
33
+ */
34
+ function buildSearchParams(sapClient) {
35
+ const params = new URLSearchParams();
36
+ if (sapClient) {
37
+ params.append('sap-client', sapClient);
38
+ }
39
+ params.append('sap-ui-xx-viewCache', 'false');
40
+ return params;
41
+ }
42
+ /**
43
+ * Constructs a URL parameter string from search parameters and an optional FLP app ID.
44
+ *
45
+ * @param {URLSearchParams} searchParams - The search parameters to include in the query string.
46
+ * @param {string} [flpAppId] - The FLP app ID to be included as a fragment identifier.
47
+ * If not provided, the fragment identifier will be omitted.
48
+ * @returns {string} - A string representing the combined query parameters and fragment identifier.
49
+ * If `searchParams` is empty, only the fragment identifier will be included.
50
+ */
51
+ function buildParams(searchParams, flpAppId) {
52
+ const searchParamString = searchParams.toString();
53
+ const searchParam = searchParamString ? `?${searchParamString}` : '';
54
+ const hashFragment = flpAppId ? `#${flpAppId}` : '';
55
+ return `${searchParam}${hashFragment}`;
56
+ }
57
+ /**
58
+ * Constructs the command for the `start` script in `package.json`.
59
+ *
60
+ * @param {boolean} localOnly - Indicates whether only a local server is available. If `true`, a warning
61
+ * message is returned instead of a command.
62
+ * @param {string} params - The query parameters to be included in the command URL.
63
+ * @param {string} [startFile] - The path to the file to be opened with the `start` command.
64
+ * If not provided, defaults to `'test/flpSandbox.html'`.
65
+ * @returns {string} - The command for the `start` script, including either a warning message or the `fiori run`
66
+ * command with the specified file and parameters.
67
+ */
68
+ function buildStartCommand(localOnly, params, startFile) {
69
+ if (localOnly) {
70
+ return `echo \\"${(0, i18n_1.t)('info.mockOnlyWarning')}\\"`;
71
+ }
72
+ return `fiori run --open "${startFile ?? 'test/flpSandbox.html'}${params}"`;
73
+ }
74
+ /**
75
+ * Generates a variant management script in preview mode.
76
+ *
77
+ * @param {string} sapClient - The SAP client parameter to include in the URL. If not provided, the URL will not include the `sap-client` parameter.
78
+ * @returns {string} A variant management script to run the application in preview mode.
79
+ */
80
+ function getVariantPreviewAppScript(sapClient) {
81
+ const previewAppAnchor = '#preview-app';
82
+ const disableCacheParam = 'sap-ui-xx-viewCache=false';
83
+ const sapClientParam = sapClient ? `&sap-client=${sapClient}` : '';
84
+ const urlParam = `?${[
85
+ sapClientParam,
86
+ disableCacheParam,
87
+ 'fiori-tools-rta-mode=true',
88
+ 'sap-ui-rta-skip-flex-validation=true'
89
+ ]
90
+ .filter(Boolean)
91
+ .join('&')}`;
92
+ // Please keep the special characters in the below command
93
+ // as removing them may cause the browser to misinterpret the URI components without the necessary escaping and quotes.
94
+ // eslint-disable-next-line no-useless-escape
95
+ return `fiori run --open \"preview.html${urlParam}${previewAppAnchor}\"`;
96
+ }
97
+ /**
98
+ * Get an object reflecting the scripts that need to be added to the package.json.
99
+ *
100
+ * @param options Collection of mostly optional settings.
101
+ * @param options.localOnly no server available
102
+ * @param options.addMock add a script for using the mockserver
103
+ * @param options.addTest add a script for executing OPA tests
104
+ * @param options.sapClient SAP client required for connecting to the backend
105
+ * @param options.flpAppId local FLP id
106
+ * @param options.startFile path that should be opened with the start script
107
+ * @param options.localStartFile path that should be opend with the start-local script
108
+ * @param options.generateIndex exclude the start-noflp script
109
+ * @returns package.json scripts
110
+ */
111
+ function getPackageScripts({ localOnly, addMock = true, addTest = false, sapClient, flpAppId = '', startFile, localStartFile, generateIndex = true }) {
112
+ const searchParams = buildSearchParams(sapClient);
113
+ const params = buildParams(searchParams, flpAppId);
114
+ const scripts = {
115
+ start: buildStartCommand(localOnly, params, startFile),
116
+ 'start-local': `fiori run --config ./ui5-local.yaml --open "${localStartFile ?? 'test/flpSandbox.html'}${params}"`
117
+ };
118
+ if (generateIndex) {
119
+ scripts['start-noflp'] = buildStartNoFLPCommand(localOnly, searchParams);
120
+ }
121
+ if (addMock) {
122
+ scripts['start-mock'] = `fiori run --config ./ui5-mock.yaml --open "test/flpSandbox.html${params}"`;
123
+ }
124
+ if (addTest) {
125
+ scripts['int-test'] = 'fiori run --config ./ui5-mock.yaml --open "test/integration/opaTests.qunit.html"';
126
+ }
127
+ scripts['start-variants-management'] = localOnly
128
+ ? `echo \\"${(0, i18n_1.t)('info.mockOnlyWarning')}\\"`
129
+ : getVariantPreviewAppScript(sapClient);
130
+ return scripts;
131
+ }
132
+ exports.getPackageScripts = getPackageScripts;
133
+ //# sourceMappingURL=getPackageScripts.js.map
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { TOptions } from 'i18next';
2
+ /**
3
+ * Initialize i18next with the translations for this module.
4
+ */
5
+ export declare function initI18n(): Promise<void>;
6
+ /**
7
+ * Helper function facading the call call to i18next.
8
+ *
9
+ * @param key i18n key
10
+ * @param options additional options
11
+ * @returns {string} localized string stored for the given key
12
+ */
13
+ export declare function t(key: string, options?: TOptions): string;
14
+ //# sourceMappingURL=i18n.d.ts.map
package/dist/i18n.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.t = exports.initI18n = void 0;
7
+ const i18next_1 = __importDefault(require("i18next"));
8
+ const fiori_generator_shared_i18n_json_1 = __importDefault(require("./translations/fiori-generator-shared.i18n.json"));
9
+ const NS = 'fiori-freestyle-writer';
10
+ /**
11
+ * Initialize i18next with the translations for this module.
12
+ */
13
+ async function initI18n() {
14
+ await i18next_1.default.init({
15
+ resources: {
16
+ en: {
17
+ [NS]: fiori_generator_shared_i18n_json_1.default
18
+ }
19
+ },
20
+ lng: 'en',
21
+ fallbackLng: 'en',
22
+ defaultNS: NS,
23
+ ns: [NS]
24
+ });
25
+ }
26
+ exports.initI18n = initI18n;
27
+ /**
28
+ * Helper function facading the call call to i18next.
29
+ *
30
+ * @param key i18n key
31
+ * @param options additional options
32
+ * @returns {string} localized string stored for the given key
33
+ */
34
+ function t(key, options) {
35
+ return i18next_1.default.t(key, options);
36
+ }
37
+ exports.t = t;
38
+ initI18n().catch(() => {
39
+ // Ignore any errors since the write will still work
40
+ });
41
+ //# sourceMappingURL=i18n.js.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './cap';
2
2
  export * from './environment';
3
+ export { getPackageScripts } from './getPackageScripts';
3
4
  export { getBootstrapResourceUrls } from './helpers';
4
5
  export { generateReadMe } from './read-me';
5
6
  export * from './system-utils';
7
+ export { PackageJsonScripts } from './types';
6
8
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,9 +14,11 @@ 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.generateReadMe = exports.getBootstrapResourceUrls = void 0;
17
+ exports.generateReadMe = exports.getBootstrapResourceUrls = exports.getPackageScripts = void 0;
18
18
  __exportStar(require("./cap"), exports);
19
19
  __exportStar(require("./environment"), exports);
20
+ var getPackageScripts_1 = require("./getPackageScripts");
21
+ Object.defineProperty(exports, "getPackageScripts", { enumerable: true, get: function () { return getPackageScripts_1.getPackageScripts; } });
20
22
  var helpers_1 = require("./helpers");
21
23
  Object.defineProperty(exports, "getBootstrapResourceUrls", { enumerable: true, get: function () { return helpers_1.getBootstrapResourceUrls; } });
22
24
  var read_me_1 = require("./read-me");
@@ -0,0 +1,5 @@
1
+ {
2
+ "info": {
3
+ "mockOnlyWarning": "This application was generated with a local metadata file and does not reference a live server. Please add the required server configuration or start this application with mock data using the target: npm run start-mock"
4
+ }
5
+ }
package/dist/types.d.ts CHANGED
@@ -53,5 +53,43 @@ export interface ReadMe {
53
53
  /** Additional custom entries for the application. */
54
54
  additionalEntries?: AdditionalEntries[];
55
55
  }
56
+ /**
57
+ * Defines the structure for the `package.json` scripts section.
58
+ */
59
+ export interface PackageJsonScripts {
60
+ /** The command to start the application. */
61
+ start: string;
62
+ /** The command to start the application with local configuration */
63
+ 'start-local': string;
64
+ /** Optional command to start the application without flp command. */
65
+ 'start-noflp'?: string;
66
+ /** Optional command to start the application with a mock server configuration. */
67
+ 'start-mock'?: string;
68
+ /** Optional command to run tests. */
69
+ 'int-test'?: string;
70
+ /** Optional command to add the variants management script. */
71
+ 'start-variants-management'?: string;
72
+ }
73
+ /**
74
+ * Defines the options for generating `package.json` scripts.
75
+ */
76
+ export interface PackageScriptsOptions {
77
+ /** Specifies whether only a local server is available. If true, certain scripts may display a warning message. */
78
+ localOnly: boolean;
79
+ /** Indicates if a script for using a mock server should be added. Defaults to true. */
80
+ addMock?: boolean;
81
+ /** Indicates if a script for running integration tests should be added. Defaults to false. */
82
+ addTest?: boolean;
83
+ /** The SAP client to be used, if applicable. */
84
+ sapClient?: string;
85
+ /** The flp app ID to be used in URLs. */
86
+ flpAppId?: string;
87
+ /** The path to the file that should be opened with the `start` script. */
88
+ startFile?: string;
89
+ /** The path to the file that should be opened with the `start-local` script. */
90
+ localStartFile?: string;
91
+ /** If true, a script for starting the app without flp will be generated. Defaults to true. */
92
+ generateIndex?: boolean;
93
+ }
56
94
  export {};
57
95
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/fiori-generator-shared",
3
3
  "description": "Commonly used shared functionality and types to support the fiori generator.",
4
- "version": "0.3.21",
4
+ "version": "0.5.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -17,10 +17,11 @@
17
17
  "!dist/**/*.map"
18
18
  ],
19
19
  "dependencies": {
20
+ "i18next": "20.6.1",
20
21
  "mem-fs": "2.1.0",
21
22
  "mem-fs-editor": "9.4.0",
22
23
  "@sap-ux/btp-utils": "0.15.2",
23
- "@sap-ux/project-access": "1.27.3"
24
+ "@sap-ux/project-access": "1.27.4"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/mem-fs-editor": "7.0.1",