@blackycoderx4/devc 0.2.3

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/devc.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ const path = require('path');
3
+ const child_process = require('child_process');
4
+ const fs = require('fs');
5
+ const { getPlatformAsset } = require('../platform');
6
+
7
+ const vendorDir = path.join(__dirname, '..', 'vendor');
8
+ const asset = getPlatformAsset(require('../package.json').version);
9
+
10
+ if (!asset) {
11
+ console.error(
12
+ `Unsupported platform: ${process.platform} ${process.arch}`
13
+ );
14
+ process.exit(1);
15
+ }
16
+
17
+ const binPath = path.join(vendorDir, asset.bin);
18
+
19
+ if (!fs.existsSync(binPath)) {
20
+ console.error(
21
+ 'devc binary not found. Please reinstall the package (npm install -g devc).'
22
+ );
23
+ process.exit(1);
24
+ }
25
+
26
+ const result = child_process.spawnSync(binPath, process.argv.slice(2), {
27
+ stdio: 'inherit',
28
+ shell: false,
29
+ });
30
+
31
+ process.exit(result.status !== null ? result.status : 1);
package/install.js ADDED
@@ -0,0 +1,90 @@
1
+ const https = require('https');
2
+ const http = require('http');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const child_process = require('child_process');
6
+
7
+ const packageJson = require('./package.json');
8
+ const { getPlatformAsset } = require('./platform');
9
+
10
+ const VERSION = packageJson.version;
11
+ const REPO = 'SamitoX4/devc';
12
+ const VENDOR_DIR = path.join(__dirname, 'vendor');
13
+
14
+ function download(url, dest) {
15
+ return new Promise((resolve, reject) => {
16
+ const file = fs.createWriteStream(dest);
17
+ const protocol = url.startsWith('https') ? https : http;
18
+ protocol
19
+ .get(url, (response) => {
20
+ if (response.statusCode === 301 || response.statusCode === 302) {
21
+ download(response.headers.location, dest)
22
+ .then(resolve)
23
+ .catch(reject);
24
+ return;
25
+ }
26
+ if (response.statusCode !== 200) {
27
+ reject(new Error(`Download failed: HTTP ${response.statusCode}`));
28
+ return;
29
+ }
30
+ response.pipe(file);
31
+ file.on('finish', () => {
32
+ file.close(resolve);
33
+ });
34
+ })
35
+ .on('error', reject);
36
+ });
37
+ }
38
+
39
+ function extract(archivePath, destDir) {
40
+ if (archivePath.endsWith('.zip')) {
41
+ child_process.execSync(
42
+ `powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force"`,
43
+ { stdio: 'inherit' }
44
+ );
45
+ } else {
46
+ fs.mkdirSync(destDir, { recursive: true });
47
+ child_process.execSync(`tar xzf "${archivePath}" -C "${destDir}"`, {
48
+ stdio: 'inherit',
49
+ });
50
+ }
51
+ }
52
+
53
+ async function main() {
54
+ const asset = getPlatformAsset(VERSION);
55
+ if (!asset) {
56
+ console.error(
57
+ `Unsupported platform: ${process.platform} ${process.arch}`
58
+ );
59
+ process.exit(1);
60
+ }
61
+
62
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${asset.name}`;
63
+ const archivePath = path.join(__dirname, asset.name);
64
+
65
+ fs.mkdirSync(VENDOR_DIR, { recursive: true });
66
+
67
+ console.log(`Downloading devc v${VERSION} for ${asset.platform}...`);
68
+ console.log(`URL: ${url}`);
69
+
70
+ await download(url, archivePath);
71
+
72
+ console.log('Extracting...');
73
+ extract(archivePath, VENDOR_DIR);
74
+
75
+ fs.unlinkSync(archivePath);
76
+
77
+ if (process.platform !== 'win32') {
78
+ const binPath = path.join(VENDOR_DIR, asset.bin);
79
+ if (fs.existsSync(binPath)) {
80
+ fs.chmodSync(binPath, 0o755);
81
+ }
82
+ }
83
+
84
+ console.log('devc installed successfully.');
85
+ }
86
+
87
+ main().catch((err) => {
88
+ console.error(err);
89
+ process.exit(1);
90
+ });
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@blackycoderx4/devc",
3
+ "version": "0.2.3",
4
+ "description": "CLI for generating devcontainers",
5
+ "main": "bin/devc.js",
6
+ "bin": {
7
+ "devc": "bin/devc.js"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node install.js",
11
+ "prepublishOnly": "node check-release.js"
12
+ },
13
+ "files": [
14
+ "bin/",
15
+ "install.js",
16
+ "platform.js"
17
+ ],
18
+ "keywords": [
19
+ "devcontainer",
20
+ "cli",
21
+ "development",
22
+ "docker",
23
+ "vscode"
24
+ ],
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/SamitoX4/devc.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/SamitoX4/devc/issues"
32
+ },
33
+ "homepage": "https://samitox4.github.io/devc",
34
+ "engines": {
35
+ "node": ">=14"
36
+ }
37
+ }
package/platform.js ADDED
@@ -0,0 +1,39 @@
1
+ function getPlatformAsset(version) {
2
+ const platform = process.platform;
3
+ const arch = process.arch;
4
+
5
+ const targets = {
6
+ win32: {
7
+ x64: {
8
+ name: `devc-v${version}-x86_64-pc-windows-msvc.zip`,
9
+ platform: 'windows-x64',
10
+ bin: 'devc.exe',
11
+ },
12
+ },
13
+ linux: {
14
+ x64: {
15
+ name: `devc-v${version}-x86_64-unknown-linux-gnu.tar.gz`,
16
+ platform: 'linux-x64',
17
+ bin: 'devc',
18
+ },
19
+ },
20
+ darwin: {
21
+ x64: {
22
+ name: `devc-v${version}-x86_64-apple-darwin.tar.gz`,
23
+ platform: 'macos-x64',
24
+ bin: 'devc',
25
+ },
26
+ arm64: {
27
+ name: `devc-v${version}-aarch64-apple-darwin.tar.gz`,
28
+ platform: 'macos-arm64',
29
+ bin: 'devc',
30
+ },
31
+ },
32
+ };
33
+
34
+ const p = targets[platform];
35
+ if (!p) return null;
36
+ return p[arch] || null;
37
+ }
38
+
39
+ module.exports = { getPlatformAsset };