@sap-ux/create 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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @sap-ux/create
2
+ Module which provides command line interface to configure features for SAP UX projects or applications.
3
+
4
+ To see usage, run
5
+
6
+ ```
7
+ npm init @sap-ux
8
+ ```
9
+
10
+ To avoid downloading and installing the module every time it is used, you might consider installing it globally or add it as `devDependency` to a project. Once installed, you can run it using
11
+
12
+ ```
13
+ npx sap-ux
14
+ ```
@@ -0,0 +1,8 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Return 'create-fiori add *' commands. Commands include also the handler action.
4
+ *
5
+ * @returns - commander command containing add <feature> commands
6
+ */
7
+ export declare function getAddCommands(): Command;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAddCommands = void 0;
4
+ const commander_1 = require("commander");
5
+ const mockserver_config_1 = require("./mockserver-config");
6
+ /**
7
+ * Return 'create-fiori add *' commands. Commands include also the handler action.
8
+ *
9
+ * @returns - commander command containing add <feature> commands
10
+ */
11
+ function getAddCommands() {
12
+ const addCommands = new commander_1.Command('add');
13
+ // create-fiori add mockserver-config
14
+ mockserver_config_1.addAddMockserverConfigCommand(addCommands);
15
+ return addCommands;
16
+ }
17
+ exports.getAddCommands = getAddCommands;
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * Add the "add mockserver config" command to a passed command.
4
+ *
5
+ * @param cmd - commander command for adding mockserver config command
6
+ */
7
+ export declare function addAddMockserverConfigCommand(cmd: Command): void;
8
+ //# sourceMappingURL=mockserver-config.d.ts.map
@@ -0,0 +1,97 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addAddMockserverConfigCommand = void 0;
13
+ const child_process_1 = require("child_process");
14
+ const prompts_1 = require("prompts");
15
+ const project_access_1 = require("@sap-ux/project-access");
16
+ const mockserver_config_writer_1 = require("@sap-ux/mockserver-config-writer");
17
+ const tracing_1 = require("../../tracing");
18
+ const validation_1 = require("../../validation");
19
+ const path_1 = require("path");
20
+ /**
21
+ * Add the "add mockserver config" command to a passed command.
22
+ *
23
+ * @param cmd - commander command for adding mockserver config command
24
+ */
25
+ function addAddMockserverConfigCommand(cmd) {
26
+ cmd.command('mockserver-config [path]')
27
+ .option('-i, --interactive', 'ask for config options, otherwise use defaults')
28
+ .option('-n, --skip-install', 'skip npm install step')
29
+ .option('-s, --simulate', 'simulate only do not write or install; sets also --verbose')
30
+ .option('-v, --verbose', 'show verbose information')
31
+ .action((path, options) => __awaiter(this, void 0, void 0, function* () {
32
+ if (options.verbose === true || options.simulate) {
33
+ tracing_1.setLogLevelVerbose();
34
+ }
35
+ yield addMockserverConfig(path || process.cwd(), !!options.simulate, !!options.skipInstall, !!options.interactive);
36
+ }));
37
+ }
38
+ exports.addAddMockserverConfigCommand = addAddMockserverConfigCommand;
39
+ /**
40
+ * Adds a mockserver config to an app or project.
41
+ *
42
+ * @param basePath - path to application root
43
+ * @param simulate - if true, do not write but just show what would be change; otherwise write
44
+ * @param skipInstall - if true, skip execution of npm install
45
+ * @param interactive - if true, prompt user for config options, otherwise use defaults
46
+ */
47
+ function addMockserverConfig(basePath, simulate, skipInstall, interactive) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const logger = tracing_1.getLogger();
50
+ try {
51
+ logger.debug(`Called add mockserver-config for path '${basePath}', simulate is '${simulate}', skip install is '${skipInstall}'`);
52
+ validation_1.validateBasePath(basePath);
53
+ const webappPath = yield project_access_1.getWebappPath(basePath);
54
+ const config = { webappPath };
55
+ if (interactive) {
56
+ const questions = mockserver_config_writer_1.getMockserverConfigQuestions({ webappPath });
57
+ config.ui5MockYamlConfig = yield prompts_1.prompt(questions);
58
+ }
59
+ const fs = yield mockserver_config_writer_1.generateMockserverConfig(basePath, config);
60
+ yield tracing_1.traceChanges(fs);
61
+ if (!simulate) {
62
+ fs.commit(() => {
63
+ logger.info(`Changes written.`);
64
+ if (skipInstall) {
65
+ logger.warn('To finish mockserver configuration run commands:');
66
+ const relPath = path_1.relative(basePath, process.cwd());
67
+ if (relPath) {
68
+ logger.info(`cd ${relPath}`);
69
+ }
70
+ logger.info('npm install -D @sap-ux/ui5-middleware-fe-mockserver');
71
+ }
72
+ else {
73
+ logger.debug('Running npm install command');
74
+ runNpmInstall(basePath);
75
+ }
76
+ });
77
+ }
78
+ }
79
+ catch (error) {
80
+ logger.error(`Error while executing add mockserver-config '${error.message}'`);
81
+ logger.debug(error);
82
+ }
83
+ });
84
+ }
85
+ /**
86
+ * Run npm install for mockserver middleware in the root folder of application.
87
+ *
88
+ * @param basePath - path to application root
89
+ */
90
+ function runNpmInstall(basePath) {
91
+ const npmCommand = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
92
+ child_process_1.spawnSync(npmCommand, ['install', '--save-dev', '@sap-ux/ui5-middleware-fe-mockserver'], {
93
+ cwd: basePath,
94
+ stdio: [0, 1, 2]
95
+ });
96
+ }
97
+ //# sourceMappingURL=mockserver-config.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Run the command line interface.
3
+ *
4
+ * @param argv - arguments, typically 'process.argv'
5
+ */
6
+ export declare function handleCreateFioriCommand(argv: string[]): void;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleCreateFioriCommand = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const commander_1 = require("commander");
7
+ const tracing_1 = require("../tracing");
8
+ const add_1 = require("./add");
9
+ const remove_1 = require("./remove");
10
+ /*
11
+ * We've chosen 'commander' over 'minimist' and 'yargs' for this CLI implementation. Reasons:
12
+ * (if it still up: https://npmtrends.com/commander-vs-minimist-vs-yargs)
13
+ * At the time this was written in August 2022, 'commander' was the most feature rich, active, and popular module with decent size and built-in types support
14
+ * - 'minimist' is super small but very limited functionality, no automatic help support
15
+ * - 'yarg' was in closer consideration, but larger (1.7 times) and not as feature rich
16
+ */
17
+ /**
18
+ * Run the command line interface.
19
+ *
20
+ * @param argv - arguments, typically 'process.argv'
21
+ */
22
+ function handleCreateFioriCommand(argv) {
23
+ const logger = tracing_1.getLogger();
24
+ if (!Array.isArray(argv) || argv.length < 2) {
25
+ throw Error(`This function must be called from command line interface (cli). Or provide meaningful arguments.`);
26
+ }
27
+ try {
28
+ const program = getCommanderProgram();
29
+ program.parse(argv);
30
+ }
31
+ catch (error) {
32
+ logger.error(`Error while executing ${argv[0]} ${argv[1]}`);
33
+ logger.error(error);
34
+ }
35
+ }
36
+ exports.handleCreateFioriCommand = handleCreateFioriCommand;
37
+ /**
38
+ * Returns an instance of the command line program (commander command) ready to be executed (parsed), like 'program.parse(argv)'.
39
+ *
40
+ * @returns - commander program
41
+ */
42
+ function getCommanderProgram() {
43
+ const program = new commander_1.Command();
44
+ const version = getVersion();
45
+ program.description(`Configure features for Fiori applications and projects. (${version})`);
46
+ program.version(version);
47
+ // Handler for create-fiori add <feature> ..
48
+ program.addCommand(add_1.getAddCommands());
49
+ // Handler for create-fiori remove <feature> ..
50
+ program.addCommand(remove_1.getRemoveCommands());
51
+ return program;
52
+ }
53
+ /**
54
+ * Return the version from package.json.
55
+ *
56
+ * @returns - version from package.json
57
+ */
58
+ function getVersion() {
59
+ let version = '';
60
+ try {
61
+ version = JSON.parse(fs_1.readFileSync(path_1.join(__dirname, '../../package.json'), { encoding: 'utf8' }).toString()).version;
62
+ }
63
+ catch (error) {
64
+ const logger = tracing_1.getLogger();
65
+ logger.warn(`Could not read version from 'package.json'`);
66
+ logger.debug(error);
67
+ }
68
+ return version;
69
+ }
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Return 'create-fiori remove *' commands. Commands include also the handler action.
4
+ *
5
+ * @returns - commander command containing remove <feature> commands
6
+ */
7
+ export declare function getRemoveCommands(): Command;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRemoveCommands = void 0;
4
+ const commander_1 = require("commander");
5
+ const mockserver_config_1 = require("./mockserver-config");
6
+ /**
7
+ * Return 'create-fiori remove *' commands. Commands include also the handler action.
8
+ *
9
+ * @returns - commander command containing remove <feature> commands
10
+ */
11
+ function getRemoveCommands() {
12
+ const removeCommands = new commander_1.Command('remove');
13
+ // create-fiori remove mockserver-config
14
+ mockserver_config_1.addRemoveMockserverConfigCommand(removeCommands);
15
+ return removeCommands;
16
+ }
17
+ exports.getRemoveCommands = getRemoveCommands;
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * Add the "add mockserver config" command to a passed command.
4
+ *
5
+ * @param cmd - commander command for adding mockserver config command
6
+ */
7
+ export declare function addRemoveMockserverConfigCommand(cmd: Command): void;
8
+ //# sourceMappingURL=mockserver-config.d.ts.map
@@ -0,0 +1,74 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.addRemoveMockserverConfigCommand = void 0;
16
+ const prompts_1 = __importDefault(require("prompts"));
17
+ const mockserver_config_writer_1 = require("@sap-ux/mockserver-config-writer");
18
+ const tracing_1 = require("../../tracing");
19
+ const validation_1 = require("../../validation");
20
+ /**
21
+ * Add the "add mockserver config" command to a passed command.
22
+ *
23
+ * @param cmd - commander command for adding mockserver config command
24
+ */
25
+ function addRemoveMockserverConfigCommand(cmd) {
26
+ cmd.command('mockserver-config [path]')
27
+ .option('-v, --verbose', 'show verbose information')
28
+ .option('-f, --force', 'do not ask for confirmation when deleting files')
29
+ .action((path, options) => __awaiter(this, void 0, void 0, function* () {
30
+ if (options.verbose === true) {
31
+ tracing_1.setLogLevelVerbose();
32
+ }
33
+ yield removeMockserverConfiguration(path || process.cwd(), !!options.force);
34
+ }));
35
+ }
36
+ exports.addRemoveMockserverConfigCommand = addRemoveMockserverConfigCommand;
37
+ /**
38
+ * Removes a mockserver config from an app or project.
39
+ *
40
+ * @param basePath - path to application root
41
+ * @param force - if true, do not ask before deleting files; otherwise ask
42
+ */
43
+ function removeMockserverConfiguration(basePath, force) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const logger = tracing_1.getLogger();
46
+ try {
47
+ logger.debug(`Called remove mockserver-config for path '${basePath}', force is '${force}'`);
48
+ validation_1.validateBasePath(basePath);
49
+ const fs = mockserver_config_writer_1.removeMockserverConfig(basePath);
50
+ yield tracing_1.traceChanges(fs);
51
+ const hasDeletions = validation_1.hasFileDeletes(fs);
52
+ let doCommit = true;
53
+ if (hasDeletions && !force) {
54
+ doCommit = (yield prompts_1.default([
55
+ {
56
+ type: 'confirm',
57
+ name: 'doCommit',
58
+ message: `Do you want to apply the changes?`
59
+ }
60
+ ])).doCommit;
61
+ }
62
+ if (doCommit) {
63
+ fs.commit(() => {
64
+ logger.info(`Mockserver config removed`);
65
+ });
66
+ }
67
+ }
68
+ catch (error) {
69
+ logger.error(`Error while executing remove mockserver-config '${error.message}'`);
70
+ logger.debug(error);
71
+ }
72
+ });
73
+ }
74
+ //# sourceMappingURL=mockserver-config.js.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cli_1 = require("./cli");
5
+ cli_1.handleCreateFioriCommand(process.argv);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Compare two json files.
3
+ *
4
+ * @param a - First object to compare
5
+ * @param b - Second object to compare
6
+ */
7
+ export declare function compareJson(a: object, b: object): void;
8
+ /**
9
+ * Compare two strings.
10
+ *
11
+ * @param a - First object to compare
12
+ * @param b - Second object to compare
13
+ */
14
+ export declare function compareStrings(a: string, b: string): void;
15
+ //# sourceMappingURL=compare.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareStrings = exports.compareJson = void 0;
4
+ const diff_1 = require("diff");
5
+ const chalk_1 = require("chalk");
6
+ const logger_1 = require("./logger");
7
+ /**
8
+ * Compare two json files.
9
+ *
10
+ * @param a - First object to compare
11
+ * @param b - Second object to compare
12
+ */
13
+ function compareJson(a, b) {
14
+ const logger = logger_1.getLogger();
15
+ const diffChanges = diff_1.diffJson(a, b);
16
+ const diffResultString = getDiffResultString(diffChanges);
17
+ logger.debug(`File changes:\n${diffResultString}`);
18
+ }
19
+ exports.compareJson = compareJson;
20
+ /**
21
+ * Compare two strings.
22
+ *
23
+ * @param a - First object to compare
24
+ * @param b - Second object to compare
25
+ */
26
+ function compareStrings(a, b) {
27
+ const logger = logger_1.getLogger();
28
+ const diffChanges = diff_1.diffTrimmedLines(a, b);
29
+ const diffResultString = getDiffResultString(diffChanges);
30
+ logger.debug(`File changes:\n${diffResultString}`);
31
+ }
32
+ exports.compareStrings = compareStrings;
33
+ /**
34
+ * Get the diff results as colored string.
35
+ *
36
+ * @param diffChanges - array of changes, result from diff
37
+ * @returns - diff results as colored string
38
+ */
39
+ function getDiffResultString(diffChanges) {
40
+ let diffResults = '';
41
+ for (const diffChange of diffChanges) {
42
+ if (diffChange.added) {
43
+ diffResults += chalk_1.green(diffChange.value);
44
+ }
45
+ else if (diffChange.removed) {
46
+ diffResults += chalk_1.red(diffChange.value);
47
+ }
48
+ else {
49
+ diffResults += chalk_1.grey(diffChange.value);
50
+ }
51
+ }
52
+ return diffResults;
53
+ }
54
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1,3 @@
1
+ export { traceChanges } from './trace';
2
+ export { getLogger, setLogLevelVerbose } from './logger';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setLogLevelVerbose = exports.getLogger = exports.traceChanges = void 0;
4
+ var trace_1 = require("./trace");
5
+ Object.defineProperty(exports, "traceChanges", { enumerable: true, get: function () { return trace_1.traceChanges; } });
6
+ var logger_1 = require("./logger");
7
+ Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return logger_1.getLogger; } });
8
+ Object.defineProperty(exports, "setLogLevelVerbose", { enumerable: true, get: function () { return logger_1.setLogLevelVerbose; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ import { ToolsLogger } from '@sap-ux/logger';
2
+ /**
3
+ * Return the logger.
4
+ *
5
+ * @returns - Logger
6
+ */
7
+ export declare function getLogger(): ToolsLogger;
8
+ /**
9
+ * Set the log level to verbose (debug).
10
+ */
11
+ export declare function setLogLevelVerbose(): void;
12
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,68 @@
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.setLogLevelVerbose = exports.getLogger = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const logger_1 = require("@sap-ux/logger");
9
+ const levelColor = {
10
+ warn: 'yellow',
11
+ error: 'red',
12
+ verbose: 'blue',
13
+ debug: 'gray'
14
+ };
15
+ let logger;
16
+ /**
17
+ * Return the logger.
18
+ *
19
+ * @returns - Logger
20
+ */
21
+ function getLogger() {
22
+ if (!logger) {
23
+ logger = new logger_1.ToolsLogger({ transports: [new logger_1.ConsoleTransport()], logPrefix: '' });
24
+ setCustomFormatter(logger);
25
+ }
26
+ return logger;
27
+ }
28
+ exports.getLogger = getLogger;
29
+ /**
30
+ * Set custom formatting to the logger. Needs better solution, perhaps proxy transport in @sap-ux/logger.
31
+ *
32
+ * @param logger - instance of the logger
33
+ */
34
+ function setCustomFormatter(logger) {
35
+ var _a, _b;
36
+ const transports = (_b = (_a = logger) === null || _a === void 0 ? void 0 : _a._logger) === null || _b === void 0 ? void 0 : _b.transports;
37
+ if (!Array.isArray(transports)) {
38
+ return;
39
+ }
40
+ const consoleTransport = transports.find((t) => (t === null || t === void 0 ? void 0 : t.name) === 'console');
41
+ if (consoleTransport === null || consoleTransport === void 0 ? void 0 : consoleTransport.format) {
42
+ consoleTransport.format.transform = (info) => {
43
+ const colorFn = levelColor[info.level] ? chalk_1.default.keyword(levelColor[info.level]) : (m) => m;
44
+ const formattedMessage = colorFn ? colorFn(info.message) : info.message;
45
+ const symbol = Object.getOwnPropertySymbols(info).find((s) => (s === null || s === void 0 ? void 0 : s.description) === 'message');
46
+ if (symbol) {
47
+ info[symbol] = formattedMessage;
48
+ }
49
+ return info;
50
+ };
51
+ }
52
+ }
53
+ /**
54
+ * Initialize the logger with a certain log level.
55
+ *
56
+ * @param logLevel - see @sap-ux/logger -> LogLevel
57
+ */
58
+ function updateLogLevel(logLevel) {
59
+ logger = new logger_1.ToolsLogger({ logLevel, transports: [new logger_1.ConsoleTransport()], logPrefix: '' });
60
+ }
61
+ /**
62
+ * Set the log level to verbose (debug).
63
+ */
64
+ function setLogLevelVerbose() {
65
+ updateLogLevel(logger_1.LogLevel.Debug);
66
+ }
67
+ exports.setLogLevelVerbose = setLogLevelVerbose;
68
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,8 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ /**
3
+ * Compare changes from mem-fs-editor and write to logger.
4
+ *
5
+ * @param fs - mem-fs-editor
6
+ */
7
+ export declare function traceChanges(fs: Editor): Promise<void>;
8
+ //# sourceMappingURL=trace.d.ts.map
@@ -0,0 +1,62 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.traceChanges = void 0;
13
+ const fs_1 = require("fs");
14
+ const path_1 = require("path");
15
+ const compare_1 = require("./compare");
16
+ const logger_1 = require("./logger");
17
+ /**
18
+ * Compare changes from mem-fs-editor and write to logger.
19
+ *
20
+ * @param fs - mem-fs-editor
21
+ */
22
+ function traceChanges(fs) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const changedFiles = fs.dump() || {};
25
+ const logger = logger_1.getLogger();
26
+ for (const changedFile in changedFiles) {
27
+ const fileStat = changedFiles[changedFile];
28
+ if (fileStat.state === 'deleted') {
29
+ logger.info(`File '${changedFile}' ${fileStat.state}`);
30
+ continue;
31
+ }
32
+ const memContent = fileStat.contents;
33
+ if (!fs_1.existsSync(changedFile)) {
34
+ logger.info(`File '${changedFile}' added`);
35
+ logger.debug(`File content:\n${memContent}`);
36
+ continue;
37
+ }
38
+ const discContent = yield fs_1.promises.readFile(changedFile, 'utf-8');
39
+ if (discContent === memContent) {
40
+ logger.info(`File '${changedFile}' unchanged`);
41
+ logger.debug(`File content:\n${memContent}`);
42
+ continue;
43
+ }
44
+ logger.info(`File '${changedFile}' modified`);
45
+ const fileExtension = path_1.extname(changedFile).toLowerCase();
46
+ switch (fileExtension) {
47
+ case '.json': {
48
+ compare_1.compareJson(JSON.parse(discContent), JSON.parse(memContent));
49
+ break;
50
+ }
51
+ case '.yaml': {
52
+ compare_1.compareStrings(discContent, memContent);
53
+ break;
54
+ }
55
+ default:
56
+ logger.debug(`Can't compare file. New file content:\n${memContent}`);
57
+ }
58
+ }
59
+ });
60
+ }
61
+ exports.traceChanges = traceChanges;
62
+ //# sourceMappingURL=trace.js.map
@@ -0,0 +1,2 @@
1
+ export { hasFileDeletes, validateBasePath } from './validation';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateBasePath = exports.hasFileDeletes = void 0;
4
+ var validation_1 = require("./validation");
5
+ Object.defineProperty(exports, "hasFileDeletes", { enumerable: true, get: function () { return validation_1.hasFileDeletes; } });
6
+ Object.defineProperty(exports, "validateBasePath", { enumerable: true, get: function () { return validation_1.validateBasePath; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ /**
3
+ * Validate base path of app, throw error if file is missing.
4
+ *
5
+ * @param basePath - base path of the app, where package.json and ui5.yaml resides
6
+ */
7
+ export declare function validateBasePath(basePath: string): void;
8
+ /**
9
+ * Return if an instance of mem-fs editor recorded any deletion.
10
+ *
11
+ * @param fs - the memfs editor instance
12
+ * @returns - true if fs contains deletions; false otherwise
13
+ */
14
+ export declare function hasFileDeletes(fs: Editor): boolean;
15
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasFileDeletes = exports.validateBasePath = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Validate base path of app, throw error if file is missing.
8
+ *
9
+ * @param basePath - base path of the app, where package.json and ui5.yaml resides
10
+ */
11
+ function validateBasePath(basePath) {
12
+ const packageJsonPath = path_1.join(basePath, 'package.json');
13
+ if (!fs_1.existsSync(packageJsonPath)) {
14
+ throw Error(`Required file '${packageJsonPath}' does not exist.`);
15
+ }
16
+ const ui5YamlPath = path_1.join(basePath, 'ui5.yaml');
17
+ const webappPath = path_1.join(basePath, 'webapp');
18
+ if (!fs_1.existsSync(ui5YamlPath) && !fs_1.existsSync(webappPath)) {
19
+ throw Error(`There must be either a folder '${webappPath}' or a config file '${ui5YamlPath}'`);
20
+ }
21
+ }
22
+ exports.validateBasePath = validateBasePath;
23
+ /**
24
+ * Return if an instance of mem-fs editor recorded any deletion.
25
+ *
26
+ * @param fs - the memfs editor instance
27
+ * @returns - true if fs contains deletions; false otherwise
28
+ */
29
+ function hasFileDeletes(fs) {
30
+ const changedFiles = fs.dump() || {};
31
+ return !!Object.keys(changedFiles).find((fileName) => changedFiles[fileName].state === 'deleted');
32
+ }
33
+ exports.hasFileDeletes = hasFileDeletes;
34
+ //# sourceMappingURL=validation.js.map
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@sap-ux/create",
3
+ "description": "SAP Fiori tools module to add or remove features",
4
+ "version": "0.0.2",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/SAP/open-ux-tools.git",
8
+ "directory": "packages/create"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Acreate"
12
+ },
13
+ "license": "Apache-2.0",
14
+ "bin": {
15
+ "sap-ux": "./dist/index.js"
16
+ },
17
+ "engines": {
18
+ "pnpm": ">=6.26.1 < 7.0.0 || >=7.1.0",
19
+ "node": ">= 14.16.0 < 15.0.0 || >=16.1.0 < 17.0.0 || >=18.0.0 < 19.0.0"
20
+ },
21
+ "files": [
22
+ "LICENSE",
23
+ "dist",
24
+ "!dist/*.map",
25
+ "!dist/**/*.map"
26
+ ],
27
+ "dependencies": {
28
+ "@sap-ux/logger": "0.3.2",
29
+ "@sap-ux/mockserver-config-writer": "0.0.2",
30
+ "@sap-ux/project-access": "1.0.4",
31
+ "chalk": "4.1.2",
32
+ "commander": "9.4.0",
33
+ "diff": "5.1.0",
34
+ "prompts": "2.4.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/diff": "5.0.2",
38
+ "@types/mem-fs-editor": "7.0.1",
39
+ "@types/prompts": "2.0.14"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc --build",
43
+ "clean": "rimraf dist coverage *.tsbuildinfo",
44
+ "format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
45
+ "lint": "eslint . --ext .ts",
46
+ "lint:fix": "eslint . --ext .ts --fix",
47
+ "test": "jest --ci --forceExit --detectOpenHandles --colors",
48
+ "watch": "tsc --watch"
49
+ }
50
+ }