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/bin/pbiviz-package.js
DELETED
|
@@ -1,122 +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 program = require('commander');
|
|
30
|
-
const compareVersions = require("compare-versions");
|
|
31
|
-
const webpack = require("webpack");
|
|
32
|
-
|
|
33
|
-
const config = require('../config.json');
|
|
34
|
-
const VisualPackage = require('../lib/VisualPackage');
|
|
35
|
-
const ConsoleWriter = require('../lib/ConsoleWriter');
|
|
36
|
-
const WebPackWrap = require('../lib/WebPackWrap');
|
|
37
|
-
const CommandHelpManager = require('../lib/CommandHelpManager');
|
|
38
|
-
|
|
39
|
-
let options = process.argv;
|
|
40
|
-
const minAPIversion = config.constants.minAPIversion;
|
|
41
|
-
|
|
42
|
-
program
|
|
43
|
-
.option('--resources', "Produces a folder containing the pbiviz resource files (js, css, json)")
|
|
44
|
-
.option('--no-pbiviz', "Doesn't produce a pbiviz file (must be used in conjunction with resources flag)")
|
|
45
|
-
.option('--no-minify', "Doesn't minify the js in the package (useful for debugging)")
|
|
46
|
-
.option('--no-plugin', "Doesn't include a plugin declaration to the package (must be used in conjunction with --no-pbiviz and --resources flags)")
|
|
47
|
-
.option('--no-stats', "Doesn't generate statistics files")
|
|
48
|
-
.option('-c, --compression <compressionLevel>', "Enables compression of visual package", /^(0|1|2|3|4|5|6|7|8|9)$/i, "6");
|
|
49
|
-
|
|
50
|
-
if (options.some(option => option === '--help' || option === '-h')) {
|
|
51
|
-
program.help(CommandHelpManager.createSubCommandHelpCallback(options));
|
|
52
|
-
process.exit(0);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
program.parse(options);
|
|
56
|
-
|
|
57
|
-
let cwd = process.cwd();
|
|
58
|
-
|
|
59
|
-
if (!program.pbiviz && !program.resources) {
|
|
60
|
-
ConsoleWriter.error('Nothing to build. Cannot use --no-pbiviz without --resources');
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
VisualPackage.loadVisualPackage(cwd).then((visualPackage) => {
|
|
65
|
-
if (visualPackage.config.apiVersion && compareVersions.compare(visualPackage.config.apiVersion, minAPIversion, "<")) {
|
|
66
|
-
ConsoleWriter.error(`Package wasn't created, your current API is '${visualPackage.config.apiVersion}'.
|
|
67
|
-
Please use 'powerbi-visuals-api' ${minAPIversion} or above to build a visual.`);
|
|
68
|
-
process.exit(9);
|
|
69
|
-
}
|
|
70
|
-
ConsoleWriter.info('Building visual...');
|
|
71
|
-
|
|
72
|
-
new WebPackWrap().applyWebpackConfig(visualPackage, {
|
|
73
|
-
devMode: false,
|
|
74
|
-
generateResources: program.resources,
|
|
75
|
-
generatePbiviz: program.pbiviz,
|
|
76
|
-
minifyJS: program.minify,
|
|
77
|
-
minify: program.minify,
|
|
78
|
-
compression: program.compression,
|
|
79
|
-
disableStats: !program.stats
|
|
80
|
-
}).then(({ webpackConfig }) => {
|
|
81
|
-
let compiler = webpack(webpackConfig);
|
|
82
|
-
compiler.run(function (err, stats) {
|
|
83
|
-
if (err) {
|
|
84
|
-
ConsoleWriter.error(`Package wasn't created. ${JSON.stringify(err)}`);
|
|
85
|
-
}
|
|
86
|
-
if (stats.compilation.errors.length) {
|
|
87
|
-
ConsoleWriter.error(`Package wasn't created. ${stats.compilation.errors.length} errors found`);
|
|
88
|
-
}
|
|
89
|
-
displayCertificationRules();
|
|
90
|
-
process.exit(0);
|
|
91
|
-
});
|
|
92
|
-
}).catch(e => {
|
|
93
|
-
ConsoleWriter.error(e.message);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
});
|
|
96
|
-
}).catch(e => {
|
|
97
|
-
ConsoleWriter.error('LOAD ERROR', e);
|
|
98
|
-
process.exit(1);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
function displayCertificationRules() {
|
|
102
|
-
ConsoleWriter.blank();
|
|
103
|
-
ConsoleWriter.warn("Please, make sure that the visual source code matches to requirements of certification:");
|
|
104
|
-
ConsoleWriter.blank();
|
|
105
|
-
ConsoleWriter.info(`Visual must use API v${minAPIversion} and above`);
|
|
106
|
-
ConsoleWriter.info("The project repository must:");
|
|
107
|
-
ConsoleWriter.info("Include package.json and package-lock.json;");
|
|
108
|
-
ConsoleWriter.info("Not include node_modules folder");
|
|
109
|
-
ConsoleWriter.info("Run npm install expect no errors");
|
|
110
|
-
ConsoleWriter.info("Run pbiviz package expect no errors");
|
|
111
|
-
ConsoleWriter.info("The compiled package of the Custom Visual should match submitted package.");
|
|
112
|
-
ConsoleWriter.info("npm audit command must not return any alerts with high or moderate level.");
|
|
113
|
-
ConsoleWriter.info("The project must include Tslint from Microsoft with no overridden configuration, and this command shouldn’t return any tslint errors.");
|
|
114
|
-
ConsoleWriter.info("https://www.npmjs.com/package/tslint-microsoft-contrib");
|
|
115
|
-
ConsoleWriter.info("Ensure no arbitrary/dynamic code is run (bad: eval(), unsafe use of settimeout(), requestAnimationFrame(), setinterval(some function with user input).. running user input/data etc.)");
|
|
116
|
-
ConsoleWriter.info("Ensure DOM is manipulated safely (bad: innerHTML, D3.html(<some user/data input>), unsanitized user input/data directly added to DOM, etc.)");
|
|
117
|
-
ConsoleWriter.info("Ensure no js errors/exceptions in browser console for any input data. As test dataset please use this sample report");
|
|
118
|
-
ConsoleWriter.blank();
|
|
119
|
-
ConsoleWriter.info("Full description of certification requirements you can find in documentation:");
|
|
120
|
-
ConsoleWriter.info("https://docs.microsoft.com/en-us/power-bi/power-bi-custom-visuals-certified#certification-requirements");
|
|
121
|
-
}
|
|
122
|
-
|
package/bin/pbiviz-start.js
DELETED
|
@@ -1,142 +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 program = require('commander');
|
|
30
|
-
const compareVersions = require("compare-versions");
|
|
31
|
-
const fs = require('fs-extra');
|
|
32
|
-
const path = require('path');
|
|
33
|
-
const webpack = require("webpack");
|
|
34
|
-
|
|
35
|
-
const config = require('../config.json');
|
|
36
|
-
const VisualPackage = require('../lib/VisualPackage');
|
|
37
|
-
const WebpackDevServer = require("webpack-dev-server");
|
|
38
|
-
const ConsoleWriter = require('../lib/ConsoleWriter');
|
|
39
|
-
const WebPackWrap = require('../lib/WebPackWrap');
|
|
40
|
-
const CommandHelpManager = require('../lib/CommandHelpManager');
|
|
41
|
-
|
|
42
|
-
const options = process.argv;
|
|
43
|
-
const minAPIversion = config.constants.minAPIversion;
|
|
44
|
-
|
|
45
|
-
program
|
|
46
|
-
.option('-p, --port [port]', 'set the port listening on')
|
|
47
|
-
.option('-m, --mute', 'mute error outputs')
|
|
48
|
-
.option('-d, --drop', 'drop outputs into output folder')
|
|
49
|
-
.option('--no-stats', "Doesn't generate statistics files");
|
|
50
|
-
|
|
51
|
-
if (options.some(option => option === '--help' || option === '-h')) {
|
|
52
|
-
program.help(CommandHelpManager.createSubCommandHelpCallback(options));
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
program.parse(options);
|
|
57
|
-
|
|
58
|
-
let cwd = process.cwd();
|
|
59
|
-
let server;
|
|
60
|
-
VisualPackage.loadVisualPackage(cwd).then((visualPackage) => {
|
|
61
|
-
if (visualPackage.config.apiVersion && compareVersions.compare(visualPackage.config.apiVersion, minAPIversion, "<")) {
|
|
62
|
-
ConsoleWriter.error(`Can't start the visual because of the current API is '${visualPackage.config.apiVersion}'.
|
|
63
|
-
Please use 'powerbi-visuals-api' ${minAPIversion} or above to build a visual.`);
|
|
64
|
-
throw new Error(`Invalid API version.`);
|
|
65
|
-
}
|
|
66
|
-
new WebPackWrap().applyWebpackConfig(visualPackage, {
|
|
67
|
-
devMode: true,
|
|
68
|
-
devtool: "source-map",
|
|
69
|
-
generateResources: true,
|
|
70
|
-
generatePbiviz: false,
|
|
71
|
-
minifyJS: false,
|
|
72
|
-
minify: false,
|
|
73
|
-
devServerPort: program.port,
|
|
74
|
-
disableStats: !program.stats
|
|
75
|
-
})
|
|
76
|
-
.then(({ webpackConfig }) => {
|
|
77
|
-
let compiler = webpack(webpackConfig);
|
|
78
|
-
ConsoleWriter.blank();
|
|
79
|
-
ConsoleWriter.info('Starting server...');
|
|
80
|
-
// webpack dev server serves bundle from disk instead memory
|
|
81
|
-
if (program.drop) {
|
|
82
|
-
webpackConfig.devServer.onBeforeSetupMiddleware = (devServer) => {
|
|
83
|
-
let setHeaders = (res) => {
|
|
84
|
-
Object.getOwnPropertyNames(webpackConfig.devServer.headers)
|
|
85
|
-
.forEach(property => res.header(property, webpackConfig.devServer.headers[property]));
|
|
86
|
-
};
|
|
87
|
-
let readFile = (file, res) => {
|
|
88
|
-
fs.readFile(file).then(function (content) {
|
|
89
|
-
res.write(content);
|
|
90
|
-
res.end();
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
[
|
|
94
|
-
'visual.js`',
|
|
95
|
-
'visual.css',
|
|
96
|
-
'pbiviz.json'
|
|
97
|
-
].forEach(asset => {
|
|
98
|
-
devServer.app.get(`${webpackConfig.devServer.publicPath}/${asset}`, function (req, res) {
|
|
99
|
-
setHeaders(res);
|
|
100
|
-
readFile(path.join(webpackConfig.devServer.static.directory, asset), res);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
server = new WebpackDevServer({
|
|
107
|
-
...webpackConfig.devServer,
|
|
108
|
-
client: false,
|
|
109
|
-
hot: false,
|
|
110
|
-
devMiddleware: {
|
|
111
|
-
writeToDisk: true
|
|
112
|
-
}
|
|
113
|
-
}, compiler);
|
|
114
|
-
|
|
115
|
-
(async () => {
|
|
116
|
-
await server.start();
|
|
117
|
-
ConsoleWriter.info(`Server listening on port ${webpackConfig.devServer.port}`);
|
|
118
|
-
})();
|
|
119
|
-
|
|
120
|
-
})
|
|
121
|
-
.catch(e => {
|
|
122
|
-
ConsoleWriter.error(e.message);
|
|
123
|
-
process.exit(1);
|
|
124
|
-
});
|
|
125
|
-
}).catch(e => {
|
|
126
|
-
ConsoleWriter.error('LOAD ERROR', e);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
//clean up
|
|
131
|
-
function stopServer() {
|
|
132
|
-
ConsoleWriter.blank();
|
|
133
|
-
ConsoleWriter.info("Stopping server...");
|
|
134
|
-
if (server) {
|
|
135
|
-
server.close();
|
|
136
|
-
server = null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
process.on('SIGINT', stopServer);
|
|
141
|
-
process.on('SIGTERM', stopServer);
|
|
142
|
-
|
|
@@ -1,51 +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 path = require('path');
|
|
30
|
-
let basename = path.basename;
|
|
31
|
-
let targetString = "Usage:";
|
|
32
|
-
|
|
33
|
-
class CommandHelpmanager {
|
|
34
|
-
static createSubCommandHelpCallback(options) {
|
|
35
|
-
return (txt) => {
|
|
36
|
-
let targetPosition = txt.indexOf(targetString);
|
|
37
|
-
let preparedHelp = "";
|
|
38
|
-
let subCommandName = basename(options[1], ".js").replace("-", " ");
|
|
39
|
-
|
|
40
|
-
if (targetPosition !== -1) {
|
|
41
|
-
targetPosition += targetString.length + 1;
|
|
42
|
-
preparedHelp = [txt.slice(0, targetPosition), subCommandName, txt.slice(targetPosition)].join('');
|
|
43
|
-
return preparedHelp;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return txt;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = CommandHelpmanager;
|
package/lib/VisualPackage.js
DELETED
|
@@ -1,118 +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 VisualGenerator = require('../lib/VisualGenerator');
|
|
32
|
-
let childProcess = require('child_process');
|
|
33
|
-
let ConsoleWriter = require('../lib/ConsoleWriter');
|
|
34
|
-
|
|
35
|
-
const CONFIG_FILE = 'pbiviz.json';
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Represents an instance of a visual package based on file path
|
|
39
|
-
*/
|
|
40
|
-
class VisualPackage {
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new visual package
|
|
43
|
-
*
|
|
44
|
-
* @param {string} rootPath - file path to root of visual package
|
|
45
|
-
* @param {string} visualName - name of the visual to create in the rootPath
|
|
46
|
-
* @param {object} generateOptions - options for the visual generator
|
|
47
|
-
* <VisualPackage>} - instance of newly created visual package
|
|
48
|
-
*/
|
|
49
|
-
static createVisualPackage(rootPath, visualName, generateOptions) {
|
|
50
|
-
return VisualGenerator.generate(rootPath, visualName, generateOptions)
|
|
51
|
-
.then((visualPath) => VisualPackage.installPackages(visualPath)
|
|
52
|
-
.then(() => visualPath)
|
|
53
|
-
)
|
|
54
|
-
.then((visualPath) => VisualPackage.loadVisualPackage(visualPath));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Loads an instance of a visual package from a file path
|
|
59
|
-
*
|
|
60
|
-
* @param {string} rootPath - file path to root of visual package
|
|
61
|
-
* @returns {Promise<VisualPackage>} - instance of newly created visual package
|
|
62
|
-
*/
|
|
63
|
-
static loadVisualPackage(rootPath) {
|
|
64
|
-
return new Promise((resolve, reject) => {
|
|
65
|
-
try {
|
|
66
|
-
resolve(new VisualPackage(rootPath));
|
|
67
|
-
} catch (e) {
|
|
68
|
-
if (e && e.code && e.code === 'ENOENT') {
|
|
69
|
-
return reject(new Error(CONFIG_FILE + ' not found. You must be in the root of a visual project to run this command.'));
|
|
70
|
-
}
|
|
71
|
-
reject(e);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Install npm dependencies for visual
|
|
78
|
-
* @param {string} rootPath - file path to root of visual package
|
|
79
|
-
* @static
|
|
80
|
-
* @returns {Promise<void>}
|
|
81
|
-
* @memberof VisualPackage
|
|
82
|
-
*/
|
|
83
|
-
static installPackages(visualPath) {
|
|
84
|
-
return new Promise(function (resolve, reject) {
|
|
85
|
-
ConsoleWriter.info('Installing packages...');
|
|
86
|
-
childProcess.exec(`npm install`, { cwd: visualPath },
|
|
87
|
-
(err) => {
|
|
88
|
-
if (err) {
|
|
89
|
-
reject(new Error('Package install failed.'));
|
|
90
|
-
} else {
|
|
91
|
-
ConsoleWriter.info('Installed packages.');
|
|
92
|
-
resolve();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Creates a VisualPackage instance
|
|
100
|
-
*
|
|
101
|
-
* @param {string} rootPath - file path to root of visual package
|
|
102
|
-
*/
|
|
103
|
-
constructor(rootPath) {
|
|
104
|
-
this.basePath = rootPath;
|
|
105
|
-
this.config = fs.readJsonSync(this.buildPath(CONFIG_FILE));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Builds a path starting from the package base path
|
|
110
|
-
*
|
|
111
|
-
* @param {...*} arguments - arguments passed through to path.join
|
|
112
|
-
*/
|
|
113
|
-
buildPath() {
|
|
114
|
-
return path.join.apply(this, [this.basePath].concat(Array.from(arguments)));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = VisualPackage;
|