-
Notifications
You must be signed in to change notification settings - Fork 7
/
deploywidget.mjs
57 lines (46 loc) · 1.72 KB
/
deploywidget.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
47
48
49
50
51
52
53
54
55
56
57
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;
}
function confirmContinuation() {
const userInput = prompt("Are you sure you want to continue (if the widget already exists in your portal, it will be overwritten)? (Type 'YES' to proceed)");
if (userInput === null || userInput.trim().toUpperCase() !== "YES") {
console.log("Exiting script...");
process.exit(1);
}
return;
}
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("Deploying Widget to APIM portal...");
spawnSync(npmCmd, ["run", "deploy"], { cwd: widgetPath, stdio: 'inherit' });
}
else
{
console.log("");
console.log("Incorrect parameters specified.");
}