@webiny/pulumi-sdk 0.0.0-ee-vpcs.549378cf03
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/LICENSE +21 -0
- package/Pulumi.d.ts +41 -0
- package/Pulumi.js +148 -0
- package/Pulumi.js.map +1 -0
- package/README.md +76 -0
- package/downloadBinaries.d.ts +2 -0
- package/downloadBinaries.js +105 -0
- package/downloadBinaries.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Pulumi.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import execa from "execa";
|
|
2
|
+
declare type Command = string | string[];
|
|
3
|
+
export interface PulumiArgs {
|
|
4
|
+
[key: string]: string | boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ExecaArgs {
|
|
7
|
+
env?: {
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface Options {
|
|
13
|
+
args?: PulumiArgs;
|
|
14
|
+
execa?: ExecaArgs;
|
|
15
|
+
beforePulumiInstall?: () => any;
|
|
16
|
+
afterPulumiInstall?: () => any;
|
|
17
|
+
pulumiFolder?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RunArgs {
|
|
20
|
+
command: Command;
|
|
21
|
+
args?: PulumiArgs;
|
|
22
|
+
execa?: ExecaArgs;
|
|
23
|
+
beforePulumiInstall?: () => any;
|
|
24
|
+
afterPulumiInstall?: () => any;
|
|
25
|
+
}
|
|
26
|
+
export interface InstallArgs {
|
|
27
|
+
beforePulumiInstall?: () => any;
|
|
28
|
+
afterPulumiInstall?: () => any;
|
|
29
|
+
}
|
|
30
|
+
export declare const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
31
|
+
export declare class Pulumi {
|
|
32
|
+
options: Options;
|
|
33
|
+
pulumiFolder: string;
|
|
34
|
+
pulumiDownloadFolder: string;
|
|
35
|
+
pulumiBinaryPath: string;
|
|
36
|
+
constructor(options?: Options);
|
|
37
|
+
run(rawArgs: RunArgs): execa.ExecaChildProcess<string>;
|
|
38
|
+
install(rawArgs?: InstallArgs): Promise<boolean>;
|
|
39
|
+
ensureAwsPluginIsInstalled(): execa.ExecaSyncReturnValue<string> | undefined;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
package/Pulumi.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.Pulumi = exports.FLAG_NON_INTERACTIVE = void 0;
|
|
11
|
+
|
|
12
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _set2 = _interopRequireDefault(require("lodash/set"));
|
|
17
|
+
|
|
18
|
+
var _kebabCase2 = _interopRequireDefault(require("lodash/kebabCase"));
|
|
19
|
+
|
|
20
|
+
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
21
|
+
|
|
22
|
+
var _os = _interopRequireDefault(require("os"));
|
|
23
|
+
|
|
24
|
+
var _execa = _interopRequireDefault(require("execa"));
|
|
25
|
+
|
|
26
|
+
var path = _interopRequireWildcard(require("path"));
|
|
27
|
+
|
|
28
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
29
|
+
|
|
30
|
+
var _downloadBinaries = _interopRequireDefault(require("./downloadBinaries"));
|
|
31
|
+
|
|
32
|
+
const FLAG_NON_INTERACTIVE = "--non-interactive";
|
|
33
|
+
exports.FLAG_NON_INTERACTIVE = FLAG_NON_INTERACTIVE;
|
|
34
|
+
|
|
35
|
+
class Pulumi {
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
38
|
+
(0, _defineProperty2.default)(this, "pulumiFolder", void 0);
|
|
39
|
+
(0, _defineProperty2.default)(this, "pulumiDownloadFolder", void 0);
|
|
40
|
+
(0, _defineProperty2.default)(this, "pulumiBinaryPath", void 0);
|
|
41
|
+
this.options = options;
|
|
42
|
+
this.pulumiDownloadFolder = path.join(options.pulumiFolder || process.cwd(), "pulumi-cli", _os.default.platform());
|
|
43
|
+
this.pulumiFolder = path.join(this.pulumiDownloadFolder, "pulumi");
|
|
44
|
+
this.pulumiBinaryPath = path.join(this.pulumiFolder, "pulumi");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
run(rawArgs) {
|
|
48
|
+
this.ensureAwsPluginIsInstalled();
|
|
49
|
+
const args = (0, _merge2.default)({}, this.options, rawArgs);
|
|
50
|
+
|
|
51
|
+
if (!Array.isArray(args.command)) {
|
|
52
|
+
args.command = [args.command];
|
|
53
|
+
} // 1. Prepare Pulumi args.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const finalArgs = [];
|
|
57
|
+
|
|
58
|
+
for (const key in args.args) {
|
|
59
|
+
const value = args.args[key];
|
|
60
|
+
|
|
61
|
+
if (!value) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
for (let i = 0; i < value.length; i++) {
|
|
67
|
+
finalArgs.push(`--${(0, _kebabCase2.default)(key)}`, value[i]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof value === "boolean") {
|
|
74
|
+
finalArgs.push(`--${(0, _kebabCase2.default)(key)}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
finalArgs.push(`--${(0, _kebabCase2.default)(key)}`, value);
|
|
79
|
+
} // Prepare execa args.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if (!args.execa) {
|
|
83
|
+
args.execa = {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
(0, _set2.default)(args.execa, "env.PULUMI_SKIP_UPDATE_CHECK", "true");
|
|
87
|
+
(0, _set2.default)(args.execa, "env.PULUMI_HOME", this.pulumiFolder);
|
|
88
|
+
|
|
89
|
+
if (_os.default.arch() === "arm64") {
|
|
90
|
+
/**
|
|
91
|
+
* This variable is an attempt to resolve this issue:
|
|
92
|
+
* https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/
|
|
93
|
+
*/
|
|
94
|
+
(0, _set2.default)(args.execa, "env.GODEBUG", "asyncpreemptoff=1");
|
|
95
|
+
} // Use ";" when on Windows. For Mac and Linux, use ":".
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const PATH_SEPARATOR = _os.default.platform() === "win32" ? ";" : ":";
|
|
99
|
+
const execaArgs = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, args.execa), {}, {
|
|
100
|
+
env: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, args.execa.env || {}), {}, {
|
|
101
|
+
/**
|
|
102
|
+
* Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this
|
|
103
|
+
* commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,
|
|
104
|
+
* we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve
|
|
105
|
+
* plugins necessary for custom resources and dynamic providers to work.
|
|
106
|
+
*/
|
|
107
|
+
PATH: process.env.PATH + PATH_SEPARATOR + this.pulumiFolder
|
|
108
|
+
})
|
|
109
|
+
}); // We want to keep the "interactive" output format of the Pulumi command when `--preview` flag is passed in.
|
|
110
|
+
|
|
111
|
+
const flags = args.command && args.command.includes("preview") ? [] : [FLAG_NON_INTERACTIVE];
|
|
112
|
+
return (0, _execa.default)(this.pulumiBinaryPath, [...args.command, ...finalArgs, ...flags], execaArgs);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async install(rawArgs) {
|
|
116
|
+
const args = (0, _merge2.default)({}, this.options, rawArgs);
|
|
117
|
+
const installed = await (0, _downloadBinaries.default)(this.pulumiDownloadFolder, args.beforePulumiInstall, args.afterPulumiInstall);
|
|
118
|
+
|
|
119
|
+
if (installed) {
|
|
120
|
+
this.ensureAwsPluginIsInstalled();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return installed;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
ensureAwsPluginIsInstalled() {
|
|
127
|
+
const {
|
|
128
|
+
version
|
|
129
|
+
} = require("@pulumi/aws/package.json");
|
|
130
|
+
|
|
131
|
+
const pluginExists = _fsExtra.default.pathExistsSync(path.join(this.pulumiFolder, "plugins", `resource-aws-${version}`, "pulumi-resource-aws"));
|
|
132
|
+
|
|
133
|
+
if (pluginExists) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return _execa.default.sync(this.pulumiBinaryPath, ["plugin", "install", "resource", "aws", version], {
|
|
138
|
+
stdio: "inherit",
|
|
139
|
+
env: {
|
|
140
|
+
PULUMI_HOME: this.pulumiFolder,
|
|
141
|
+
PULUMI_SKIP_UPDATE_CHECK: "true"
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
exports.Pulumi = Pulumi;
|
package/Pulumi.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FLAG_NON_INTERACTIVE","Pulumi","constructor","options","pulumiDownloadFolder","path","join","pulumiFolder","process","cwd","os","platform","pulumiBinaryPath","run","rawArgs","ensureAwsPluginIsInstalled","args","Array","isArray","command","finalArgs","key","value","i","length","push","execa","arch","PATH_SEPARATOR","execaArgs","env","PATH","flags","includes","install","installed","downloadBinaries","beforePulumiInstall","afterPulumiInstall","version","require","pluginExists","fs","pathExistsSync","sync","stdio","PULUMI_HOME","PULUMI_SKIP_UPDATE_CHECK"],"sources":["Pulumi.ts"],"sourcesContent":["import os from \"os\";\nimport execa from \"execa\";\nimport * as path from \"path\";\nimport fs from \"fs-extra\";\nimport { merge, kebabCase, set } from \"lodash\";\nimport downloadBinaries from \"./downloadBinaries\";\n\ntype Command = string | string[];\n\nexport interface PulumiArgs {\n [key: string]: string | boolean;\n}\n\nexport interface ExecaArgs {\n env?: {\n [key: string]: string | undefined;\n };\n [key: string]: any;\n}\n\nexport interface Options {\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n\n // A folder into which the Pulumi CLI, along with all of its meta data and config files, will be set up.\n // It's recommended this folder is not checked in into a code repository, since the Pulumi CLI can store\n // sensitive information here, for example - user's Pulumi Service credentials.\n pulumiFolder?: string;\n}\n\nexport interface RunArgs {\n command: Command;\n\n args?: PulumiArgs;\n execa?: ExecaArgs;\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport interface InstallArgs {\n beforePulumiInstall?: () => any;\n afterPulumiInstall?: () => any;\n}\n\nexport const FLAG_NON_INTERACTIVE = \"--non-interactive\";\n\nexport class Pulumi {\n options: Options;\n pulumiFolder: string;\n pulumiDownloadFolder: string;\n pulumiBinaryPath: string;\n constructor(options: Options = {}) {\n this.options = options;\n\n this.pulumiDownloadFolder = path.join(\n options.pulumiFolder || process.cwd(),\n \"pulumi-cli\",\n os.platform()\n );\n\n this.pulumiFolder = path.join(this.pulumiDownloadFolder, \"pulumi\");\n this.pulumiBinaryPath = path.join(this.pulumiFolder, \"pulumi\");\n }\n\n run(rawArgs: RunArgs) {\n this.ensureAwsPluginIsInstalled();\n\n const args = merge({}, this.options, rawArgs);\n\n if (!Array.isArray(args.command)) {\n args.command = [args.command];\n }\n\n // 1. Prepare Pulumi args.\n const finalArgs = [];\n for (const key in args.args) {\n const value = args.args[key];\n if (!value) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n finalArgs.push(`--${kebabCase(key)}`, value[i]);\n }\n continue;\n }\n\n if (typeof value === \"boolean\") {\n finalArgs.push(`--${kebabCase(key)}`);\n continue;\n }\n\n finalArgs.push(`--${kebabCase(key)}`, value);\n }\n\n // Prepare execa args.\n if (!args.execa) {\n args.execa = {};\n }\n\n set(args.execa, \"env.PULUMI_SKIP_UPDATE_CHECK\", \"true\");\n set(args.execa, \"env.PULUMI_HOME\", this.pulumiFolder);\n\n if (os.arch() === \"arm64\") {\n /**\n * This variable is an attempt to resolve this issue:\n * https://yaleman.org/post/2021/2021-01-01-apple-m1-terraform-and-golang/\n */\n set(args.execa, \"env.GODEBUG\", \"asyncpreemptoff=1\");\n }\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const execaArgs = {\n ...args.execa,\n env: {\n ...(args.execa.env || {}),\n /**\n * Due to an issue with Pulumi https://github.com/pulumi/pulumi/issues/8374, and even though this\n * commit suggests it should already work like that https://github.com/pulumi/pulumi/commit/c878916901a997a9c0ffcbed23560e19e224a6f1,\n * we need to specify the exact location of our Pulumi binaries, using the PATH environment variable, so it can correctly resolve\n * plugins necessary for custom resources and dynamic providers to work.\n */\n PATH: process.env.PATH + PATH_SEPARATOR + this.pulumiFolder\n }\n };\n\n // We want to keep the \"interactive\" output format of the Pulumi command when `--preview` flag is passed in.\n const flags =\n args.command && args.command.includes(\"preview\") ? [] : [FLAG_NON_INTERACTIVE];\n\n return execa(this.pulumiBinaryPath, [...args.command, ...finalArgs, ...flags], execaArgs);\n }\n\n async install(rawArgs?: InstallArgs): Promise<boolean> {\n const args = merge({}, this.options, rawArgs);\n\n const installed = await downloadBinaries(\n this.pulumiDownloadFolder,\n args.beforePulumiInstall,\n args.afterPulumiInstall\n );\n\n if (installed) {\n this.ensureAwsPluginIsInstalled();\n }\n\n return installed;\n }\n\n ensureAwsPluginIsInstalled() {\n const { version } = require(\"@pulumi/aws/package.json\");\n\n const pluginExists = fs.pathExistsSync(\n path.join(\n this.pulumiFolder,\n \"plugins\",\n `resource-aws-${version}`,\n \"pulumi-resource-aws\"\n )\n );\n\n if (pluginExists) {\n return;\n }\n\n return execa.sync(\n this.pulumiBinaryPath,\n [\"plugin\", \"install\", \"resource\", \"aws\", version],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](https://www.npmjs.com/package/@webiny/pulumi-sdk)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/pulumi-sdk)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
A simple Pulumi Node.JS SDK - programmatically execute Pulumi CLI commands within your Node.js scripts.
|
|
8
|
+
|
|
9
|
+
### Example
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const { Pulumi } = require("@webiny/pulumi-sdk");
|
|
13
|
+
|
|
14
|
+
// Create a new instance of Pulumi class.
|
|
15
|
+
// Note that Pulumi will be installed automatically on first use, you don't need to install it
|
|
16
|
+
// manually first. That's why the `beforePulumiInstall` and `afterPulumiInstall` are exposed.
|
|
17
|
+
const pulumi = new Pulumi({
|
|
18
|
+
execa: {
|
|
19
|
+
cwd: stacksDir,
|
|
20
|
+
env: { PULUMI_CONFIG_PASSPHRASE: process.env.PULUMI_CONFIG_PASSPHRASE }
|
|
21
|
+
},
|
|
22
|
+
args: {
|
|
23
|
+
secretsProvider: "passphrase"
|
|
24
|
+
},
|
|
25
|
+
beforePulumiInstall: () => {
|
|
26
|
+
console.log(
|
|
27
|
+
`💡 It looks like this is your first time using ${green(
|
|
28
|
+
"@webiny/pulumi-sdk"
|
|
29
|
+
)}.`
|
|
30
|
+
);
|
|
31
|
+
spinner.start(`Downloading Pulumi...`);
|
|
32
|
+
},
|
|
33
|
+
afterPulumiInstall: () => {
|
|
34
|
+
spinner.stopAndPersist({
|
|
35
|
+
symbol: green("✔"),
|
|
36
|
+
text: `Pulumi downloaded, continuing...`
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Use existing stack if possible, otherwise create a new one.
|
|
42
|
+
let stackExists = true;
|
|
43
|
+
try {
|
|
44
|
+
const { process } = await pulumi.run({ command: ["stack", "select", env] });
|
|
45
|
+
await process;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
stackExists = false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!stackExists) {
|
|
51
|
+
const { process } = await pulumi.run({ command: ["stack", "init", env] });
|
|
52
|
+
await process;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If isPreview was set to true in our script, then run `preview` command, otherwise `up`.
|
|
56
|
+
if (isPreview) {
|
|
57
|
+
const pulumi = new Pulumi();
|
|
58
|
+
const { toConsole } = await pulumi.run({
|
|
59
|
+
command: "preview",
|
|
60
|
+
execa: {
|
|
61
|
+
cwd: stacksDir,
|
|
62
|
+
env: { PULUMI_CONFIG_PASSPHRASE: process.env.PULUMI_CONFIG_PASSPHRASE }
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
await toConsole();
|
|
66
|
+
} else {
|
|
67
|
+
const { toConsole } = await pulumi.run({
|
|
68
|
+
command: "up",
|
|
69
|
+
args: {
|
|
70
|
+
yes: true,
|
|
71
|
+
skipPreview: true
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
await toConsole();
|
|
75
|
+
}
|
|
76
|
+
```
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
const os = require("os");
|
|
9
|
+
|
|
10
|
+
const tar = require("tar");
|
|
11
|
+
|
|
12
|
+
const fs = require("fs");
|
|
13
|
+
|
|
14
|
+
const download = require("download");
|
|
15
|
+
|
|
16
|
+
const path = require("path");
|
|
17
|
+
|
|
18
|
+
const decompress = require("decompress");
|
|
19
|
+
|
|
20
|
+
const semver = require("semver"); // We gotta sanitize the package version, since on a few occasions, we've detected the Pulumi version
|
|
21
|
+
// can look like the following: "2.25.2+dirty". We want to ensure only "2.25.2" is returned.
|
|
22
|
+
// @see https://github.com/pulumi/pulumi/issues/6847
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const getPulumiVersion = () => {
|
|
26
|
+
const {
|
|
27
|
+
version
|
|
28
|
+
} = require("@pulumi/pulumi/package.json");
|
|
29
|
+
|
|
30
|
+
return semver.clean(version);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var _default = async (downloadFolder, beforeInstall, afterInstall) => {
|
|
34
|
+
if (fs.existsSync(downloadFolder)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof beforeInstall === "function") {
|
|
39
|
+
await beforeInstall();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const platform = os.platform();
|
|
43
|
+
|
|
44
|
+
switch (platform) {
|
|
45
|
+
case "darwin":
|
|
46
|
+
await setupDarwin(downloadFolder);
|
|
47
|
+
break;
|
|
48
|
+
|
|
49
|
+
case "linux":
|
|
50
|
+
await setupLinux(downloadFolder);
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case "win32":
|
|
54
|
+
await setupWindows(downloadFolder);
|
|
55
|
+
break;
|
|
56
|
+
|
|
57
|
+
default:
|
|
58
|
+
throw Error(`Cannot download Pulumi binaries - platform "${platform}" not supported. Supported ones are "darwin", "linux", and "win32"`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (typeof afterInstall === "function") {
|
|
62
|
+
await afterInstall();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.default = _default;
|
|
69
|
+
|
|
70
|
+
async function setupDarwin(downloadFolder) {
|
|
71
|
+
const version = getPulumiVersion();
|
|
72
|
+
const filename = `pulumi-v${version}-darwin-x64.tar.gz`;
|
|
73
|
+
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
74
|
+
await download(downloadUrl, downloadFolder);
|
|
75
|
+
await tar.extract({
|
|
76
|
+
cwd: downloadFolder,
|
|
77
|
+
file: path.join(downloadFolder, filename)
|
|
78
|
+
});
|
|
79
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function setupWindows(downloadFolder) {
|
|
83
|
+
const version = getPulumiVersion();
|
|
84
|
+
const filename = `pulumi-v${version}-windows-x64.zip`;
|
|
85
|
+
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
86
|
+
await download(downloadUrl, downloadFolder);
|
|
87
|
+
const archive = path.join(downloadFolder, filename);
|
|
88
|
+
const destination = path.join(downloadFolder, "pulumi");
|
|
89
|
+
await decompress(archive, destination, {
|
|
90
|
+
strip: 2
|
|
91
|
+
});
|
|
92
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function setupLinux(downloadFolder) {
|
|
96
|
+
const version = getPulumiVersion();
|
|
97
|
+
const filename = `pulumi-v${version}-linux-x64.tar.gz`;
|
|
98
|
+
const downloadUrl = "https://get.pulumi.com/releases/sdk/" + filename;
|
|
99
|
+
await download(downloadUrl, downloadFolder);
|
|
100
|
+
await tar.extract({
|
|
101
|
+
cwd: downloadFolder,
|
|
102
|
+
file: path.join(downloadFolder, filename)
|
|
103
|
+
});
|
|
104
|
+
fs.unlinkSync(path.join(downloadFolder, filename));
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["os","require","tar","fs","download","path","decompress","semver","getPulumiVersion","version","clean","downloadFolder","beforeInstall","afterInstall","existsSync","platform","setupDarwin","setupLinux","setupWindows","Error","filename","downloadUrl","extract","cwd","file","join","unlinkSync","archive","destination","strip"],"sources":["downloadBinaries.ts"],"sourcesContent":["const os = require(\"os\");\nconst tar = require(\"tar\");\nconst fs = require(\"fs\");\nconst download = require(\"download\");\nconst path = require(\"path\");\nconst decompress = require(\"decompress\");\nconst semver = require(\"semver\");\n\n// We gotta sanitize the package version, since on a few occasions, we've detected the Pulumi version\n// can look like the following: \"2.25.2+dirty\". We want to ensure only \"2.25.2\" is returned.\n// @see https://github.com/pulumi/pulumi/issues/6847\nconst getPulumiVersion = () => {\n const { version } = require(\"@pulumi/pulumi/package.json\");\n return semver.clean(version);\n};\n\nexport default async (\n downloadFolder: string,\n beforeInstall?: () => void,\n afterInstall?: () => void\n) => {\n if (fs.existsSync(downloadFolder)) {\n return false;\n }\n\n if (typeof beforeInstall === \"function\") {\n await beforeInstall();\n }\n\n const platform = os.platform();\n switch (platform) {\n case \"darwin\":\n await setupDarwin(downloadFolder);\n break;\n case \"linux\":\n await setupLinux(downloadFolder);\n break;\n case \"win32\":\n await setupWindows(downloadFolder);\n break;\n default:\n throw Error(\n `Cannot download Pulumi binaries - platform \"${platform}\" not supported. Supported ones are \"darwin\", \"linux\", and \"win32\"`\n );\n }\n\n if (typeof afterInstall === \"function\") {\n await afterInstall();\n }\n\n return true;\n};\n\nasync function setupDarwin(downloadFolder: string) {\n const version = getPulumiVersion();\n const filename = `pulumi-v${version}-darwin-x64.tar.gz`;\n const downloadUrl = \"https://get.pulumi.com/releases/sdk/\" + filename;\n\n await download(downloadUrl, downloadFolder);\n\n await tar.extract({\n cwd: downloadFolder,\n file: path.join(downloadFolder, filename)\n });\n\n fs.unlinkSync(path.join(downloadFolder, filename));\n}\n\nasync function setupWindows(downloadFolder: string) {\n const version = getPulumiVersion();\n const filename = `pulumi-v${version}-windows-x64.zip`;\n const downloadUrl = \"https://get.pulumi.com/releases/sdk/\" + filename;\n\n await download(downloadUrl, downloadFolder);\n\n const archive = path.join(downloadFolder, filename);\n const destination = path.join(downloadFolder, \"pulumi\");\n await decompress(archive, destination, { strip: 2 });\n\n fs.unlinkSync(path.join(downloadFolder, filename));\n}\n\nasync function setupLinux(downloadFolder: string) {\n const version = getPulumiVersion();\n const filename = `pulumi-v${version}-linux-x64.tar.gz`;\n const downloadUrl = \"https://get.pulumi.com/releases/sdk/\" + filename;\n\n await download(downloadUrl, downloadFolder);\n\n await tar.extract({\n cwd: downloadFolder,\n file: path.join(downloadFolder, filename)\n });\n\n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MhB,QAAQ,CAACiB,WAAD,EAAcV,cAAd,CAAd;EAEA,MAAMT,GAAG,CAACoB,OAAJ,CAAY;IACdC,GAAG,EAAEZ,cADS;IAEda,IAAI,EAAEnB,IAAI,CAACoB,IAAL,CAAUd,cAAV,EAA0BS,QAA1B;EAFQ,CAAZ,CAAN;EAKAjB,EAAE,CAACuB,UAAH,CAAcrB,IAAI,CAACoB,IAAL,CAAUd,cAAV,EAA0BS,QAA1B,CAAd;AACH"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Pulumi";
|
package/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _Pulumi = require("./Pulumi");
|
|
8
|
+
|
|
9
|
+
Object.keys(_Pulumi).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _Pulumi[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Pulumi[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Pulumi\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/pulumi-sdk",
|
|
3
|
+
"version": "0.0.0-ee-vpcs.549378cf03",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "A simple Node.js Pulumi SDK.",
|
|
10
|
+
"author": "Webiny Ltd",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"directory": "dist"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@pulumi/aws": "^5.8.0",
|
|
18
|
+
"@pulumi/pulumi": "^3.34.0",
|
|
19
|
+
"decompress": "4.2.1",
|
|
20
|
+
"download": "5.0.3",
|
|
21
|
+
"execa": "5.1.1",
|
|
22
|
+
"fs-extra": "9.1.0",
|
|
23
|
+
"lodash": "4.17.21",
|
|
24
|
+
"semver": "7.3.8",
|
|
25
|
+
"tar": "6.1.11"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@babel/cli": "^7.19.3",
|
|
29
|
+
"@babel/core": "^7.19.3",
|
|
30
|
+
"@types/lodash": "^4.14.190",
|
|
31
|
+
"@types/node": "*",
|
|
32
|
+
"@webiny/cli": "^0.0.0-ee-vpcs.549378cf03",
|
|
33
|
+
"@webiny/project-utils": "^0.0.0-ee-vpcs.549378cf03",
|
|
34
|
+
"rimraf": "^3.0.2",
|
|
35
|
+
"typescript": "4.7.4"
|
|
36
|
+
},
|
|
37
|
+
"adio": {
|
|
38
|
+
"ignore": {
|
|
39
|
+
"dependencies": [
|
|
40
|
+
"@pulumi/pulumi",
|
|
41
|
+
"@pulumi/aws"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "yarn webiny run build",
|
|
47
|
+
"watch": "yarn webiny run watch"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "549378cf03fcd27845fc3fa23d1dc6b32896f630"
|
|
50
|
+
}
|