@shopware-ag/shopware-cli 0.5.18

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Friends of Shopware
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/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Shopware CLI
2
+
3
+ [![Hosted By: Cloudsmith](https://img.shields.io/badge/OSS%20hosting%20by-cloudsmith-blue?logo=cloudsmith&style=flat-square)](https://cloudsmith.com)
4
+
5
+ A cli which contains handy helpful commands for daily Shopware tasks
6
+
7
+ ## Features
8
+
9
+ - Manage your Shopware account extensions in the CLI
10
+ - Build and validate Shopware extensions
11
+
12
+ For docs see [here](https://developer.shopware.com/docs/products/cli/)
13
+
14
+ ## Contributing
15
+
16
+ Contributions are always welcome!
package/install.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ // This file was generated by GoReleaser. DO NOT EDIT.
4
+
5
+ const { install } = require("./lib.js");
6
+ install();
package/lib.js ADDED
@@ -0,0 +1,175 @@
1
+ // This file was generated by GoReleaser. DO NOT EDIT.
2
+ const { archives } = require("./package.json");
3
+ const fs = require("fs");
4
+ const crypto = require("crypto");
5
+ const path = require("path");
6
+ const JSZip = require("jszip");
7
+ const tar = require("tar");
8
+ const axios = require("axios");
9
+ const { spawnSync } = require("child_process");
10
+
11
+ const getArchive = () => {
12
+ let target = `${process.platform}-${process.arch}`;
13
+ const archive = archives[target];
14
+ if (!archive) {
15
+ throw new Error(`No archive available for ${target}`);
16
+ }
17
+ return archive;
18
+ };
19
+
20
+ const binDir = path.join(__dirname, "bin");
21
+
22
+ async function extractTar(tarPath, binaries, dir) {
23
+ try {
24
+ await tar.x({
25
+ file: tarPath,
26
+ cwd: dir,
27
+ filter: (path) => binaries.includes(path),
28
+ });
29
+ console.log(`Successfully extracted binaries to "${dir}"`);
30
+ } catch (err) {
31
+ throw new Error(`Extraction failed: ${err.message}`);
32
+ }
33
+ }
34
+
35
+ async function extractZip(zipPath, binaries, dir) {
36
+ try {
37
+ const zipData = fs.readFileSync(zipPath);
38
+ const zip = await JSZip.loadAsync(zipData);
39
+ for (const binary of binaries) {
40
+ if (!zip.files[binary]) {
41
+ throw new Error(
42
+ `Error: ${binary} does not exist in ${zipPath}`,
43
+ );
44
+ }
45
+
46
+ const content = await zip.files[binary].async("nodebuffer");
47
+ if (!fs.existsSync(dir)) {
48
+ fs.mkdirSync(dir, { recursive: true });
49
+ }
50
+ const file = path.join(dir, binary);
51
+ fs.writeFileSync(file, content);
52
+ fs.chmodSync(file, "755");
53
+ console.log(`Successfully extracted "${binary}" to "${dir}"`);
54
+ }
55
+ } catch (err) {
56
+ throw new Error(`Extraction failed: ${err.message}`);
57
+ }
58
+ }
59
+
60
+ const run = async (bin) => {
61
+ await install();
62
+ if (process.platform === "win32") {
63
+ bin += ".exe";
64
+ }
65
+ const [, , ...args] = process.argv;
66
+ let result = spawnSync(path.join(binDir, bin), args, {
67
+ cwd: process.cwd(),
68
+ stdio: "inherit",
69
+ });
70
+ if (result.error) {
71
+ console.error(result.error);
72
+ }
73
+ return result.status;
74
+ };
75
+
76
+ const install = async () => {
77
+ try {
78
+ let archive = getArchive();
79
+ if (await exists(archive)) {
80
+ return;
81
+ }
82
+ let tmp = fs.mkdtempSync("archive-");
83
+ let archivePath = path.join(tmp, archive.name);
84
+ await download(archive.url, archivePath);
85
+ verify(archivePath, archive.checksum);
86
+
87
+ if (!fs.existsSync(binDir)) {
88
+ fs.mkdirSync(binDir);
89
+ }
90
+ switch (archive.format) {
91
+ case "binary":
92
+ const bin = path.join(binDir, archive.bins[0]);
93
+ fs.copyFileSync(archivePath, bin);
94
+ fs.chmodSync(bin, 0o755);
95
+ return;
96
+ case "zip":
97
+ return extractZip(archivePath, archive.bins, binDir);
98
+ case "tar":
99
+ case "tar.gz":
100
+ case "tgz":
101
+ return extractTar(archivePath, archive.bins, binDir);
102
+ case "tar.zst":
103
+ case "tzst":
104
+ case "tar.xz":
105
+ case "txz":
106
+ default:
107
+ throw new Error(`unsupported format: ${archive.format}`);
108
+ }
109
+ } catch (err) {
110
+ throw new Error(`Installation failed: ${err.message}`);
111
+ }
112
+ };
113
+
114
+ const verify = (filename, checksum) => {
115
+ if (checksum.algorithm == "" || checksum.digest == "") {
116
+ console.warn("Warning: No checksum provided for verification");
117
+ return;
118
+ }
119
+ let digest = crypto
120
+ .createHash(checksum.algorithm)
121
+ .update(fs.readFileSync(filename))
122
+ .digest("hex");
123
+ if (digest != checksum.digest) {
124
+ throw new Error(
125
+ `${filename}: ${checksum.algorithm} does not match, expected ${checksum.digest}, got ${digest}`,
126
+ );
127
+ }
128
+ };
129
+
130
+ const download = async (url, filename) => {
131
+ try {
132
+ console.log(`Downloading ${url} to ${filename}...`);
133
+ const dir = path.dirname(filename);
134
+ if (!fs.existsSync(dir)) {
135
+ fs.mkdirSync(dir, { recursive: true });
136
+ }
137
+
138
+ const response = await axios({
139
+ method: "GET",
140
+ url: url,
141
+ responseType: "stream",
142
+ timeout: 300000, // 5min
143
+ });
144
+
145
+ const writer = fs.createWriteStream(filename);
146
+ response.data.pipe(writer);
147
+
148
+ return new Promise((resolve, reject) => {
149
+ writer.on("finish", () => {
150
+ console.log(`Download complete: ${filename}`);
151
+ resolve(dir);
152
+ });
153
+
154
+ writer.on("error", (err) => {
155
+ console.error(`Error writing file: ${err.message}`);
156
+ reject(err);
157
+ });
158
+ });
159
+ } catch (err) {
160
+ throw new Error(`Download failed: ${err.message}`);
161
+ }
162
+ };
163
+
164
+ function exists(archive) {
165
+ if (!fs.existsSync(binDir)) {
166
+ return false;
167
+ }
168
+ return archive.bins.every((bin) => fs.existsSync(path.join(binDir, bin)));
169
+ }
170
+
171
+ module.exports = {
172
+ install,
173
+ run,
174
+ getArchive,
175
+ };
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@shopware-ag/shopware-cli",
3
+ "version": "0.5.18",
4
+ "description": "Shopware CLI helps Shopware developers manage extensions",
5
+ "scripts": {
6
+ "postinstall": "node install.js",
7
+ "run": "node run-shopware-cli.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/shopware/shopware-cli"
12
+ },
13
+ "keywords": [
14
+ "cli",
15
+ "shopware"
16
+ ],
17
+ "author": "",
18
+ "license": "MIT",
19
+ "bugs": {
20
+ "url": "https://github.com/shopware/shopware-cli/issues"
21
+ },
22
+ "homepage": "https://developer.shopware.com/docs/products/cli/",
23
+ "bin": {
24
+ "shopware-cli": "run-shopware-cli.js"
25
+ },
26
+ "dependencies": {
27
+ "axios": "^1.8.2",
28
+ "jszip": "^3.10.1",
29
+ "tar": "^7.4.3"
30
+ },
31
+ "archives": {
32
+ "darwin-arm64": {
33
+ "name": "shopware-cli_Darwin_arm64.tar.gz",
34
+ "url": "https://github.com/shopware/shopware-cli/releases/download/0.5.18/shopware-cli_Darwin_arm64.tar.gz",
35
+ "bins": [
36
+ "shopware-cli"
37
+ ],
38
+ "format": "tar.gz",
39
+ "checksum": {
40
+ "algorithm": "sha256",
41
+ "digest": "f9486a2d29d9df74e02612777236783d0c9716dffdbe5d70972e38cf2e4d8500"
42
+ }
43
+ },
44
+ "darwin-x64": {
45
+ "name": "shopware-cli_Darwin_x86_64.tar.gz",
46
+ "url": "https://github.com/shopware/shopware-cli/releases/download/0.5.18/shopware-cli_Darwin_x86_64.tar.gz",
47
+ "bins": [
48
+ "shopware-cli"
49
+ ],
50
+ "format": "tar.gz",
51
+ "checksum": {
52
+ "algorithm": "sha256",
53
+ "digest": "0a21fcea0e20c7e71ffa65c9ada23f7e59ff942abe3f28faee825bdfbe5d0f69"
54
+ }
55
+ },
56
+ "linux-arm64": {
57
+ "name": "shopware-cli_Linux_arm64.tar.gz",
58
+ "url": "https://github.com/shopware/shopware-cli/releases/download/0.5.18/shopware-cli_Linux_arm64.tar.gz",
59
+ "bins": [
60
+ "shopware-cli"
61
+ ],
62
+ "format": "tar.gz",
63
+ "checksum": {
64
+ "algorithm": "sha256",
65
+ "digest": "0adf8ba56b7ce56872be30bef059665af66855a79b2127a594e2754285c742a1"
66
+ }
67
+ },
68
+ "linux-x64": {
69
+ "name": "shopware-cli_Linux_x86_64.tar.gz",
70
+ "url": "https://github.com/shopware/shopware-cli/releases/download/0.5.18/shopware-cli_Linux_x86_64.tar.gz",
71
+ "bins": [
72
+ "shopware-cli"
73
+ ],
74
+ "format": "tar.gz",
75
+ "checksum": {
76
+ "algorithm": "sha256",
77
+ "digest": "8774c71f08ee52e1c9bb1839127a521e4b88c7cb64dd778f5bb9b5ccdff70de7"
78
+ }
79
+ },
80
+ "win32-x64": {
81
+ "name": "shopware-cli_Windows_x86_64.zip",
82
+ "url": "https://github.com/shopware/shopware-cli/releases/download/0.5.18/shopware-cli_Windows_x86_64.zip",
83
+ "bins": [
84
+ "shopware-cli.exe"
85
+ ],
86
+ "format": "zip",
87
+ "checksum": {
88
+ "algorithm": "sha256",
89
+ "digest": "62d32ab820e9bd0c29002a8692bf00e4008e46771e0201168a4ff6fdcdb7ba5c"
90
+ }
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ // This file was generated by GoReleaser. DO NOT EDIT.
4
+
5
+ const { run } = require("./lib.js");
6
+ run("shopware-cli");