@fastly/cli 10.13.2
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/fastly.js +22 -0
- package/index.js +19 -0
- package/package-helpers.js +5 -0
- package/package.json +39 -0
- package/update.js +180 -0
package/fastly.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
import { pkgForCurrentPlatform } from "./package-helpers.js";
|
|
5
|
+
|
|
6
|
+
const pkg = pkgForCurrentPlatform();
|
|
7
|
+
|
|
8
|
+
let location;
|
|
9
|
+
try {
|
|
10
|
+
// Check for the binary package from our "optionalDependencies". This
|
|
11
|
+
// package should have been installed alongside this package at install time.
|
|
12
|
+
location = (await import(pkg)).default;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by @fastly/cli.
|
|
15
|
+
Either the package is missing or the platform/architecture you are using is not supported.
|
|
16
|
+
If you are installing @fastly/cli with npm, make sure that you don't specify the
|
|
17
|
+
"--no-optional" flag. The "optionalDependencies" package.json feature is used
|
|
18
|
+
by @fastly/cli to install the correct binary executable for your current platform.
|
|
19
|
+
If your platform is not supported, you can open an issue at https://github.com/fastly/cli/issues`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
execFileSync(location, process.argv.slice(2), { stdio: "inherit" });
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { pkgForCurrentPlatform } from "./package-helpers.js";
|
|
2
|
+
|
|
3
|
+
const pkg = pkgForCurrentPlatform();
|
|
4
|
+
|
|
5
|
+
let location;
|
|
6
|
+
try {
|
|
7
|
+
// Check for the binary package from our "optionalDependencies". This
|
|
8
|
+
// package should have been installed alongside this package at install time.
|
|
9
|
+
location = (await import(pkg)).default;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by @fastly/cli.
|
|
12
|
+
Either the package is missing or the platform/architecture you are using is not supported.
|
|
13
|
+
If you are installing @fastly/cli with npm, make sure that you don't specify the
|
|
14
|
+
"--no-optional" flag. The "optionalDependencies" package.json feature is used
|
|
15
|
+
by @fastly/cli to install the correct binary executable for your current platform.
|
|
16
|
+
If your platform is not supported, you can open an issue at https://github.com/fastly/cli/issues`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default location;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fastly/cli",
|
|
3
|
+
"version": "10.13.2",
|
|
4
|
+
"description": "Build, deploy and configure Fastly services from your terminal",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"version": "node ./update.js $npm_package_version"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"decompress": "^4.2.1",
|
|
11
|
+
"decompress-targz": "^4.1.1"
|
|
12
|
+
},
|
|
13
|
+
"main": "index.js",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=16"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"fastly": "./fastly.js"
|
|
19
|
+
},
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@fastly/cli-darwin-arm64": "=10.13.2",
|
|
22
|
+
"@fastly/cli-darwin-x64": "=10.13.2",
|
|
23
|
+
"@fastly/cli-linux-arm64": "=10.13.2",
|
|
24
|
+
"@fastly/cli-linux-x64": "=10.13.2",
|
|
25
|
+
"@fastly/cli-linux-x32": "=10.13.2",
|
|
26
|
+
"@fastly/cli-win32-arm64": "=10.13.2",
|
|
27
|
+
"@fastly/cli-win32-x64": "=10.13.2",
|
|
28
|
+
"@fastly/cli-win32-x32": "=10.13.2"
|
|
29
|
+
},
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/fastly/cli.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/fastly/cli/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/fastly/cli#readme"
|
|
39
|
+
}
|
package/update.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, join, parse } from "node:path";
|
|
5
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import decompress from "decompress";
|
|
7
|
+
import decompressTargz from "decompress-targz";
|
|
8
|
+
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const input = process.argv.slice(2).at(0);
|
|
11
|
+
const tag = input ? `v${input}` : "dev";
|
|
12
|
+
|
|
13
|
+
let packages = [
|
|
14
|
+
{
|
|
15
|
+
releaseAsset: `fastly_${tag}_darwin-arm64.tar.gz`,
|
|
16
|
+
binaryAsset: "fastly",
|
|
17
|
+
description: "The macOS (M-series) binary for the Fastly CLI",
|
|
18
|
+
os: "darwin",
|
|
19
|
+
cpu: "arm64",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
releaseAsset: `fastly_${tag}_darwin-amd64.tar.gz`,
|
|
23
|
+
binaryAsset: "fastly",
|
|
24
|
+
description: "The macOS (Intel) binary for the Fastly CLI",
|
|
25
|
+
os: "darwin",
|
|
26
|
+
cpu: "x64",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
releaseAsset: `fastly_${tag}_linux-arm64.tar.gz`,
|
|
30
|
+
binaryAsset: "fastly",
|
|
31
|
+
description: "The Linux (arm64) binary for the Fastly CLI",
|
|
32
|
+
os: "linux",
|
|
33
|
+
cpu: "arm64",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
releaseAsset: `fastly_${tag}_linux-amd64.tar.gz`,
|
|
37
|
+
binaryAsset: "fastly",
|
|
38
|
+
description: "The Linux (64-bit) binary for the Fastly CLI",
|
|
39
|
+
os: "linux",
|
|
40
|
+
cpu: "x64",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
releaseAsset: `fastly_${tag}_linux-386.tar.gz`,
|
|
44
|
+
binaryAsset: "fastly",
|
|
45
|
+
description: "The Linux (32-bit) binary for the Fastly CLI",
|
|
46
|
+
os: "linux",
|
|
47
|
+
cpu: "x32",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
releaseAsset: `fastly_${tag}_windows-arm64.tar.gz`,
|
|
51
|
+
binaryAsset: "fastly.exe",
|
|
52
|
+
description: "The Windows (arm64) binary for the Fastly CLI",
|
|
53
|
+
os: "win32",
|
|
54
|
+
cpu: "arm64",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
releaseAsset: `fastly_${tag}_windows-amd64.tar.gz`,
|
|
58
|
+
binaryAsset: "fastly.exe",
|
|
59
|
+
description: "The Windows (64-bit) binary for the Fastly CLI",
|
|
60
|
+
os: "win32",
|
|
61
|
+
cpu: "x64",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
releaseAsset: `fastly_${tag}_windows-386.tar.gz`,
|
|
65
|
+
binaryAsset: "fastly.exe",
|
|
66
|
+
description: "The Windows (32-bit) binary for the Fastly CLI",
|
|
67
|
+
os: "win32",
|
|
68
|
+
cpu: "x32",
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
let response = await fetch(
|
|
73
|
+
`https://api.github.com/repos/fastly/cli/releases/tags/${tag}`
|
|
74
|
+
);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
console.error(
|
|
77
|
+
`Response from https://api.github.com/repos/fastly/cli/releases/tags/${tag} was not ok`,
|
|
78
|
+
response
|
|
79
|
+
);
|
|
80
|
+
console.error(await response.text());
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
response = await response.json();
|
|
84
|
+
const id = response.id;
|
|
85
|
+
let assets = await fetch(
|
|
86
|
+
`https://api.github.com/repos/fastly/cli/releases/${id}/assets`
|
|
87
|
+
);
|
|
88
|
+
if (!assets.ok) {
|
|
89
|
+
console.error(
|
|
90
|
+
`Response from https://api.github.com/repos/fastly/cli/releases/${id}/assets was not ok`,
|
|
91
|
+
assets
|
|
92
|
+
);
|
|
93
|
+
console.error(await response.text());
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
assets = await assets.json();
|
|
97
|
+
|
|
98
|
+
let generatedPackages = [];
|
|
99
|
+
|
|
100
|
+
for (const info of packages) {
|
|
101
|
+
const packageName = `cli-${info.os}-${info.cpu}`;
|
|
102
|
+
const asset = assets.find((asset) => asset.name === info.releaseAsset);
|
|
103
|
+
if (!asset) {
|
|
104
|
+
console.error(
|
|
105
|
+
`Can't find an asset named ${info.releaseAsset} for the release https://github.com/fastly/cli/releases/tag/${tag}`
|
|
106
|
+
);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
const packageDirectory = join(__dirname, "../", packageName.split("/").pop());
|
|
110
|
+
await mkdir(packageDirectory, { recursive: true });
|
|
111
|
+
await writeFile(
|
|
112
|
+
join(packageDirectory, "package.json"),
|
|
113
|
+
packageJson(packageName, tag, info.description, info.os, info.cpu)
|
|
114
|
+
);
|
|
115
|
+
await writeFile(
|
|
116
|
+
join(packageDirectory, "index.js"),
|
|
117
|
+
indexJs(info.binaryAsset)
|
|
118
|
+
);
|
|
119
|
+
generatedPackages.push(packageName);
|
|
120
|
+
const browser_download_url = asset.browser_download_url;
|
|
121
|
+
const archive = await fetch(browser_download_url);
|
|
122
|
+
if (!archive.ok) {
|
|
123
|
+
console.error(`Response from ${browser_download_url} was not ok`, archive);
|
|
124
|
+
console.error(await response.text());
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
let buf = await archive.arrayBuffer();
|
|
128
|
+
|
|
129
|
+
await decompress(Buffer.from(buf), packageDirectory, {
|
|
130
|
+
// Remove the leading directory from the extracted file.
|
|
131
|
+
strip: 1,
|
|
132
|
+
plugins: [decompressTargz()],
|
|
133
|
+
// Only extract the binary file and nothing else
|
|
134
|
+
filter: (file) => parse(file.path).base === info.binaryAsset,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Generate `optionalDependencies` section in the root package.json
|
|
139
|
+
const rootPackageJsonPath = join(__dirname, "./package.json");
|
|
140
|
+
let rootPackageJson = await readFile(rootPackageJsonPath, "utf8");
|
|
141
|
+
rootPackageJson = JSON.parse(rootPackageJson);
|
|
142
|
+
rootPackageJson["optionalDependencies"] = generatedPackages.reduce(
|
|
143
|
+
(acc, packageName) => {
|
|
144
|
+
acc[`@fastly/${packageName}`] = `=${tag.substring(1)}`;
|
|
145
|
+
return acc;
|
|
146
|
+
},
|
|
147
|
+
{}
|
|
148
|
+
);
|
|
149
|
+
await writeFile(rootPackageJsonPath, JSON.stringify(rootPackageJson, null, 4));
|
|
150
|
+
|
|
151
|
+
function indexJs(binaryAsset) {
|
|
152
|
+
return `
|
|
153
|
+
import { fileURLToPath } from 'node:url'
|
|
154
|
+
import { dirname, join } from 'node:path'
|
|
155
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
156
|
+
let location = join(__dirname, '${binaryAsset}')
|
|
157
|
+
export default location
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
function packageJson(name, version, description, os, cpu) {
|
|
161
|
+
version = version.startsWith("v") ? version.replace("v", "") : version;
|
|
162
|
+
return JSON.stringify(
|
|
163
|
+
{
|
|
164
|
+
name: `@fastly/${name}`,
|
|
165
|
+
bin: {
|
|
166
|
+
[name]: "fastly",
|
|
167
|
+
},
|
|
168
|
+
type: "module",
|
|
169
|
+
version,
|
|
170
|
+
main: "index.js",
|
|
171
|
+
description,
|
|
172
|
+
license: "Apache-2.0",
|
|
173
|
+
preferUnplugged: false,
|
|
174
|
+
os: [os],
|
|
175
|
+
cpu: [cpu],
|
|
176
|
+
},
|
|
177
|
+
null,
|
|
178
|
+
4
|
|
179
|
+
);
|
|
180
|
+
}
|