powerbi-visuals-tools 4.3.2 → 5.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.
- package/Changelog.md +7 -0
- package/README.md +1 -1
- package/bin/pbiviz.js +55 -36
- package/certs/PowerBICustomVisualTest_private.key +26 -26
- package/certs/PowerBICustomVisualTest_public.crt +17 -17
- package/config.json +27 -34
- package/lib/CertificateTools.js +119 -143
- package/lib/CommandManager.js +52 -0
- package/lib/ConsoleWriter.js +63 -85
- package/lib/TemplateFetcher.js +23 -30
- package/lib/VisualGenerator.js +42 -56
- package/lib/VisualManager.js +193 -0
- package/lib/WebPackWrap.js +96 -145
- package/lib/utils.js +21 -13
- package/lib/webpack.config.js +47 -56
- package/package.json +34 -26
- package/spec/clean-tests.js +1 -1
- package/spec/e2e/pbivizCertSpec.js +14 -13
- package/spec/e2e/pbivizInfoSpec.js +7 -10
- package/spec/e2e/pbivizNewSpec.js +53 -65
- package/spec/e2e/pbivizPackageSpec.js +86 -90
- package/spec/e2e/pbivizStartSpec.js +6 -7
- package/spec/e2e/pbivizWebpackVerSpec.js +14 -16
- package/spec/e2e/{utils.js → testUtils.js} +9 -12
- package/spec/helpers/FileSystem.js +18 -18
- package/spec/jasmine-runner.js +5 -5
- package/src/CertificateTools.ts +431 -0
- package/src/CommandManager.ts +78 -0
- package/src/ConsoleWriter.ts +206 -0
- package/src/TemplateFetcher.ts +122 -0
- package/src/VisualGenerator.ts +236 -0
- package/src/VisualManager.ts +220 -0
- package/src/WebPackWrap.ts +299 -0
- package/src/utils.ts +41 -0
- package/src/webpack.config.ts +144 -0
- package/templates/pbiviz-json-template.js +2 -2
- package/templates/pbiviz.json.template +1 -1
- package/templates/plugin-ts-template.js +1 -1
- package/templates/visuals/default/.eslintignore +5 -0
- package/templates/visuals/default/.eslintrc.js +20 -0
- package/templates/visuals/default/package.json +9 -8
- package/templates/visuals/default/pbiviz.json +3 -2
- package/templates/visuals/default/tsconfig.json +2 -2
- package/templates/visuals/rhtml/.eslintignore +5 -0
- package/templates/visuals/rhtml/.eslintrc.js +20 -0
- package/templates/visuals/rhtml/package.json +7 -6
- package/templates/visuals/rhtml/pbiviz.json +2 -1
- package/templates/visuals/rvisual/.eslintignore +5 -0
- package/templates/visuals/rvisual/.eslintrc.js +20 -0
- package/templates/visuals/rvisual/package.json +5 -4
- package/templates/visuals/slicer/.eslintignore +5 -0
- package/templates/visuals/slicer/.eslintrc.js +20 -0
- package/templates/visuals/slicer/package.json +8 -7
- package/templates/visuals/table/.eslintignore +5 -0
- package/templates/visuals/table/.eslintrc.js +20 -0
- package/templates/visuals/table/package.json +8 -7
- package/templates/visuals/table/tsconfig.json +4 -0
- package/tsconfig.json +22 -0
- package/bin/pbiviz-info.js +0 -54
- package/bin/pbiviz-new.js +0 -82
- package/bin/pbiviz-package.js +0 -122
- package/bin/pbiviz-start.js +0 -142
- package/lib/CommandHelpManager.js +0 -51
- package/lib/VisualPackage.js +0 -118
- package/templates/visuals/default/tslint.json +0 -9
- package/templates/visuals/rhtml/tslint.json +0 -9
- package/templates/visuals/rvisual/tslint.json +0 -9
- package/templates/visuals/slicer/tslint.json +0 -9
- package/templates/visuals/table/tslint.json +0 -9
package/lib/CertificateTools.js
CHANGED
|
@@ -23,56 +23,56 @@
|
|
|
23
23
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
24
|
* THE SOFTWARE.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
26
|
"use strict";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
27
|
+
import { exec as nodeExec } from 'child_process';
|
|
28
|
+
import fs from 'fs-extra';
|
|
29
|
+
import os from 'os';
|
|
30
|
+
import path from 'path';
|
|
31
|
+
import crypto from "crypto";
|
|
32
|
+
import { getRootPath, readJsonFromRoot } from './utils.js';
|
|
33
|
+
import ConsoleWriter from './ConsoleWriter.js';
|
|
34
|
+
const certSafePeriod = 1000 * 60 * 60 * 24; // 24 hours
|
|
35
|
+
const rootPath = getRootPath();
|
|
36
|
+
const confPath = '/config.json';
|
|
38
37
|
function exec(command, callback) {
|
|
39
|
-
if (callback) {
|
|
40
|
-
return nodeExec(command, callback);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
return new Promise((resolve, reject) => {
|
|
44
|
-
nodeExec(command, (err, stdout, stderr) => {
|
|
39
|
+
nodeExec(command, callback ? callback : (err, stdout, stderr) => {
|
|
45
40
|
if (err) {
|
|
46
41
|
reject(stderr);
|
|
47
42
|
}
|
|
48
43
|
resolve(stdout);
|
|
49
44
|
});
|
|
50
45
|
});
|
|
51
|
-
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
export async function createCertificate() {
|
|
48
|
+
const config = readJsonFromRoot('config.json');
|
|
49
|
+
const certPath = await getCertFile(config, true);
|
|
50
|
+
if (!certPath) {
|
|
51
|
+
ConsoleWriter.error("Certificate not found. The new certificate will be generated");
|
|
52
|
+
await createCertFile(config, true);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
await openCertFile(config);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export async function createCertFile(config, open) {
|
|
55
59
|
ConsoleWriter.info(`Generating a new certificate...`);
|
|
56
60
|
const subject = "localhost";
|
|
57
61
|
const keyLength = 2048;
|
|
58
62
|
const algorithm = "sha256";
|
|
59
63
|
const validPeriod = 365;
|
|
60
|
-
|
|
61
64
|
if (typeof open === 'undefined') {
|
|
62
65
|
open = false;
|
|
63
66
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
let openCmds = {
|
|
67
|
+
const certPath = path.join(rootPath, config.server.certificate);
|
|
68
|
+
const keyPath = path.join(rootPath, config.server.privateKey);
|
|
69
|
+
const pfxPath = path.join(rootPath, config.server.pfx);
|
|
70
|
+
const openCmds = {
|
|
70
71
|
linux: 'openssl',
|
|
71
72
|
darwin: 'openssl',
|
|
72
73
|
win32: 'powershell'
|
|
73
74
|
};
|
|
74
75
|
let startCmd = openCmds[os.platform()];
|
|
75
|
-
|
|
76
76
|
if (startCmd) {
|
|
77
77
|
try {
|
|
78
78
|
let createCertCommand = "";
|
|
@@ -81,12 +81,12 @@ async function createCertFile(config, open) {
|
|
|
81
81
|
await removeCertFiles(certPath, keyPath);
|
|
82
82
|
createCertCommand =
|
|
83
83
|
` req -newkey rsa:${keyLength}` +
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
` -nodes` +
|
|
85
|
+
` -keyout ${keyPath}` +
|
|
86
|
+
` -x509 ` +
|
|
87
|
+
` -days ${validPeriod} ` +
|
|
88
|
+
` -out ${certPath} ` +
|
|
89
|
+
` -subj "/CN=${subject}"`;
|
|
90
90
|
await exec(`${startCmd} ${createCertCommand}`);
|
|
91
91
|
if (await fs.exists(certPath)) {
|
|
92
92
|
ConsoleWriter.info(`Certificate generated. Location is ${certPath}`);
|
|
@@ -99,12 +99,12 @@ async function createCertFile(config, open) {
|
|
|
99
99
|
await removeCertFiles(certPath, keyPath);
|
|
100
100
|
createCertCommand =
|
|
101
101
|
` req -newkey rsa:${keyLength}` +
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
` -nodes` +
|
|
103
|
+
` -keyout ${keyPath}` +
|
|
104
|
+
` -x509 ` +
|
|
105
|
+
` -days ${validPeriod} ` +
|
|
106
|
+
` -out ${certPath} ` +
|
|
107
|
+
` -subj "/CN=${subject}"`;
|
|
108
108
|
await exec(`${startCmd} ${createCertCommand}`);
|
|
109
109
|
if (await fs.exists(certPath)) {
|
|
110
110
|
ConsoleWriter.info(`Certificate generated. Location is ${certPath}`);
|
|
@@ -114,21 +114,23 @@ async function createCertFile(config, open) {
|
|
|
114
114
|
}
|
|
115
115
|
break;
|
|
116
116
|
case "win32":
|
|
117
|
+
// eslint-disable-next-line no-case-declarations
|
|
117
118
|
let passphrase = "";
|
|
118
119
|
// for windows 7 and others
|
|
119
120
|
// 6.1 - Windows 7
|
|
120
|
-
|
|
121
|
+
// eslint-disable-next-line no-case-declarations
|
|
122
|
+
const osVersion = os.release().split(".");
|
|
121
123
|
if ((Number(osVersion[0]) === 6 && Number(osVersion[1]) === 1) || Number(osVersion[0]) < 6) {
|
|
122
124
|
await removeCertFiles(certPath, keyPath, pfxPath);
|
|
123
125
|
startCmd = "openssl";
|
|
124
126
|
createCertCommand =
|
|
125
127
|
` req -newkey rsa:${keyLength}` +
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
` -nodes` +
|
|
129
|
+
` -keyout ${keyPath}` +
|
|
130
|
+
` -x509 ` +
|
|
131
|
+
` -days ${validPeriod} ` +
|
|
132
|
+
` -out ${certPath} ` +
|
|
133
|
+
` -subj "/CN=${subject}"`;
|
|
132
134
|
await exec(`${startCmd} ${createCertCommand}`);
|
|
133
135
|
if (await fs.exists(certPath)) {
|
|
134
136
|
ConsoleWriter.info(`Certificate generated. Location is ${certPath}`);
|
|
@@ -138,13 +140,12 @@ async function createCertFile(config, open) {
|
|
|
138
140
|
}
|
|
139
141
|
break;
|
|
140
142
|
}
|
|
143
|
+
passphrase = crypto.getRandomValues(new Uint32Array(1))[0].toString().substring(2);
|
|
144
|
+
config.server.passphrase = passphrase;
|
|
145
|
+
fs.writeFileSync(path.join(rootPath, confPath), JSON.stringify(config));
|
|
141
146
|
// for windows 8 / 8.1 / server 2012 R2 /
|
|
142
147
|
if (Number(osVersion[0]) === 6 && (Number(osVersion[1]) === 2 || Number(osVersion[1]) === 3)) {
|
|
143
148
|
// for 10
|
|
144
|
-
passphrase = Math.random().toString().substring(2);
|
|
145
|
-
config.server.passphrase = passphrase;
|
|
146
|
-
fs.writeFileSync(path.join(__dirname, confPath), JSON.stringify(config));
|
|
147
|
-
|
|
148
149
|
createCertCommand = `$cert = ('Cert:\\CurrentUser\\My\\' + (` +
|
|
149
150
|
` New-SelfSignedCertificate ` +
|
|
150
151
|
` -DnsName localhost ` +
|
|
@@ -154,17 +155,10 @@ async function createCertFile(config, open) {
|
|
|
154
155
|
` Export-PfxCertificate -Cert $cert` +
|
|
155
156
|
` -FilePath '${pfxPath}' ` +
|
|
156
157
|
` -Password (ConvertTo-SecureString -String '${passphrase}' -Force -AsPlainText)`;
|
|
157
|
-
|
|
158
158
|
await exec(`${startCmd} "${createCertCommand}"`);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
163
161
|
// for window 10 / server 2016
|
|
164
|
-
passphrase = Math.random().toString().substring(2);
|
|
165
|
-
config.server.passphrase = passphrase;
|
|
166
|
-
fs.writeFileSync(path.join(__dirname, confPath), JSON.stringify(config));
|
|
167
|
-
|
|
168
162
|
createCertCommand = `$cert = ('Cert:\\CurrentUser\\My\\' + (` +
|
|
169
163
|
` New-SelfSignedCertificate ` +
|
|
170
164
|
` -DnsName localhost ` +
|
|
@@ -181,41 +175,40 @@ async function createCertFile(config, open) {
|
|
|
181
175
|
` Export-PfxCertificate -Cert $cert` +
|
|
182
176
|
` -FilePath '${pfxPath}' ` +
|
|
183
177
|
` -Password (ConvertTo-SecureString -String '${passphrase}' -Force -AsPlainText)`;
|
|
184
|
-
|
|
185
178
|
await exec(`${startCmd} "${createCertCommand}"`);
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
179
|
+
}
|
|
180
|
+
if (await fs.exists(pfxPath)) {
|
|
181
|
+
ConsoleWriter.info(`Certificate generated. Location is ${pfxPath}. Passphrase is '${passphrase}'`);
|
|
189
182
|
}
|
|
190
183
|
break;
|
|
191
184
|
default:
|
|
192
185
|
ConsoleWriter.error('Unknown platform');
|
|
193
186
|
}
|
|
194
|
-
}
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
195
189
|
if (e && e.message && e.message.indexOf("'openssl' is not recognized as an internal or external command") > 0) {
|
|
196
|
-
ConsoleWriter.
|
|
197
|
-
ConsoleWriter.
|
|
190
|
+
ConsoleWriter.warning('Create certificate error:');
|
|
191
|
+
ConsoleWriter.warning('OpenSSL is not installed or not available from command line');
|
|
198
192
|
ConsoleWriter.info('Install OpenSSL from https://www.openssl.org or https://wiki.openssl.org/index.php/Binaries');
|
|
199
193
|
ConsoleWriter.info('and try again');
|
|
200
|
-
|
|
201
194
|
ConsoleWriter.info('Read more at');
|
|
202
195
|
ConsoleWriter.info('https://github.com/Microsoft/PowerBI-visuals/blob/master/tools/CreateCertificate.md#manual');
|
|
203
|
-
}
|
|
204
|
-
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
ConsoleWriter.error(['Create certificate error:', e]);
|
|
205
199
|
}
|
|
206
200
|
}
|
|
207
|
-
}
|
|
208
|
-
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
ConsoleWriter.error(['Unknown platform. Please place a custom-generated certificate in:', certPath]);
|
|
209
204
|
}
|
|
210
205
|
}
|
|
211
|
-
|
|
212
206
|
async function getCertFile(config, silent) {
|
|
213
207
|
if (typeof silent === "undefined") {
|
|
214
208
|
silent = false;
|
|
215
209
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
const cert = path.join(rootPath, config.server.certificate);
|
|
211
|
+
const pfx = path.join(rootPath, config.server.pfx);
|
|
219
212
|
if (await fs.exists(cert)) {
|
|
220
213
|
return cert;
|
|
221
214
|
}
|
|
@@ -227,92 +220,88 @@ async function getCertFile(config, silent) {
|
|
|
227
220
|
}
|
|
228
221
|
return pfx;
|
|
229
222
|
}
|
|
230
|
-
|
|
231
223
|
if (!silent) {
|
|
232
224
|
ConsoleWriter.info('Certificate not found. Call `pbiviz --install-cert` command to create the new certificate');
|
|
233
225
|
}
|
|
234
226
|
return null;
|
|
235
227
|
}
|
|
236
|
-
|
|
237
228
|
async function openCertFile(config) {
|
|
238
|
-
|
|
239
|
-
|
|
229
|
+
const certPath = await getCertFile(config);
|
|
240
230
|
if (!certPath) {
|
|
241
231
|
return null;
|
|
242
232
|
}
|
|
243
|
-
|
|
244
|
-
let openCmds = {
|
|
233
|
+
const openCmds = {
|
|
245
234
|
linux: 'xdg-open',
|
|
246
235
|
darwin: 'open',
|
|
247
236
|
win32: 'powershell start'
|
|
248
237
|
};
|
|
249
|
-
|
|
238
|
+
const startCmd = openCmds[os.platform()];
|
|
250
239
|
if (startCmd) {
|
|
251
240
|
try {
|
|
252
241
|
await exec(`${startCmd} "${certPath}"`);
|
|
253
|
-
} catch (e) {
|
|
254
|
-
ConsoleWriter.info('Certificate path:', certPath);
|
|
255
242
|
}
|
|
256
|
-
|
|
257
|
-
|
|
243
|
+
catch (e) {
|
|
244
|
+
ConsoleWriter.info(['Certificate path:', certPath]);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
ConsoleWriter.info(['Certificate path:', certPath]);
|
|
258
249
|
}
|
|
259
250
|
}
|
|
260
|
-
|
|
261
|
-
async function removeCertFiles(certPath, keyPath, pfxPath) {
|
|
251
|
+
export async function removeCertFiles(certPath, keyPath, pfxPath) {
|
|
262
252
|
try {
|
|
263
253
|
await fs.unlink(certPath);
|
|
264
|
-
}
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
265
256
|
if (!e.message.indexOf("no such file or directory")) {
|
|
266
257
|
throw e;
|
|
267
258
|
}
|
|
268
259
|
}
|
|
269
260
|
try {
|
|
270
261
|
await fs.unlink(keyPath);
|
|
271
|
-
}
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
272
264
|
if (!e.message.indexOf("no such file or directory")) {
|
|
273
265
|
throw e;
|
|
274
266
|
}
|
|
275
267
|
}
|
|
276
268
|
try {
|
|
277
269
|
await fs.unlink(pfxPath);
|
|
278
|
-
}
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
279
272
|
if (!e.message.indexOf("no such file or directory")) {
|
|
280
273
|
throw e;
|
|
281
274
|
}
|
|
282
275
|
}
|
|
283
276
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
let options = {};
|
|
277
|
+
async function getGlobalPbivizCerts(config) {
|
|
278
|
+
const options = {};
|
|
287
279
|
try {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
options.passphrase = fs.existsSync(
|
|
294
|
-
|
|
295
|
-
let CertFileVerified = await veryfyCertFile(keyPath, certPath, pfxPath, options.passphrase);
|
|
296
|
-
|
|
280
|
+
const location = (await exec('npm ls -g powerbi-visuals-tools')).split("\n")[0];
|
|
281
|
+
const certPath = path.join(location, "node_modules", "powerbi-visuals-tools", config.server.certificate);
|
|
282
|
+
const keyPath = path.join(location, "node_modules", "powerbi-visuals-tools", config.server.privateKey);
|
|
283
|
+
const pfxPath = path.join(location, "node_modules", "powerbi-visuals-tools", config.server.pfx);
|
|
284
|
+
const globalPbivizConfig = path.join(location, "node_modules", "powerbi-visuals-tools", "config.json");
|
|
285
|
+
options.passphrase = fs.existsSync(globalPbivizConfig) && fs.readJSONSync(globalPbivizConfig).server.passphrase;
|
|
286
|
+
const CertFileVerified = await verifyCertFile(keyPath, certPath, pfxPath, options.passphrase);
|
|
297
287
|
options.cert = fs.existsSync(certPath) && certPath;
|
|
298
288
|
options.key = fs.existsSync(keyPath) && keyPath;
|
|
299
289
|
options.pfx = fs.existsSync(pfxPath) && CertFileVerified && pfxPath;
|
|
300
290
|
}
|
|
301
291
|
catch (err) {
|
|
302
|
-
ConsoleWriter.
|
|
292
|
+
ConsoleWriter.warning(`Global certificate error: ${err}`);
|
|
303
293
|
}
|
|
304
294
|
if (!options.cert && !options.pfx) {
|
|
305
|
-
ConsoleWriter.
|
|
295
|
+
ConsoleWriter.warning(`Global instance of valid pbiviz certificate not found.`);
|
|
306
296
|
}
|
|
307
297
|
return options;
|
|
308
298
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
299
|
+
export async function resolveCertificate() {
|
|
300
|
+
const config = readJsonFromRoot('config.json');
|
|
301
|
+
const options = {};
|
|
302
|
+
const keyPath = path.join(rootPath, config.server.privateKey);
|
|
303
|
+
const certPath = path.join(rootPath, config.server.certificate);
|
|
304
|
+
const pfxPath = path.join(rootPath, config.server.pfx);
|
|
316
305
|
if (config.server.passphrase) {
|
|
317
306
|
options.passphrase = config.server.passphrase;
|
|
318
307
|
}
|
|
@@ -325,14 +314,11 @@ async function resolveCertificate() {
|
|
|
325
314
|
if (await fs.exists(pfxPath)) {
|
|
326
315
|
options.pfx = await fs.readFile(pfxPath);
|
|
327
316
|
}
|
|
328
|
-
|
|
329
|
-
let CertFileVerified = await veryfyCertFile(keyPath, certPath, pfxPath, options.passphrase);
|
|
330
|
-
|
|
317
|
+
const CertFileVerified = await verifyCertFile(keyPath, certPath, pfxPath, options.passphrase);
|
|
331
318
|
if ((!options.cert && !options.pfx) || !CertFileVerified) {
|
|
332
|
-
ConsoleWriter.
|
|
319
|
+
ConsoleWriter.warning("Local valid certificate not found.");
|
|
333
320
|
ConsoleWriter.info("Checking global instance of pbiviz certificate...");
|
|
334
|
-
|
|
335
|
-
|
|
321
|
+
const globalPbivizOptions = await getGlobalPbivizCerts(config);
|
|
336
322
|
if (!globalPbivizOptions.cert && !globalPbivizOptions.pfx) {
|
|
337
323
|
await createCertFile(config, true);
|
|
338
324
|
if (!(await getCertFile(config, true))) {
|
|
@@ -358,38 +344,36 @@ async function resolveCertificate() {
|
|
|
358
344
|
// copy certs to local instance
|
|
359
345
|
ConsoleWriter.info("Copy server certificate from global instance of pbiviz...");
|
|
360
346
|
if (globalPbivizOptions.cert) {
|
|
361
|
-
await fs.copyFile(globalPbivizOptions.cert, path.join(
|
|
347
|
+
await fs.copyFile(globalPbivizOptions.cert, path.join(rootPath, config.server.certificate));
|
|
362
348
|
options.certificate = config.server.certificate;
|
|
363
349
|
}
|
|
364
350
|
if (globalPbivizOptions.key) {
|
|
365
|
-
await fs.copyFile(globalPbivizOptions.key, path.join(
|
|
351
|
+
await fs.copyFile(globalPbivizOptions.key, path.join(rootPath, config.server.privateKey));
|
|
366
352
|
options.privateKey = config.server.privateKey;
|
|
367
353
|
}
|
|
368
354
|
if (globalPbivizOptions.pfx) {
|
|
369
|
-
await fs.copyFile(globalPbivizOptions.pfx, path.join(
|
|
370
|
-
// need to pass whole file instead
|
|
371
|
-
options.pfx = await fs.readFile(path.join(
|
|
355
|
+
await fs.copyFile(globalPbivizOptions.pfx, path.join(rootPath, config.server.pfx));
|
|
356
|
+
// need to pass whole file instead path to file
|
|
357
|
+
options.pfx = await fs.readFile(path.join(rootPath, config.server.pfx));
|
|
372
358
|
options.passphrase = globalPbivizOptions.passphrase;
|
|
373
359
|
// eslint-disable-next-line require-atomic-updates
|
|
374
360
|
config.server.passphrase = globalPbivizOptions.passphrase;
|
|
375
361
|
}
|
|
376
|
-
await fs.writeFile(path.join(
|
|
362
|
+
await fs.writeFile(path.join(rootPath, confPath), JSON.stringify(config));
|
|
377
363
|
}
|
|
378
364
|
}
|
|
379
365
|
return options;
|
|
380
366
|
}
|
|
381
|
-
|
|
382
|
-
async function veryfyCertFile(keyPath, certPath, pfxPath, passphrase) {
|
|
367
|
+
export async function verifyCertFile(keyPath, certPath, pfxPath, passphrase) {
|
|
383
368
|
let verifyCertDate;
|
|
384
369
|
try {
|
|
385
370
|
let endDateStr;
|
|
386
|
-
|
|
387
371
|
// For Windows OS:
|
|
388
372
|
if (os.platform() === "win32") {
|
|
389
373
|
if (!fs.existsSync(pfxPath) || !passphrase) {
|
|
390
374
|
return false;
|
|
391
375
|
}
|
|
392
|
-
|
|
376
|
+
const certStr = await exec(`powershell.exe (New-Object System.Security.Cryptography.X509Certificates.X509Certificate2('${pfxPath}','${passphrase}')).NotAfter.ToString('yyyy-MM-dd HH:mm:ss')`);
|
|
393
377
|
endDateStr = certStr.trim();
|
|
394
378
|
}
|
|
395
379
|
// For Linux and Mac/darwin OS:
|
|
@@ -399,27 +383,19 @@ async function veryfyCertFile(keyPath, certPath, pfxPath, passphrase) {
|
|
|
399
383
|
}
|
|
400
384
|
endDateStr = await exec(`openssl x509 -enddate -noout -in ${certPath} | cut -d = -f 2`);
|
|
401
385
|
}
|
|
402
|
-
|
|
403
|
-
let endDate = Date.parse(endDateStr);
|
|
386
|
+
const endDate = Date.parse(endDateStr);
|
|
404
387
|
verifyCertDate = (endDate - Date.now()) > certSafePeriod;
|
|
405
388
|
if (verifyCertDate) {
|
|
406
389
|
ConsoleWriter.info(`Certificate is valid.`);
|
|
407
|
-
}
|
|
408
|
-
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
ConsoleWriter.warning(`Certificate is invalid!`);
|
|
409
393
|
removeCertFiles(certPath, keyPath, pfxPath);
|
|
410
394
|
}
|
|
411
|
-
}
|
|
412
|
-
|
|
395
|
+
}
|
|
396
|
+
catch (err) {
|
|
397
|
+
ConsoleWriter.warning(`Certificate verification error: ${err}`);
|
|
413
398
|
removeCertFiles(certPath, keyPath, pfxPath);
|
|
414
399
|
}
|
|
415
400
|
return verifyCertDate;
|
|
416
401
|
}
|
|
417
|
-
|
|
418
|
-
module.exports = {
|
|
419
|
-
getCertFile,
|
|
420
|
-
createCertFile,
|
|
421
|
-
openCertFile,
|
|
422
|
-
removeCertFiles,
|
|
423
|
-
getGlobalPbivizCerts,
|
|
424
|
-
resolveCertificate
|
|
425
|
-
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import ConsoleWriter from './ConsoleWriter.js';
|
|
2
|
+
import VisualManager from './VisualManager.js';
|
|
3
|
+
export default class CommandManager {
|
|
4
|
+
static async start(options, rootPath) {
|
|
5
|
+
const webpackOptions = {
|
|
6
|
+
devMode: true,
|
|
7
|
+
devtool: "source-map",
|
|
8
|
+
generateResources: true,
|
|
9
|
+
generatePbiviz: false,
|
|
10
|
+
minifyJS: false,
|
|
11
|
+
minify: false,
|
|
12
|
+
devServerPort: options.port,
|
|
13
|
+
stats: options.stats
|
|
14
|
+
};
|
|
15
|
+
const visualManager = new VisualManager(rootPath);
|
|
16
|
+
await visualManager
|
|
17
|
+
.prepareVisual()
|
|
18
|
+
.initializeWebpack(webpackOptions);
|
|
19
|
+
visualManager.startWebpackServer(options.drop);
|
|
20
|
+
}
|
|
21
|
+
static async package(options, rootPath) {
|
|
22
|
+
if (!options.pbiviz && !options.resources) {
|
|
23
|
+
ConsoleWriter.error('Nothing to build. Cannot use --no-pbiviz without --resources');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const webpackOptions = {
|
|
27
|
+
devMode: false,
|
|
28
|
+
generateResources: options.resources,
|
|
29
|
+
generatePbiviz: options.pbiviz,
|
|
30
|
+
minifyJS: options.minify,
|
|
31
|
+
minify: options.minify,
|
|
32
|
+
compression: options.compression,
|
|
33
|
+
stats: options.stats
|
|
34
|
+
};
|
|
35
|
+
new VisualManager(rootPath)
|
|
36
|
+
.prepareVisual()
|
|
37
|
+
.initializeWebpack(webpackOptions)
|
|
38
|
+
.then(visualManager => visualManager.generatePackage());
|
|
39
|
+
}
|
|
40
|
+
static new({ force, template }, name, rootPath) {
|
|
41
|
+
const generateOptions = {
|
|
42
|
+
force: force,
|
|
43
|
+
template: template
|
|
44
|
+
};
|
|
45
|
+
VisualManager.createVisual(rootPath, name, generateOptions);
|
|
46
|
+
}
|
|
47
|
+
static info(rootPath) {
|
|
48
|
+
new VisualManager(rootPath)
|
|
49
|
+
.prepareVisual()
|
|
50
|
+
.displayInfo();
|
|
51
|
+
}
|
|
52
|
+
}
|