@sap-ux/ui5-library-writer 0.7.2 → 1.0.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.
@@ -1,4 +1,4 @@
1
- import type { UI5LibInput, UI5LibConfig } from '../types';
1
+ import type { UI5LibInput, UI5LibConfig } from '../types.js';
2
2
  /**
3
3
  * Merges UI5LibConfig instance with default properties.
4
4
  *
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeWithDefaults = mergeWithDefaults;
4
- const validators_1 = require("./validators");
1
+ import { validate } from './validators.js';
5
2
  /**
6
3
  * Merges UI5LibConfig instance with default properties.
7
4
  *
8
5
  * @param {UI5LibConfig} libConfig - the UI5LibConfig instance
9
6
  * @returns {UI5LibInput} - a new UI5LibInput instance with all required defaults set
10
7
  */
11
- function mergeWithDefaults(libConfig) {
12
- (0, validators_1.validate)(libConfig);
8
+ export function mergeWithDefaults(libConfig) {
9
+ validate(libConfig);
13
10
  const libraryNamespace = `${libConfig.namespace}.${libConfig.libraryName}`;
14
11
  const author = libConfig.author ?? 'UX Tools';
15
12
  const libInput = {
@@ -1,4 +1,4 @@
1
- import type { UI5LibConfig } from '../types';
1
+ import type { UI5LibConfig } from '../types.js';
2
2
  /**
3
3
  * Validates the specified lib name to ensure we do not create malformed documents.
4
4
  *
@@ -1,14 +1,5 @@
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.validateLibName = validateLibName;
7
- exports.validateNamespace = validateNamespace;
8
- exports.validateUI5Version = validateUI5Version;
9
- exports.validate = validate;
10
- const semver_1 = __importDefault(require("semver"));
11
- const i18n_1 = require("../i18n");
1
+ import semVer from 'semver';
2
+ import { t } from '../i18n.js';
12
3
  /**
13
4
  * Validates the specified lib name to ensure we do not create malformed documents.
14
5
  *
@@ -16,12 +7,12 @@ const i18n_1 = require("../i18n");
16
7
  * @throws Error with validation message, if the app id is not valid
17
8
  * @returns true, if app id is validated
18
9
  */
19
- function validateLibName(libName) {
10
+ export function validateLibName(libName) {
20
11
  if (!libName) {
21
- throw new Error((0, i18n_1.t)('error.missingRequiredProperty', { propertyName: 'libraryName' }));
12
+ throw new Error(t('error.missingRequiredProperty', { propertyName: 'libraryName' }));
22
13
  }
23
14
  if (!/^[a-z][a-z0-9]*$/g.test(libName)) {
24
- throw new Error((0, i18n_1.t)('error.useAlphaNumeric', { propertyName: 'libraryName' }));
15
+ throw new Error(t('error.useAlphaNumeric', { propertyName: 'libraryName' }));
25
16
  }
26
17
  return true;
27
18
  }
@@ -35,25 +26,25 @@ function validateLibName(libName) {
35
26
  */
36
27
  function validateNamespacePattern(namespace, libName) {
37
28
  if (!/^[a-zA-Z]/.test(namespace)) {
38
- throw new Error((0, i18n_1.t)('error.invalidNamespace.mustStartWithLetter'));
29
+ throw new Error(t('error.invalidNamespace.mustStartWithLetter'));
39
30
  }
40
31
  if (namespace.endsWith('.')) {
41
- throw new Error((0, i18n_1.t)('error.invalidNamespace.mustEndInPeriod'));
32
+ throw new Error(t('error.invalidNamespace.mustEndInPeriod'));
42
33
  }
43
34
  if (namespace.toUpperCase() === 'SAP') {
44
- throw new Error((0, i18n_1.t)('error.invalidNamespace.cannotBeSap', { str: namespace }));
35
+ throw new Error(t('error.invalidNamespace.cannotBeSap', { str: namespace }));
45
36
  }
46
37
  if (namespace.toLowerCase().startsWith('new')) {
47
- throw new Error((0, i18n_1.t)('error.invalidNamespace.cannotStartWithNew', { str: namespace.substring(0, 3) }));
38
+ throw new Error(t('error.invalidNamespace.cannotStartWithNew', { str: namespace.substring(0, 3) }));
48
39
  }
49
40
  if (/\.\d/.test(namespace)) {
50
- throw new Error((0, i18n_1.t)('error.invalidNamespace.numAfterPeriod'));
41
+ throw new Error(t('error.invalidNamespace.numAfterPeriod'));
51
42
  }
52
43
  if (!/^[a-zA-Z\d_.]+$/.test(namespace)) {
53
- throw new Error((0, i18n_1.t)('error.invalidNamespace.specialCharacter'));
44
+ throw new Error(t('error.invalidNamespace.specialCharacter'));
54
45
  }
55
46
  if ((libName + namespace).length > 70) {
56
- throw new Error((0, i18n_1.t)('error.invalidNamespace.tooLong', { length: 70 }));
47
+ throw new Error(t('error.invalidNamespace.tooLong', { length: 70 }));
57
48
  }
58
49
  return true;
59
50
  }
@@ -65,9 +56,9 @@ function validateNamespacePattern(namespace, libName) {
65
56
  * @throws Error with validation message, if the namespace is not valid
66
57
  * @returns true, if app id is validated
67
58
  */
68
- function validateNamespace(namespace, libName) {
59
+ export function validateNamespace(namespace, libName) {
69
60
  if (!namespace) {
70
- throw new Error((0, i18n_1.t)('error.missingRequiredProperty', { propertyName: 'namespace' }));
61
+ throw new Error(t('error.missingRequiredProperty', { propertyName: 'namespace' }));
71
62
  }
72
63
  return validateNamespacePattern(namespace, libName);
73
64
  }
@@ -79,9 +70,9 @@ function validateNamespace(namespace, libName) {
79
70
  * @param version - the UI5 version string to validate
80
71
  * @returns - true if the specified UI5 version is considered valid
81
72
  */
82
- function validateUI5Version(version) {
83
- if (version && semver_1.default.coerce(version) === null) {
84
- throw new Error((0, i18n_1.t)('error.invalidUI5Version', { version }));
73
+ export function validateUI5Version(version) {
74
+ if (version && semVer.coerce(version) === null) {
75
+ throw new Error(t('error.invalidUI5Version', { version }));
85
76
  }
86
77
  return true;
87
78
  }
@@ -92,7 +83,7 @@ function validateUI5Version(version) {
92
83
  * @returns true, if the ui5Lib is valid
93
84
  * @throws Error with validation message, if the ui5App is not valid
94
85
  */
95
- function validate(ui5Lib) {
86
+ export function validate(ui5Lib) {
96
87
  return (validateLibName(ui5Lib.libraryName) &&
97
88
  validateNamespace(ui5Lib.namespace, ui5Lib.libraryName) &&
98
89
  validateUI5Version(ui5Lib.frameworkVersion));
package/dist/i18n.js CHANGED
@@ -1,23 +1,15 @@
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.i18n = void 0;
7
- exports.initI18n = initI18n;
8
- exports.t = t;
9
- const i18next_1 = __importDefault(require("i18next"));
10
- const ui5_library_writer_i18n_json_1 = __importDefault(require("./translations/ui5-library-writer.i18n.json"));
1
+ import i18next from 'i18next';
2
+ import translations from './translations/ui5-library-writer.i18n.json' with { type: 'json' };
11
3
  const NS = 'ui5-library-writer';
12
- exports.i18n = i18next_1.default.createInstance();
4
+ export const i18n = i18next.createInstance();
13
5
  /**
14
6
  * Initialize i18next with the translations for this module.
15
7
  */
16
- async function initI18n() {
17
- await exports.i18n.init({
8
+ export async function initI18n() {
9
+ await i18n.init({
18
10
  resources: {
19
11
  en: {
20
- [NS]: ui5_library_writer_i18n_json_1.default
12
+ [NS]: translations
21
13
  }
22
14
  },
23
15
  lng: 'en',
@@ -34,10 +26,8 @@ async function initI18n() {
34
26
  * @param options additional options
35
27
  * @returns {string} localized string stored for the given key
36
28
  */
37
- function t(key, options) {
38
- return exports.i18n.t(key, options);
29
+ export function t(key, options) {
30
+ return i18n.t(key, options);
39
31
  }
40
- initI18n().catch(() => {
41
- // cannot do anything about it but the write will still work
42
- });
32
+ void initI18n().catch(() => undefined);
43
33
  //# sourceMappingURL=i18n.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
- import type { UI5LibConfig } from './types';
2
+ import type { UI5LibConfig } from './types.js';
3
3
  /**
4
4
  * Writes the template to the memfs editor instance.
5
5
  *
package/dist/index.js CHANGED
@@ -1,16 +1,12 @@
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.generate = generate;
7
- const node_path_1 = require("node:path");
8
- const mem_fs_1 = require("mem-fs");
9
- const mem_fs_editor_1 = require("mem-fs-editor");
10
- const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
11
- const options_1 = require("./options");
12
- const data_1 = require("./data");
13
- const utils_1 = require("./utils");
1
+ import { dirname, join } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { create as createStorage } from 'mem-fs';
4
+ import { create } from 'mem-fs-editor';
5
+ import cloneDeep from 'lodash/cloneDeep.js';
6
+ import { enableTypescript } from './options/index.js';
7
+ import { mergeWithDefaults } from './data/index.js';
8
+ import { getTemplateVersionPath } from './utils.js';
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
10
  /**
15
11
  * Writes the template to the memfs editor instance.
16
12
  *
@@ -20,16 +16,16 @@ const utils_1 = require("./utils");
20
16
  * @returns the updated memfs editor instance
21
17
  */
22
18
  async function generate(basePath, ui5LibConfig, fs) {
23
- const reuseLib = (0, cloneDeep_1.default)(ui5LibConfig);
19
+ const reuseLib = cloneDeep(ui5LibConfig);
24
20
  if (!fs) {
25
- fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
21
+ fs = create(createStorage());
26
22
  }
27
- const libInput = (0, data_1.mergeWithDefaults)(ui5LibConfig);
28
- basePath = (0, node_path_1.join)(basePath, libInput.libraryNamespace);
29
- const tmplPath = (0, node_path_1.join)(__dirname, '..', 'templates');
23
+ const libInput = mergeWithDefaults(ui5LibConfig);
24
+ basePath = join(basePath, libInput.libraryNamespace);
25
+ const tmplPath = join(__dirname, '..', 'templates');
30
26
  const ignore = [reuseLib.typescript ? '**/*.js' : '**/*.ts'];
31
- const templateVersionPath = (0, utils_1.getTemplateVersionPath)(reuseLib.frameworkVersion);
32
- fs.copyTpl((0, node_path_1.join)(tmplPath, 'common', templateVersionPath, '**/*.*'), basePath, libInput, undefined, {
27
+ const templateVersionPath = getTemplateVersionPath(reuseLib.frameworkVersion);
28
+ fs.copyTpl(join(tmplPath, 'common', templateVersionPath, '**/*.*'), basePath, libInput, undefined, {
33
29
  globOptions: { dot: true, ignore },
34
30
  processDestinationPath: (filePath) => filePath
35
31
  .replace('baselibrary', libInput.libraryNamespaceURI)
@@ -37,8 +33,9 @@ async function generate(basePath, ui5LibConfig, fs) {
37
33
  .replace(/karma.conf.tmpl/g, 'karma.conf.js')
38
34
  });
39
35
  if (reuseLib.typescript) {
40
- await (0, options_1.enableTypescript)(libInput, basePath, tmplPath, fs);
36
+ await enableTypescript(libInput, basePath, tmplPath, fs);
41
37
  }
42
38
  return fs;
43
39
  }
40
+ export { generate };
44
41
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export * from './typescript';
1
+ export * from './typescript.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./typescript"), exports);
1
+ export * from './typescript.js';
18
2
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
- import type { UI5LibInput } from '../types';
2
+ import type { UI5LibInput } from '../types.js';
3
3
  /**
4
4
  * Enable typescript for the given input.
5
5
  *
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enableTypescript = enableTypescript;
4
- const ejs_1 = require("ejs");
5
- const project_access_1 = require("@sap-ux/project-access");
6
- const ui5_config_1 = require("@sap-ux/ui5-config");
7
- const node_path_1 = require("node:path");
8
- const semver_1 = require("semver");
1
+ import { render } from 'ejs';
2
+ import { getFilePaths } from '@sap-ux/project-access';
3
+ import { mergeObjects, UI5Config } from '@sap-ux/ui5-config';
4
+ import { join } from 'node:path';
5
+ import { gte } from 'semver';
9
6
  /**
10
7
  * Enable typescript for the given input.
11
8
  *
@@ -14,9 +11,9 @@ const semver_1 = require("semver");
14
11
  * @param tmplPath - the template path
15
12
  * @param fs - the memfs editor instance
16
13
  */
17
- async function enableTypescript(libInput, basePath, tmplPath, fs) {
18
- const tsTmplDirPath = (0, node_path_1.join)(tmplPath, 'optional', 'typescript');
19
- const tsTmplFilePaths = await (0, project_access_1.getFilePaths)(tsTmplDirPath);
14
+ export async function enableTypescript(libInput, basePath, tmplPath, fs) {
15
+ const tsTmplDirPath = join(tmplPath, 'optional', 'typescript');
16
+ const tsTmplFilePaths = await getFilePaths(tsTmplDirPath);
20
17
  const tsLibInput = {
21
18
  ...libInput,
22
19
  tsTypes: getTypePackageFor(libInput.framework, libInput.frameworkVersion),
@@ -24,7 +21,7 @@ async function enableTypescript(libInput, basePath, tmplPath, fs) {
24
21
  };
25
22
  tsTmplFilePaths.forEach((tsTmplFilePath) => {
26
23
  const relPath = tsTmplFilePath.replace(tsTmplDirPath, '');
27
- const outPath = (0, node_path_1.join)(basePath, relPath);
24
+ const outPath = join(basePath, relPath);
28
25
  // Extend or add
29
26
  if (!fs.exists(outPath)) {
30
27
  fs.copyTpl(tsTmplFilePath, outPath, tsLibInput, undefined, {
@@ -32,15 +29,15 @@ async function enableTypescript(libInput, basePath, tmplPath, fs) {
32
29
  });
33
30
  }
34
31
  else {
35
- const add = JSON.parse((0, ejs_1.render)(fs.read(tsTmplFilePath), tsLibInput, {}));
32
+ const add = JSON.parse(render(fs.read(tsTmplFilePath), tsLibInput, {}));
36
33
  const existingFile = JSON.parse(fs.read(outPath));
37
- const merged = (0, ui5_config_1.mergeObjects)(existingFile, add);
34
+ const merged = mergeObjects(existingFile, add);
38
35
  fs.writeJSON(outPath, merged);
39
36
  }
40
37
  });
41
38
  // ui5 yaml
42
- const ui5ConfigPath = (0, node_path_1.join)(basePath, 'ui5.yaml');
43
- const ui5Config = await ui5_config_1.UI5Config.newInstance(fs.read(ui5ConfigPath));
39
+ const ui5ConfigPath = join(basePath, 'ui5.yaml');
40
+ const ui5Config = await UI5Config.newInstance(fs.read(ui5ConfigPath));
44
41
  ui5Config.updateCustomMiddleware({
45
42
  name: 'fiori-tools-appreload',
46
43
  afterMiddleware: 'compression',
@@ -84,7 +81,7 @@ async function enableTypescript(libInput, basePath, tmplPath, fs) {
84
81
  * @returns types package
85
82
  */
86
83
  function getTypePackageFor(framework, version) {
87
- const typesName = (0, semver_1.gte)(version, '1.113.0') ? 'types' : 'ts-types-esm';
84
+ const typesName = gte(version, '1.113.0') ? 'types' : 'ts-types-esm';
88
85
  return `@${framework.toLowerCase()}/${typesName}`;
89
86
  }
90
87
  //# sourceMappingURL=typescript.js.map
package/dist/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/dist/utils.js CHANGED
@@ -1,11 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ui5LtsVersion_1_120 = exports.ui5LtsVersion_1_71 = void 0;
4
- exports.compareUI5VersionGte = compareUI5VersionGte;
5
- exports.getTemplateVersionPath = getTemplateVersionPath;
6
- const semver_1 = require("semver");
7
- exports.ui5LtsVersion_1_71 = '1.71.0';
8
- exports.ui5LtsVersion_1_120 = '1.120.0';
1
+ import { gte } from 'semver';
2
+ export const ui5LtsVersion_1_71 = '1.71.0';
3
+ export const ui5LtsVersion_1_120 = '1.120.0';
9
4
  /**
10
5
  * Compares two UI5 versions to determine if the first is greater than or equal to the second.
11
6
  *
@@ -13,13 +8,13 @@ exports.ui5LtsVersion_1_120 = '1.120.0';
13
8
  * @param {string} ui5VersionB - The second UI5 version to compare.
14
9
  * @returns {boolean} - True if the first version is greater than or equal to the second, false otherwise.
15
10
  */
16
- function compareUI5VersionGte(ui5VersionA, ui5VersionB) {
11
+ export function compareUI5VersionGte(ui5VersionA, ui5VersionB) {
17
12
  if (ui5VersionA === '') {
18
13
  // latest version
19
14
  return true;
20
15
  }
21
16
  else {
22
- return (0, semver_1.gte)(ui5VersionA, ui5VersionB, { loose: true });
17
+ return gte(ui5VersionA, ui5VersionB, { loose: true });
23
18
  }
24
19
  }
25
20
  /**
@@ -28,13 +23,13 @@ function compareUI5VersionGte(ui5VersionA, ui5VersionB) {
28
23
  * @param version - The framework version.
29
24
  * @returns {string} - The template version path.
30
25
  */
31
- function getTemplateVersionPath(version) {
26
+ export function getTemplateVersionPath(version) {
32
27
  let templateVersionPath = '';
33
- if (compareUI5VersionGte(version, exports.ui5LtsVersion_1_120)) {
34
- templateVersionPath = exports.ui5LtsVersion_1_120;
28
+ if (compareUI5VersionGte(version, ui5LtsVersion_1_120)) {
29
+ templateVersionPath = ui5LtsVersion_1_120;
35
30
  }
36
31
  else {
37
- templateVersionPath = exports.ui5LtsVersion_1_71;
32
+ templateVersionPath = ui5LtsVersion_1_71;
38
33
  }
39
34
  return templateVersionPath;
40
35
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/ui5-library-writer",
3
3
  "description": "Writer module to generate a new ui5 library",
4
+ "type": "module",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -9,7 +10,7 @@
9
10
  "bugs": {
10
11
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aui5-library-writer"
11
12
  },
12
- "version": "0.7.2",
13
+ "version": "1.0.0",
13
14
  "license": "Apache-2.0",
14
15
  "main": "dist/index.js",
15
16
  "files": [
@@ -29,8 +30,8 @@
29
30
  "mem-fs": "2.1.0",
30
31
  "mem-fs-editor": "9.4.0",
31
32
  "semver": "7.7.4",
32
- "@sap-ux/project-access": "1.38.1",
33
- "@sap-ux/ui5-config": "0.31.1"
33
+ "@sap-ux/project-access": "2.0.0",
34
+ "@sap-ux/ui5-config": "1.0.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/ejs": "3.1.5",
@@ -40,7 +41,7 @@
40
41
  "@types/mem-fs": "1.1.2",
41
42
  "fs-extra": "11.3.4",
42
43
  "@types/semver": "7.7.1",
43
- "@sap-ux/eslint-plugin-fiori-tools": "10.2.1"
44
+ "@sap-ux/eslint-plugin-fiori-tools": "10.4.0"
44
45
  },
45
46
  "scripts": {
46
47
  "build": "tsc --build",
@@ -49,8 +50,8 @@
49
50
  "format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
50
51
  "lint": "eslint",
51
52
  "lint:fix": "eslint --fix",
52
- "test": "jest --ci --forceExit --detectOpenHandles --colors",
53
- "test-u": "jest --ci --forceExit --detectOpenHandles --colors -u",
53
+ "test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --ci --forceExit --detectOpenHandles --colors",
54
+ "test-u": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --ci --forceExit --detectOpenHandles --colors -u",
54
55
  "link": "pnpm link --global",
55
56
  "unlink": "pnpm unlink --global"
56
57
  }