powerbi-visuals-tools 3.3.2 → 3.4.3
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/.vscode/launch.json +52 -0
- package/Changelog.md +105 -16
- package/bin/pbiviz-new.js +3 -12
- package/bin/pbiviz-package.js +12 -8
- package/bin/pbiviz-start.js +25 -51
- package/bin/pbiviz.js +0 -1
- package/config.json +1 -1
- package/lib/CertificateTools.js +6 -8
- package/lib/TemplateFetcher.js +7 -29
- package/lib/VisualGenerator.js +5 -94
- package/lib/WebPackWrap.js +69 -75
- package/lib/utils.js +26 -0
- package/lib/webpack.config.js +9 -6
- package/package.json +14 -16
- package/templates/visuals/default/package.json +2 -2
- package/templates/visuals/rhtml/package.json +1 -1
- package/templates/visuals/rvisual/package.json +1 -1
- package/templates/visuals/slicer/package.json +2 -2
- package/templates/visuals/table/package.json +2 -2
- package/bin/pbiviz-update.js +0 -128
- package/lib/LessCompiler.js +0 -86
- package/lib/TypescriptCompiler.js +0 -243
- package/templates/visuals/.api/v1.0.0/PowerBI-visuals.d.ts +0 -1139
- package/templates/visuals/.api/v1.0.0/schema.capabilities.json +0 -758
- package/templates/visuals/.api/v1.0.0/schema.pbiviz.json +0 -95
- package/templates/visuals/.api/v1.1.0/PowerBI-visuals.d.ts +0 -1179
- package/templates/visuals/.api/v1.1.0/schema.capabilities.json +0 -828
- package/templates/visuals/.api/v1.1.0/schema.pbiviz.json +0 -95
- package/templates/visuals/.api/v1.10.0/PowerBI-visuals.d.ts +0 -1406
- package/templates/visuals/.api/v1.10.0/schema.capabilities.json +0 -1143
- package/templates/visuals/.api/v1.10.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.10.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.10.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.11.0/PowerBI-visuals.d.ts +0 -1406
- package/templates/visuals/.api/v1.11.0/schema.capabilities.json +0 -1143
- package/templates/visuals/.api/v1.11.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.11.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.11.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.12.0/PowerBI-visuals.d.ts +0 -1408
- package/templates/visuals/.api/v1.12.0/schema.capabilities.json +0 -1173
- package/templates/visuals/.api/v1.12.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.12.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.12.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.13.0/PowerBI-visuals.d.ts +0 -1450
- package/templates/visuals/.api/v1.13.0/schema.capabilities.json +0 -1181
- package/templates/visuals/.api/v1.13.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.13.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.13.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.2.0/PowerBI-visuals.d.ts +0 -1188
- package/templates/visuals/.api/v1.2.0/schema.capabilities.json +0 -951
- package/templates/visuals/.api/v1.2.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.2.0/schema.pbiviz.json +0 -99
- package/templates/visuals/.api/v1.3.0/PowerBI-visuals.d.ts +0 -1293
- package/templates/visuals/.api/v1.3.0/schema.capabilities.json +0 -951
- package/templates/visuals/.api/v1.3.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.3.0/schema.pbiviz.json +0 -95
- package/templates/visuals/.api/v1.4.0/PowerBI-visuals.d.ts +0 -1282
- package/templates/visuals/.api/v1.4.0/schema.capabilities.json +0 -951
- package/templates/visuals/.api/v1.4.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.4.0/schema.pbiviz.json +0 -95
- package/templates/visuals/.api/v1.5.0/PowerBI-visuals.d.ts +0 -1205
- package/templates/visuals/.api/v1.5.0/schema.capabilities.json +0 -987
- package/templates/visuals/.api/v1.5.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.5.0/schema.pbiviz.json +0 -95
- package/templates/visuals/.api/v1.6.0/PowerBI-visuals.d.ts +0 -1297
- package/templates/visuals/.api/v1.6.0/schema.capabilities.json +0 -1007
- package/templates/visuals/.api/v1.6.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.6.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.6.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.7.0/PowerBI-visuals.d.ts +0 -1381
- package/templates/visuals/.api/v1.7.0/schema.capabilities.json +0 -1007
- package/templates/visuals/.api/v1.7.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.7.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.7.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.8.0/PowerBI-visuals.d.ts +0 -1389
- package/templates/visuals/.api/v1.8.0/schema.capabilities.json +0 -1131
- package/templates/visuals/.api/v1.8.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.8.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.8.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v1.9.0/PowerBI-visuals.d.ts +0 -1391
- package/templates/visuals/.api/v1.9.0/schema.capabilities.json +0 -1131
- package/templates/visuals/.api/v1.9.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v1.9.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v1.9.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v2.0.0/PowerBI-visuals.d.ts +0 -1417
- package/templates/visuals/.api/v2.0.0/schema.capabilities.json +0 -1177
- package/templates/visuals/.api/v2.0.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v2.0.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v2.0.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v2.1.0/PowerBI-visuals.d.ts +0 -1417
- package/templates/visuals/.api/v2.1.0/schema.capabilities.json +0 -1177
- package/templates/visuals/.api/v2.1.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v2.1.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v2.1.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v2.2.0/PowerBI-visuals.d.ts +0 -1423
- package/templates/visuals/.api/v2.2.0/schema.capabilities.json +0 -1189
- package/templates/visuals/.api/v2.2.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v2.2.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v2.2.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v2.3.0/PowerBI-visuals.d.ts +0 -1480
- package/templates/visuals/.api/v2.3.0/schema.capabilities.json +0 -1193
- package/templates/visuals/.api/v2.3.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v2.3.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v2.3.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v2.5.0/PowerBI-visuals.d.ts +0 -1483
- package/templates/visuals/.api/v2.5.0/schema.capabilities.json +0 -1197
- package/templates/visuals/.api/v2.5.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v2.5.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v2.5.0/schema.stringResources.json +0 -67
- package/templates/visuals/.api/v2.6.0/PowerBI-visuals.d.ts +0 -1485
- package/templates/visuals/.api/v2.6.0/schema.capabilities.json +0 -1323
- package/templates/visuals/.api/v2.6.0/schema.dependencies.json +0 -38
- package/templates/visuals/.api/v2.6.0/schema.pbiviz.json +0 -103
- package/templates/visuals/.api/v2.6.0/schema.stringResources.json +0 -67
- package/templates/visuals/default1/assets/icon.png +0 -0
- package/templates/visuals/default1/capabilities.json +0 -84
- package/templates/visuals/default1/package.json +0 -6
- package/templates/visuals/default1/pbiviz.json +0 -3
- package/templates/visuals/default1/src/settings.ts +0 -32
- package/templates/visuals/default1/src/visual.ts +0 -71
- package/templates/visuals/default1/style/visual.less +0 -9
- package/templates/visuals/default1/tsconfig.json +0 -16
package/bin/pbiviz-update.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
* Power BI Visual CLI
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Microsoft Corporation
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
* MIT License
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
-
* of this software and associated documentation files (the ""Software""), to deal
|
|
11
|
-
* in the Software without restriction, including without limitation the rights
|
|
12
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
* furnished to do so, subject to the following conditions:
|
|
15
|
-
*
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in
|
|
17
|
-
* all copies or substantial portions of the Software.
|
|
18
|
-
*
|
|
19
|
-
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
-
* THE SOFTWARE.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
"use strict";
|
|
29
|
-
|
|
30
|
-
const { exec } = require('child_process');
|
|
31
|
-
let path = require('path');
|
|
32
|
-
let program = require('commander');
|
|
33
|
-
let VisualPackage = require('../lib/VisualPackage');
|
|
34
|
-
let VisualGenerator = require('../lib/VisualGenerator');
|
|
35
|
-
let ConsoleWriter = require('../lib/ConsoleWriter');
|
|
36
|
-
let CommandHelpManager = require('../lib/CommandHelpManager');
|
|
37
|
-
let options = process.argv;
|
|
38
|
-
|
|
39
|
-
for (let i = 0; i < options.length; i++) {
|
|
40
|
-
if (options[i] == '--help' || options[i] == '-h') {
|
|
41
|
-
program.help(CommandHelpManager.createSubCommandHelpCallback(options));
|
|
42
|
-
process.exit(0);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
program.parse(options);
|
|
47
|
-
|
|
48
|
-
let args = program.args;
|
|
49
|
-
|
|
50
|
-
let cwd = process.cwd();
|
|
51
|
-
|
|
52
|
-
let pbiviz;
|
|
53
|
-
try {
|
|
54
|
-
pbiviz = require(path.join(cwd, "./pbiviz.json"));
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
throw new Error("pbiviz.json not found. You must be in the root of a visual project to run this command");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let pkg;
|
|
61
|
-
try {
|
|
62
|
-
pkg = require(path.join(cwd, "./package.json"));
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
throw new Error("package.json not found. You must be in the root of a visual project to run this command");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let tsconfig;
|
|
69
|
-
try {
|
|
70
|
-
tsconfig = require(path.join(cwd, "./tsconfig.json"));
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
throw new Error("tsconfig.json not found. You must be in the root of a visual project to run this command");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (tsconfig.compilerOptions && tsconfig.compilerOptions.outDir) {
|
|
77
|
-
let packgeApiVersion;
|
|
78
|
-
if (pkg.devDependencies && pkg.devDependencies["powerbi-visuals-api"]) {
|
|
79
|
-
packgeApiVersion = pkg.devDependencies["powerbi-visuals-api"];
|
|
80
|
-
}
|
|
81
|
-
if (pkg.dependencies && pkg.dependencies["powerbi-visuals-api"]) {
|
|
82
|
-
packgeApiVersion = pkg.dependencies["powerbi-visuals-api"];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
let apiVersion;
|
|
87
|
-
if (args.length > 0) {
|
|
88
|
-
apiVersion = `~${args[0]}`;
|
|
89
|
-
}
|
|
90
|
-
if (!apiVersion && pbiviz.apiVersion) {
|
|
91
|
-
apiVersion = `~${pbiviz.apiVersion}`;
|
|
92
|
-
}
|
|
93
|
-
if (!apiVersion && packgeApiVersion) {
|
|
94
|
-
apiVersion = `~${packgeApiVersion}`;
|
|
95
|
-
}
|
|
96
|
-
if (!apiVersion) {
|
|
97
|
-
apiVersion = "latest";
|
|
98
|
-
}
|
|
99
|
-
exec(`npm install --save powerbi-visuals-api@${apiVersion}`, (err, strout, stderror) => {
|
|
100
|
-
if (err) {
|
|
101
|
-
if (err.message.indexOf("No matching version found for powerbi-visuals-api") !== -1) {
|
|
102
|
-
throw new Error(`Error: Invalid API version: ${apiVersion}`);
|
|
103
|
-
}
|
|
104
|
-
ConsoleWriter.error(`npm install --save powerbi-visuals-api@${apiVersion} failed`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
ConsoleWriter.info(strout);
|
|
108
|
-
ConsoleWriter.error(stderror);
|
|
109
|
-
});
|
|
110
|
-
} catch (error) {
|
|
111
|
-
ConsoleWriter.error(error.message);
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
VisualPackage.loadVisualPackage(cwd).then((visualPackage) => {
|
|
115
|
-
let apiVersion = args.length > 0 ? args[0] : visualPackage.config.apiVersion;
|
|
116
|
-
let visualPath = visualPackage.buildPath();
|
|
117
|
-
VisualGenerator.updateApi(visualPath, apiVersion)
|
|
118
|
-
.then(() => visualPackage.config.apiVersion === apiVersion ? false : VisualGenerator.setApiVersion(visualPath, apiVersion))
|
|
119
|
-
.then(() => ConsoleWriter.info(`Visual api ${apiVersion} updated`))
|
|
120
|
-
.catch(e => {
|
|
121
|
-
ConsoleWriter.error('UPDATE ERROR', e);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
});
|
|
124
|
-
}).catch((e) => {
|
|
125
|
-
ConsoleWriter.error('LOAD ERROR', e);
|
|
126
|
-
process.exit(1);
|
|
127
|
-
});
|
|
128
|
-
}
|
package/lib/LessCompiler.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Power BI Visual CLI
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Microsoft Corporation
|
|
5
|
-
* All rights reserved.
|
|
6
|
-
* MIT License
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the ""Software""), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
|
16
|
-
* all copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
-
* THE SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
"use strict";
|
|
28
|
-
|
|
29
|
-
let fs = require('fs-extra');
|
|
30
|
-
let path = require('path');
|
|
31
|
-
let less = require('less');
|
|
32
|
-
let config = require('../config.json');
|
|
33
|
-
|
|
34
|
-
function createProdCss(srcFilePath, cssContent) {
|
|
35
|
-
let cssCommentRegExp = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
36
|
-
let prodFilePath = srcFilePath.slice(0, -3) + 'prod.css';
|
|
37
|
-
let cssProdContent = cssContent.replace(cssCommentRegExp, '');
|
|
38
|
-
fs.writeFileSync(prodFilePath, cssProdContent);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class LessCompiler {
|
|
42
|
-
/**
|
|
43
|
-
* Builds less of a visual package
|
|
44
|
-
*
|
|
45
|
-
* @param {VisualPackage} package - An instance of a visual package
|
|
46
|
-
* @returns {Promise}
|
|
47
|
-
*/
|
|
48
|
-
static build(visualPackage, options) {
|
|
49
|
-
options = options || {};
|
|
50
|
-
let lessFilename = visualPackage.config.style;
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
let lessPath = visualPackage.buildPath(lessFilename);
|
|
53
|
-
let dropCssPath = visualPackage.buildPath(config.build.dropFolder, config.build.css);
|
|
54
|
-
let lessContent = fs.readFileSync(lessPath).toString();
|
|
55
|
-
let lessMinifiedOptions = {
|
|
56
|
-
sourceMap: {
|
|
57
|
-
sourceMapURL: path.basename(dropCssPath) + '.map'
|
|
58
|
-
},
|
|
59
|
-
compress: true
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
less.render(lessContent, options.minify ? lessMinifiedOptions : null).then(cssContent => {
|
|
63
|
-
fs.ensureDirSync(path.dirname(dropCssPath));
|
|
64
|
-
fs.writeFileSync(dropCssPath, cssContent.css);
|
|
65
|
-
createProdCss(dropCssPath, cssContent.css);
|
|
66
|
-
if (cssContent.map) {
|
|
67
|
-
fs.writeFileSync(dropCssPath + '.map', cssContent.map);
|
|
68
|
-
}
|
|
69
|
-
resolve();
|
|
70
|
-
}).catch(e => {
|
|
71
|
-
let messages = [
|
|
72
|
-
{
|
|
73
|
-
filename: lessFilename,
|
|
74
|
-
line: e.line,
|
|
75
|
-
column: e.column,
|
|
76
|
-
message: e.message,
|
|
77
|
-
type: 'less'
|
|
78
|
-
}
|
|
79
|
-
];
|
|
80
|
-
reject(messages);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = LessCompiler;
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Power BI Visual CLI
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Microsoft Corporation
|
|
5
|
-
* All rights reserved.
|
|
6
|
-
* MIT License
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the ""Software""), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
|
16
|
-
* all copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
-
* THE SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
"use strict";
|
|
28
|
-
|
|
29
|
-
const fs = require('fs-extra');
|
|
30
|
-
const path = require('path');
|
|
31
|
-
const ts = require('typescript');
|
|
32
|
-
const concat = require('source-map-concat');
|
|
33
|
-
const config = require('../config.json');
|
|
34
|
-
const ConsoleWriter = require('./ConsoleWriter');
|
|
35
|
-
const encoding = "utf8";
|
|
36
|
-
const template = require('../templates/plugin-ts-template');
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Whatches TypeScript files and compiles into javascript
|
|
40
|
-
*
|
|
41
|
-
* @param {array<string>} rootFileNames - an array of files to watch and compile
|
|
42
|
-
* @param {object} options - TSC compiler options object
|
|
43
|
-
* @returns {Promise}
|
|
44
|
-
*/
|
|
45
|
-
function runWatcher(rootFileNames, options, packagemode, visualPackage) {
|
|
46
|
-
const files = {};
|
|
47
|
-
for (let fileName in rootFileNames) {
|
|
48
|
-
files[rootFileNames[fileName]] = { version: 0 };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const servicesHost = {
|
|
52
|
-
getScriptFileNames: () => rootFileNames,
|
|
53
|
-
getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(),
|
|
54
|
-
getScriptSnapshot: (fileName) => {
|
|
55
|
-
if (!fs.existsSync(fileName)) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
|
|
60
|
-
},
|
|
61
|
-
getCurrentDirectory: () => process.cwd(),
|
|
62
|
-
getCompilationSettings: () => options,
|
|
63
|
-
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options),
|
|
64
|
-
fileExists: ts.sys.fileExists,
|
|
65
|
-
readFile: ts.sys.readFile,
|
|
66
|
-
readDirectory: ts.sys.readDirectory
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
if (options.outDir) {
|
|
70
|
-
if (!fs.existsSync(options.outDir)) {
|
|
71
|
-
fs.mkdir(options.outDir);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (options.out && options.out.length) {
|
|
75
|
-
let out = options.out.split("/");
|
|
76
|
-
out.pop();
|
|
77
|
-
let buildPath = out.join(path.sep);
|
|
78
|
-
if (!fs.existsSync(buildPath)) {
|
|
79
|
-
fs.mkdir(buildPath);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
rootFileNames.forEach((fileName) => {
|
|
86
|
-
// First time around, emit all files
|
|
87
|
-
emitFile(fileName);
|
|
88
|
-
// Add a watch on the file to handle next change
|
|
89
|
-
if (packagemode) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
fs.watchFile(fileName,
|
|
93
|
-
{
|
|
94
|
-
persistent: true,
|
|
95
|
-
interval: 250
|
|
96
|
-
},
|
|
97
|
-
(curr, prev) => {
|
|
98
|
-
// Check timestamp
|
|
99
|
-
if (Number(curr.mtime) <= Number(prev.mtime)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Update the version to signal a change in the file
|
|
104
|
-
files[fileName].version++;
|
|
105
|
-
|
|
106
|
-
// write the changes to disk
|
|
107
|
-
emitFile(fileName);
|
|
108
|
-
concatExternalJS(visualPackage);
|
|
109
|
-
appendExportPowerBINameSpace(visualPackage, options);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
catch (ex) {
|
|
114
|
-
ConsoleWriter.error(ex.message);
|
|
115
|
-
ConsoleWriter.error(ex.path);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function emitFile(fileName) {
|
|
120
|
-
let output = services.getEmitOutput(fileName);
|
|
121
|
-
|
|
122
|
-
ConsoleWriter.info(`Compile ${fileName}`);
|
|
123
|
-
|
|
124
|
-
output.outputFiles.forEach(o => {
|
|
125
|
-
fs.writeFileSync(o.name, o.text, "utf8");
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return services;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Creates a visual plugin from a visual package
|
|
134
|
-
*
|
|
135
|
-
* @param {VisualPackage} visualPackage - instance of a visual package to build
|
|
136
|
-
* @param {string} pluginName - name of the plugin
|
|
137
|
-
* @returns {string} path to the created visual plugin
|
|
138
|
-
*/
|
|
139
|
-
async function createPlugin(visualPackage, pluginName) {
|
|
140
|
-
let visualConfig = visualPackage.config;
|
|
141
|
-
let pluginOptions = {
|
|
142
|
-
pluginName: pluginName,
|
|
143
|
-
visualGuid: visualConfig.visual.guid,
|
|
144
|
-
visualClass: visualConfig.visual.visualClassName,
|
|
145
|
-
visualDisplayName: visualConfig.visual.displayName,
|
|
146
|
-
visualVersion: visualConfig.visual.version,
|
|
147
|
-
apiVersion: visualConfig.apiVersion
|
|
148
|
-
};
|
|
149
|
-
let pluginTs = template(pluginOptions);
|
|
150
|
-
let pluginDropPath = visualPackage.buildPath(config.build.precompileFolder, 'visualPlugin.ts');
|
|
151
|
-
await fs.ensureDir(path.dirname(pluginDropPath));
|
|
152
|
-
await fs.writeFile(pluginDropPath, pluginTs);
|
|
153
|
-
return pluginDropPath;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Concatenates external js resource referenced in pbiviz.externalJS
|
|
158
|
-
*
|
|
159
|
-
* @param {VisualPackage} visualPackage - instance of a visual package
|
|
160
|
-
*/
|
|
161
|
-
async function concatExternalJS(visualPackage) {
|
|
162
|
-
let files = visualPackage.config.externalJS;
|
|
163
|
-
if (!files || files.length < 1) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
let tsconfig = require(visualPackage.buildPath('tsconfig.json'));
|
|
168
|
-
let visualJsName = tsconfig.compilerOptions.out;
|
|
169
|
-
let visualJsPath = visualPackage.buildPath(visualJsName);
|
|
170
|
-
let visualJsMapPath = visualJsPath + '.map';
|
|
171
|
-
|
|
172
|
-
let visualJsMap = JSON.parse((await fs.readFile(visualJsMapPath)).toString());
|
|
173
|
-
visualJsMap.sourceRoot = path.posix.relative(config.build.dropFolder, config.build.precompileFolder);
|
|
174
|
-
|
|
175
|
-
let concatFiles = files.map(file => {
|
|
176
|
-
return {
|
|
177
|
-
source: file,
|
|
178
|
-
code: (fs.readFileSync(visualPackage.buildPath(file))).toString()
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
concatFiles.push({
|
|
183
|
-
source: visualJsName,
|
|
184
|
-
code: (await fs.readFile(visualJsPath)).toString(),
|
|
185
|
-
map: (await fs.readFile(visualJsMapPath)).toString()
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
let concatResult = concat(concatFiles, {
|
|
189
|
-
delimiter: '\n',
|
|
190
|
-
mapPath: visualJsName + '.map'
|
|
191
|
-
}).toStringWithSourceMap({
|
|
192
|
-
file: visualJsName
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
await fs.writeFile(visualJsPath, concatResult.code);
|
|
196
|
-
await fs.writeFile(visualJsMapPath, concatResult.map.toString());
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function appendExportPowerBINameSpace(visualPackage, compilerOptions) {
|
|
200
|
-
if (compilerOptions.outDir) {
|
|
201
|
-
// we should not use externalJS in modern style modules
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
let visualJsName = compilerOptions.out;
|
|
205
|
-
let visualJSFileContent = "";
|
|
206
|
-
let visualJSFilePath = visualPackage.buildPath(visualJsName);
|
|
207
|
-
|
|
208
|
-
visualJSFileContent += "\n" + fs.readFileSync(visualJSFilePath, { encoding: encoding });
|
|
209
|
-
visualJSFileContent = "\nvar powerbi = window.powerbi;\n" + visualJSFileContent;
|
|
210
|
-
await fs.writeFile(visualJSFilePath, visualJSFileContent);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async function injectGlobalizeNameSpace(visualPackage, compilerOptions) {
|
|
214
|
-
if (compilerOptions.outDir) {
|
|
215
|
-
// we should not use externalJS in modern style modules
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
let visualJsName = compilerOptions.out;
|
|
219
|
-
let visualJSFileContent = "";
|
|
220
|
-
let visualJSFilePath = visualPackage.buildPath(visualJsName);
|
|
221
|
-
|
|
222
|
-
visualJSFileContent += "\n" + fs.readFileSync(visualJSFilePath, { encoding: encoding });
|
|
223
|
-
// visualJSFileContent += `\nvar Globalize = Globalize || window["Globalize"] || require("Globalize");\n`;
|
|
224
|
-
visualJSFileContent += `\n
|
|
225
|
-
var Globalize = (() => {
|
|
226
|
-
try {
|
|
227
|
-
return Globalize || window["Globalize"] || require("Globalize");
|
|
228
|
-
}
|
|
229
|
-
catch(ex) {
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
})();
|
|
233
|
-
\n`;
|
|
234
|
-
await fs.writeFile(visualJSFilePath, visualJSFileContent);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
module.exports = {
|
|
238
|
-
concatExternalJS,
|
|
239
|
-
runWatcher,
|
|
240
|
-
createPlugin,
|
|
241
|
-
appendExportPowerBINameSpace,
|
|
242
|
-
injectGlobalizeNameSpace
|
|
243
|
-
};
|