@sap-ux/ui5-library-sub-generator 0.0.1 → 0.0.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.
@@ -0,0 +1,6 @@
1
+ export declare const defaultLibraryName = "library1";
2
+ export declare const defaultNamespace = "com.myorg";
3
+ export declare const defaultFramework = "SAPUI5";
4
+ export declare const defaultUi5Version = "1.79.0";
5
+ export declare const defaultAuthor = "Fiori tools";
6
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultAuthor = exports.defaultUi5Version = exports.defaultFramework = exports.defaultNamespace = exports.defaultLibraryName = void 0;
4
+ const ui5_info_1 = require("@sap-ux/ui5-info");
5
+ // Default values for the UI5 library writer
6
+ exports.defaultLibraryName = 'library1';
7
+ exports.defaultNamespace = 'com.myorg';
8
+ exports.defaultFramework = 'SAPUI5';
9
+ exports.defaultUi5Version = ui5_info_1.minUI5VersionForLocalDev;
10
+ exports.defaultAuthor = 'Fiori tools';
11
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1,30 @@
1
+ import Generator from 'yeoman-generator';
2
+ import { AppWizard, Prompts } from '@sap-devx/yeoman-ui-types';
3
+ import { type UI5LibraryAnswers } from '@sap-ux/ui5-library-inquirer';
4
+ import type { Ui5LibGenerator } from './types';
5
+ /**
6
+ * Generator for creating a new UI5 library.
7
+ *
8
+ * @extends Generator
9
+ */
10
+ export default class extends Generator implements Ui5LibGenerator {
11
+ answers: UI5LibraryAnswers;
12
+ prompts: Prompts;
13
+ appWizard: AppWizard;
14
+ targetFolder: string;
15
+ vscode: unknown;
16
+ projectPath: string;
17
+ setPromptsCallback: (fn: any) => void;
18
+ /**
19
+ * Constructor for the generator.
20
+ *
21
+ * @param args - arguments passed to the generator
22
+ * @param opts - options passed to the generator
23
+ */
24
+ constructor(args: string | string[], opts: Generator.GeneratorOptions);
25
+ prompting(): Promise<void>;
26
+ writing(): Promise<void>;
27
+ install(): Promise<void>;
28
+ end(): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,111 @@
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
+ const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
7
+ const yeoman_ui_types_1 = require("@sap-devx/yeoman-ui-types");
8
+ const path_1 = require("path");
9
+ const logger_1 = __importDefault(require("../utils/logger"));
10
+ const utils_1 = require("../utils");
11
+ const fiori_tools_settings_1 = require("@sap-ux/fiori-tools-settings");
12
+ const os_1 = require("os");
13
+ const nodejs_utils_1 = require("@sap-ux/nodejs-utils");
14
+ const defaults_1 = require("./defaults");
15
+ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
16
+ const ui5_library_writer_1 = require("@sap-ux/ui5-library-writer");
17
+ const ui5_library_inquirer_1 = require("@sap-ux/ui5-library-inquirer");
18
+ /**
19
+ * Generator for creating a new UI5 library.
20
+ *
21
+ * @extends Generator
22
+ */
23
+ class default_1 extends yeoman_generator_1.default {
24
+ answers = {};
25
+ prompts;
26
+ appWizard;
27
+ targetFolder;
28
+ vscode;
29
+ projectPath;
30
+ setPromptsCallback;
31
+ /**
32
+ * Constructor for the generator.
33
+ *
34
+ * @param args - arguments passed to the generator
35
+ * @param opts - options passed to the generator
36
+ */
37
+ constructor(args, opts) {
38
+ super(args, opts);
39
+ this.appWizard = yeoman_ui_types_1.AppWizard.create(opts);
40
+ this.vscode = opts.vscode;
41
+ logger_1.default.configureLogging(this.options.logger, this.rootGeneratorName(), this.log, this.options.vscode, this.options.logLevel);
42
+ this.targetFolder = (0, fiori_generator_shared_1.getDefaultTargetFolder)(this.options.vscode) ?? process.cwd();
43
+ this.appWizard.setHeaderTitle(utils_1.generatorTitle);
44
+ this.prompts = new yeoman_ui_types_1.Prompts(utils_1.prompts);
45
+ this.setPromptsCallback = (fn) => {
46
+ if (this.prompts) {
47
+ this.prompts.setCallback(fn);
48
+ }
49
+ };
50
+ }
51
+ async prompting() {
52
+ const promptCli = (0, fiori_generator_shared_1.isCli)();
53
+ let inquirerAdaptor;
54
+ if (this.env?.adapter?.actualAdapter) {
55
+ inquirerAdaptor = this.env.adapter.actualAdapter;
56
+ }
57
+ else {
58
+ inquirerAdaptor = this.env?.adapter;
59
+ }
60
+ const answers = await (0, ui5_library_inquirer_1.prompt)({
61
+ targetFolder: this.targetFolder,
62
+ includeSeparators: !promptCli,
63
+ useAutocomplete: promptCli
64
+ }, inquirerAdaptor);
65
+ Object.assign(this.answers, answers);
66
+ }
67
+ async writing() {
68
+ const ui5Lib = {
69
+ libraryName: this.answers.libraryName ?? defaults_1.defaultLibraryName,
70
+ namespace: this.answers.namespace ?? defaults_1.defaultNamespace,
71
+ framework: defaults_1.defaultFramework,
72
+ frameworkVersion: this.answers.ui5Version ?? defaults_1.defaultUi5Version,
73
+ author: defaults_1.defaultAuthor,
74
+ typescript: this.answers.enableTypescript
75
+ };
76
+ if (this.answers.targetFolder) {
77
+ this.targetFolder = this.answers.targetFolder;
78
+ }
79
+ try {
80
+ await (0, ui5_library_writer_1.generate)(this.targetFolder, ui5Lib, this.fs);
81
+ }
82
+ catch (e) {
83
+ logger_1.default.logger.error(e);
84
+ throw new Error((0, utils_1.t)('error.generatingUi5Lib'));
85
+ }
86
+ }
87
+ async install() {
88
+ if (!this.options.skipInstall) {
89
+ try {
90
+ const runner = new nodejs_utils_1.CommandRunner();
91
+ const npm = (0, os_1.platform)() === 'win32' ? 'npm.cmd' : 'npm';
92
+ logger_1.default.logger.info((0, utils_1.t)('info.installingDependencies'));
93
+ this.projectPath = (0, path_1.join)(this.targetFolder, `${this.answers.namespace}.${this.answers.libraryName}`);
94
+ await runner.run(npm, ['install'], { cwd: this.projectPath });
95
+ logger_1.default.logger.info((0, utils_1.t)('info.dependenciesInstalled'));
96
+ }
97
+ catch (error) {
98
+ logger_1.default.logger.error(error || (0, utils_1.t)('error.unknown'));
99
+ }
100
+ }
101
+ }
102
+ async end() {
103
+ (0, fiori_tools_settings_1.writeApplicationInfoSettings)(this.projectPath, this.fs);
104
+ await (0, utils_1.runPostLibGenHook)({
105
+ path: this.projectPath,
106
+ vscodeInstance: this.vscode
107
+ });
108
+ }
109
+ }
110
+ exports.default = default_1;
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import type { Prompts, AppWizard } from '@sap-devx/yeoman-ui-types';
2
+ import type { UI5LibraryAnswers } from '@sap-ux/ui5-library-inquirer';
3
+ export interface Ui5LibGenerator {
4
+ appWizard: AppWizard;
5
+ answers: UI5LibraryAnswers;
6
+ prompts: Prompts;
7
+ }
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "info": {
3
+ "installingDependencies": "Installing dependencies...",
4
+ "dependenciesInstalled": "Library dependencies have been installed."
5
+ },
6
+ "error": {
7
+ "unknown": "Unknown error",
8
+ "generatingUi5Lib": "Error generating reusable UI5 library",
9
+ "postLibGenHook": "Failed to run hook after library generation {{- error}}"
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ export declare const UI5_LIB_GEN = "UI5_LIB_GEN";
2
+ export declare const generatorTitle = "SAP Fiori Reusable Library";
3
+ export declare const prompts: {
4
+ name: string;
5
+ description: string;
6
+ }[];
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prompts = exports.generatorTitle = exports.UI5_LIB_GEN = void 0;
4
+ exports.UI5_LIB_GEN = 'UI5_LIB_GEN';
5
+ exports.generatorTitle = 'SAP Fiori Reusable Library';
6
+ exports.prompts = [
7
+ {
8
+ name: 'Generate UI5 Library',
9
+ description: 'Create a Reusable Library for use in SAP Fiori applications'
10
+ }
11
+ ];
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,13 @@
1
+ import type { VSCodeInstance } from '@sap-ux/fiori-generator-shared';
2
+ export interface LibContext {
3
+ path: string;
4
+ vscodeInstance?: VSCodeInstance;
5
+ }
6
+ export declare const POST_LIB_GEN_COMMAND = "sap.ux.library.generated.handler";
7
+ /**
8
+ * Executes post library generation command : 'sap.ux.library.generated.handler'.
9
+ *
10
+ * @param context LibContext
11
+ */
12
+ export declare function runPostLibGenHook(context: LibContext): Promise<void>;
13
+ //# sourceMappingURL=eventHook.d.ts.map
@@ -0,0 +1,26 @@
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.runPostLibGenHook = exports.POST_LIB_GEN_COMMAND = void 0;
7
+ const logger_1 = __importDefault(require("./logger"));
8
+ const i18n_1 = require("./i18n");
9
+ exports.POST_LIB_GEN_COMMAND = 'sap.ux.library.generated.handler';
10
+ /**
11
+ * Executes post library generation command : 'sap.ux.library.generated.handler'.
12
+ *
13
+ * @param context LibContext
14
+ */
15
+ async function runPostLibGenHook(context) {
16
+ try {
17
+ await context.vscodeInstance?.commands?.executeCommand?.(exports.POST_LIB_GEN_COMMAND, {
18
+ fsPath: context.path
19
+ });
20
+ }
21
+ catch (e) {
22
+ logger_1.default.logger.error((0, i18n_1.t)('error.postLibGenHook', { error: e }));
23
+ }
24
+ }
25
+ exports.runPostLibGenHook = runPostLibGenHook;
26
+ //# sourceMappingURL=eventHook.js.map
@@ -0,0 +1,10 @@
1
+ import type { TOptions } from 'i18next';
2
+ /**
3
+ * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
4
+ *
5
+ * @param key i18n key
6
+ * @param options additional options
7
+ * @returns {string} localized string stored for the given key
8
+ */
9
+ export declare function t(key: string, options?: TOptions): string;
10
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1,33 @@
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 = void 0;
7
+ const i18next_1 = __importDefault(require("i18next"));
8
+ const ui5_lib_generator_i18n_json_1 = __importDefault(require("../translations/ui5-lib-generator.i18n.json"));
9
+ const ui5LibGeneratorNs = 'ui5-lib-generator';
10
+ /**
11
+ * Initialize i18next with the translations for this module.
12
+ */
13
+ async function initI18n() {
14
+ await i18next_1.default.init({ lng: 'en', fallbackLng: 'en' }, () => i18next_1.default.addResourceBundle('en', ui5LibGeneratorNs, ui5_lib_generator_i18n_json_1.default));
15
+ }
16
+ /**
17
+ * Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
18
+ *
19
+ * @param key i18n key
20
+ * @param options additional options
21
+ * @returns {string} localized string stored for the given key
22
+ */
23
+ function t(key, options) {
24
+ if (!options?.ns) {
25
+ options = Object.assign(options ?? {}, { ns: ui5LibGeneratorNs });
26
+ }
27
+ return i18next_1.default.t(key, options);
28
+ }
29
+ exports.t = t;
30
+ initI18n().catch(() => {
31
+ // Needed for lint
32
+ });
33
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1,4 @@
1
+ export * from './i18n';
2
+ export { prompts, generatorTitle } from './constants';
3
+ export { runPostLibGenHook } from './eventHook';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,24 @@
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
+ exports.runPostLibGenHook = exports.generatorTitle = exports.prompts = void 0;
18
+ __exportStar(require("./i18n"), exports);
19
+ var constants_1 = require("./constants");
20
+ Object.defineProperty(exports, "prompts", { enumerable: true, get: function () { return constants_1.prompts; } });
21
+ Object.defineProperty(exports, "generatorTitle", { enumerable: true, get: function () { return constants_1.generatorTitle; } });
22
+ var eventHook_1 = require("./eventHook");
23
+ Object.defineProperty(exports, "runPostLibGenHook", { enumerable: true, get: function () { return eventHook_1.runPostLibGenHook; } });
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,32 @@
1
+ import { type ILogWrapper } from '@sap-ux/fiori-generator-shared';
2
+ import type { Logger } from 'yeoman-environment';
3
+ import type { IVSCodeExtLogger, LogLevel } from '@vscode-logging/logger';
4
+ /**
5
+ * Static logger prevents passing of logger references through all functions, as this is a cross-cutting concern.
6
+ */
7
+ export default class ReuseLibGenLogger {
8
+ private static _logger;
9
+ /**
10
+ * Get the logger.
11
+ *
12
+ * @returns the logger
13
+ */
14
+ static get logger(): ILogWrapper;
15
+ /**
16
+ * Set the logger.
17
+ *
18
+ * @param value the logger to set
19
+ */
20
+ static set logger(value: ILogWrapper);
21
+ /**
22
+ * Configures the vscode logger.
23
+ *
24
+ * @param vscLogger - the vscode logger
25
+ * @param loggerName - the logger name
26
+ * @param yoLogger - the yeoman logger
27
+ * @param vscode - the vscode instance
28
+ * @param logLevel - the log level
29
+ */
30
+ static configureLogging(vscLogger: IVSCodeExtLogger, loggerName: string, yoLogger: Logger, vscode?: unknown, logLevel?: LogLevel): void;
31
+ }
32
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fiori_generator_shared_1 = require("@sap-ux/fiori-generator-shared");
4
+ /**
5
+ * Static logger prevents passing of logger references through all functions, as this is a cross-cutting concern.
6
+ */
7
+ class ReuseLibGenLogger {
8
+ static _logger = fiori_generator_shared_1.DefaultLogger;
9
+ /**
10
+ * Get the logger.
11
+ *
12
+ * @returns the logger
13
+ */
14
+ static get logger() {
15
+ return ReuseLibGenLogger._logger;
16
+ }
17
+ /**
18
+ * Set the logger.
19
+ *
20
+ * @param value the logger to set
21
+ */
22
+ static set logger(value) {
23
+ ReuseLibGenLogger._logger = value;
24
+ }
25
+ /**
26
+ * Configures the vscode logger.
27
+ *
28
+ * @param vscLogger - the vscode logger
29
+ * @param loggerName - the logger name
30
+ * @param yoLogger - the yeoman logger
31
+ * @param vscode - the vscode instance
32
+ * @param logLevel - the log level
33
+ */
34
+ static configureLogging(vscLogger, loggerName, yoLogger, vscode, logLevel) {
35
+ const logWrapper = new fiori_generator_shared_1.LogWrapper(loggerName, yoLogger, logLevel, vscLogger, vscode);
36
+ ReuseLibGenLogger.logger = logWrapper;
37
+ }
38
+ }
39
+ exports.default = ReuseLibGenLogger;
40
+ //# sourceMappingURL=logger.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/ui5-library-sub-generator",
3
3
  "description": "Generator for creating UI5 libraries",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -23,10 +23,10 @@
23
23
  "i18next": "23.5.1",
24
24
  "yeoman-generator": "5.10.0",
25
25
  "@sap-ux/fiori-generator-shared": "0.6.0",
26
- "@sap-ux/fiori-tools-settings": "0.1.0",
27
26
  "@sap-ux/nodejs-utils": "0.1.0",
28
- "@sap-ux/ui5-info": "0.8.1",
27
+ "@sap-ux/fiori-tools-settings": "0.1.0",
29
28
  "@sap-ux/ui5-library-inquirer": "0.3.7",
29
+ "@sap-ux/ui5-info": "0.8.1",
30
30
  "@sap-ux/ui5-library-writer": "0.5.22"
31
31
  },
32
32
  "devDependencies": {