-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhostwidget.mjs
46 lines (38 loc) · 1.36 KB
/
hostwidget.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fs from 'fs';
import path from 'path';
import { spawnSync } from 'child_process';
const scaffoldWidgetPrefix = "azure-api-management-widget-";
const distPath = "./dist";
if (process.argv.length > 2) {
const componentName = process.argv[2].toLowerCase();
let npmCmd = "npm";
let npxCmd = "npx";
if (process.platform === 'win32') {
npmCmd = "npm.cmd";
npxCmd = "npx.cmd";
}
function getWidgetScaffoldPath(componentName) {
const scaffoldWidgetName = scaffoldWidgetPrefix + componentName.toLowerCase();
const scaffoldWidgetPath = path.join(distPath, scaffoldWidgetName);
return scaffoldWidgetPath;
}
console.log(`React Component Toolkit - Widget Packager - ${componentName}`);
const widgetPath = getWidgetScaffoldPath(componentName);
if (!fs.existsSync(widgetPath)) {
console.log("");
console.log("ERROR: Either that widget has not been packaged or a widget does not exist with that name.");
console.log("");
console.log(" To package your component as an APIM widget:");
console.log("");
console.log(" npm run packagewidget <componentName>");
console.log("");
process.exit(1);
}
console.log("Testing Widget to in local host mode...");
spawnSync(npmCmd, ["run", "host"], { cwd: widgetPath, stdio: 'inherit' });
}
else
{
console.log("");
console.log("Incorrect parameters specified.");
}