defang 0.5.10

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/bin/cli.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const path = require("path");
5
+ const child_process = require("child_process");
6
+ const EXECUTABLE = "defang";
7
+ function getPathToExecutable() {
8
+ let extension = "";
9
+ if (["win32", "cygwin"].includes(process.platform)) {
10
+ extension = ".exe";
11
+ }
12
+ const executablePath = path.join(__dirname, `${EXECUTABLE}${extension}`);
13
+ try {
14
+ return require.resolve(executablePath);
15
+ }
16
+ catch (e) {
17
+ throw new Error(`Could not find application binary at ${executablePath}.`);
18
+ }
19
+ }
20
+ function run() {
21
+ const args = process.argv.slice(2);
22
+ const processResult = child_process.spawnSync(getPathToExecutable(), args, {
23
+ stdio: "inherit",
24
+ });
25
+ process.exit(processResult.status ?? 0);
26
+ }
27
+ run();
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("graceful-fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
+ const tar = require("tar");
7
+ const AdmZip = require("adm-zip");
8
+ const axios_1 = require("axios");
9
+ async function downloadAppArchive(version, archiveFilename, outputPath) {
10
+ const repo = "defang-io/defang";
11
+ const downloadUrl = `https://github.com/${repo}/releases/download/v${version}/${archiveFilename}`;
12
+ const downloadTargetFile = path.join(outputPath, archiveFilename);
13
+ return downloadFile(downloadUrl, downloadTargetFile);
14
+ }
15
+ async function downloadFile(downloadUrl, downloadTargetFile) {
16
+ try {
17
+ const writeFileStream = fs.createWriteStream(downloadTargetFile);
18
+ console.log(`Downloading ${downloadUrl}`);
19
+ const response = await axios_1.default.get(downloadUrl, {
20
+ responseType: "arraybuffer",
21
+ headers: {
22
+ "Content-Type": "application/octet-stream",
23
+ },
24
+ });
25
+ if (response?.data === undefined) {
26
+ throw new Error(`Failed to download ${downloadUrl}. No data in response.`);
27
+ }
28
+ fs.writeFileSync(downloadTargetFile, response.data);
29
+ return downloadTargetFile;
30
+ }
31
+ catch (error) {
32
+ console.error(`Failed to download ${downloadUrl}. ${error}`);
33
+ fs.unlinkSync(downloadTargetFile);
34
+ return "";
35
+ }
36
+ }
37
+ function extractArchive(archiveFilePath, outputPath) {
38
+ let result = false;
39
+ console.log(`Extracting ${archiveFilePath}`);
40
+ const ext = path.extname(archiveFilePath).toLocaleLowerCase();
41
+ switch (ext) {
42
+ case ".zip":
43
+ result = extractZip(archiveFilePath, outputPath);
44
+ break;
45
+ case ".gz":
46
+ result = extractTarGz(archiveFilePath, outputPath);
47
+ break;
48
+ default:
49
+ throw new Error(`Unsupported archive extension: ${ext}`);
50
+ }
51
+ return result;
52
+ }
53
+ function extractZip(zipPath, outputPath) {
54
+ try {
55
+ const zip = new AdmZip(zipPath);
56
+ zip.extractAllTo(outputPath, true, true);
57
+ return true;
58
+ }
59
+ catch (error) {
60
+ console.error(`An error occurred during zip extraction: ${error}`);
61
+ return false;
62
+ }
63
+ }
64
+ function extractTarGz(tarGzFilePath, outputPath) {
65
+ try {
66
+ tar.extract({
67
+ cwd: outputPath,
68
+ file: tarGzFilePath,
69
+ sync: true,
70
+ strict: true,
71
+ });
72
+ return true;
73
+ }
74
+ catch (error) {
75
+ console.error(`An error occurred during tar.gz extraction: ${error}`);
76
+ return false;
77
+ }
78
+ }
79
+ function deleteArchive(archiveFilePath) {
80
+ fs.unlinkSync(archiveFilePath);
81
+ }
82
+ function getVersion(filename) {
83
+ const data = fs.readFileSync(filename, "utf8");
84
+ const pkg = JSON.parse(data);
85
+ return pkg.version;
86
+ }
87
+ function getAppArchiveFilename(version, platform, arch) {
88
+ let compression = "zip";
89
+ switch (platform) {
90
+ case "windows":
91
+ platform = "windows";
92
+ break;
93
+ case "linux":
94
+ platform = "linux";
95
+ compression = "tar.gz";
96
+ break;
97
+ case "darwin":
98
+ platform = "macOS";
99
+ break;
100
+ default:
101
+ throw new Error(`Unsupported operating system: ${platform}`);
102
+ }
103
+ switch (arch) {
104
+ case "x64":
105
+ arch = "amd64";
106
+ break;
107
+ case "arm64":
108
+ arch = "arm64";
109
+ break;
110
+ default:
111
+ throw new Error(`Unsupported architecture: ${arch}`);
112
+ }
113
+ if (platform === "macOS") {
114
+ return `defang_${version}_${platform}.${compression}`;
115
+ }
116
+ return `defang_${version}_${platform}_${arch}.${compression}`;
117
+ }
118
+ async function install() {
119
+ try {
120
+ console.log(`Starting install of defang cli`);
121
+ const version = getVersion("package.json");
122
+ const filename = getAppArchiveFilename(version, os.platform(), os.arch());
123
+ const archiveFile = await downloadAppArchive(version, filename, __dirname);
124
+ if (archiveFile.length === 0) {
125
+ throw new Error(`Failed to download ${filename}`);
126
+ }
127
+ const result = extractArchive(archiveFile, "./bin");
128
+ if (result === false) {
129
+ throw new Error(`Failed to install binaries!`);
130
+ }
131
+ console.log(`Successfully installed defang cli!`);
132
+ deleteArchive(archiveFile);
133
+ }
134
+ catch (error) {
135
+ console.error(error);
136
+ process.exit(1);
137
+ }
138
+ }
139
+ install();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "defang",
3
+ "version": "0.5.10",
4
+ "author": "Defang Software Labs Inc.",
5
+ "description": "CLI for the Defang Opinionated Platform",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "defang": "./bin/cli.js"
9
+ },
10
+ "keywords": [],
11
+ "homepage": "https://github.com/defang-io/defang#readme",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/defang-io/defang.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/defang-io/defang/issues"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "postinstall": "node ./bin/installer.js"
22
+ },
23
+ "dependencies": {
24
+ "adm-zip": "^0.5.12",
25
+ "axios": "^1.6.8",
26
+ "graceful-fs": "^4.2.11",
27
+ "https": "^1.0.0",
28
+ "os": "^0.1.2",
29
+ "tar": "^7.0.1"
30
+ },
31
+ "devDependencies": {
32
+ "@types/adm-zip": "^0.5.5",
33
+ "@types/graceful-fs": "^4.1.9",
34
+ "@types/node": "^20.12.7",
35
+ "@types/tar": "^6.1.13",
36
+ "typescript": "^5.4.5"
37
+ },
38
+ "main": "./bin/cli.js"
39
+ }