@hackthedev/frontend-libs 1.0.0
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/.gitattributes +2 -0
- package/.github/workflows/publish.yml +43 -0
- package/README.md +2 -0
- package/bun.lock +24 -0
- package/index.mjs +95 -0
- package/package.json +15 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
persist-credentials: true
|
|
19
|
+
|
|
20
|
+
- name: Skip version bump commits
|
|
21
|
+
run: |
|
|
22
|
+
if git log -1 --pretty=%B | grep -q "chore: bump version"; then
|
|
23
|
+
echo "Version bump commit detected, skipping."
|
|
24
|
+
exit 0
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
- uses: actions/setup-node@v4
|
|
28
|
+
with:
|
|
29
|
+
node-version: 20
|
|
30
|
+
registry-url: https://registry.npmjs.org/
|
|
31
|
+
|
|
32
|
+
- run: npm ci
|
|
33
|
+
|
|
34
|
+
- run: |
|
|
35
|
+
git config user.name "github-actions"
|
|
36
|
+
git config user.email "actions@github.com"
|
|
37
|
+
npm version patch -m "chore: bump version %s"
|
|
38
|
+
git push
|
|
39
|
+
|
|
40
|
+
- run: npm publish --access public
|
|
41
|
+
env:
|
|
42
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
43
|
+
|
package/README.md
ADDED
package/bun.lock
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"configVersion": 1,
|
|
4
|
+
"workspaces": {
|
|
5
|
+
"": {
|
|
6
|
+
"name": "frontendlibs",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"fs": "^0.0.1-security",
|
|
9
|
+
"path": "^0.12.7",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
"packages": {
|
|
14
|
+
"fs": ["fs@0.0.1-security", "", {}, "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="],
|
|
15
|
+
|
|
16
|
+
"inherits": ["inherits@2.0.3", "", {}, "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="],
|
|
17
|
+
|
|
18
|
+
"path": ["path@0.12.7", "", { "dependencies": { "process": "^0.11.1", "util": "^0.10.3" } }, "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q=="],
|
|
19
|
+
|
|
20
|
+
"process": ["process@0.11.10", "", {}, "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A=="],
|
|
21
|
+
|
|
22
|
+
"util": ["util@0.10.4", "", { "dependencies": { "inherits": "2.0.3" } }, "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A=="],
|
|
23
|
+
}
|
|
24
|
+
}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
|
|
5
|
+
export default class FrontendLibs {
|
|
6
|
+
static async install(packageSpec, pathToSave) {
|
|
7
|
+
try {
|
|
8
|
+
const [packageName, version] = packageSpec.includes('@') && !packageSpec.startsWith('@')
|
|
9
|
+
? packageSpec.split('@')
|
|
10
|
+
: [packageSpec, 'latest'];
|
|
11
|
+
|
|
12
|
+
const targetDirName = version === 'latest'
|
|
13
|
+
? packageName
|
|
14
|
+
: `${packageName}_${version}`;
|
|
15
|
+
|
|
16
|
+
const targetPath = path.resolve(pathToSave, targetDirName);
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(targetPath)) {
|
|
19
|
+
return {
|
|
20
|
+
success: true,
|
|
21
|
+
message: `Package ${packageName}@${version} already exists. Skipped.`,
|
|
22
|
+
path: targetPath
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const tempDir = path.join(process.cwd(), '.temp', `${Date.now()}`);
|
|
27
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
28
|
+
|
|
29
|
+
const fullPackageName = `@hackthedev/${packageName}`;
|
|
30
|
+
const installSpec = version === 'latest'
|
|
31
|
+
? fullPackageName
|
|
32
|
+
: `${fullPackageName}@${version}`;
|
|
33
|
+
|
|
34
|
+
console.log(`Fetching ${installSpec}...`);
|
|
35
|
+
|
|
36
|
+
const tarballName = execSync(
|
|
37
|
+
`npm pack ${installSpec}`,
|
|
38
|
+
{ cwd: tempDir, encoding: 'utf8' }
|
|
39
|
+
).trim();
|
|
40
|
+
|
|
41
|
+
execSync(`tar -xzf ${tarballName}`, { cwd: tempDir });
|
|
42
|
+
|
|
43
|
+
const extractedPath = path.join(tempDir, 'package');
|
|
44
|
+
|
|
45
|
+
fs.mkdirSync(pathToSave, { recursive: true });
|
|
46
|
+
|
|
47
|
+
this._copyRecursive(extractedPath, targetPath);
|
|
48
|
+
|
|
49
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
success: true,
|
|
53
|
+
message: `Successfully installed ${packageName}@${version}`,
|
|
54
|
+
path: targetPath
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
message: `Error installing ${packageSpec}: ${error.message}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static async installMultiple(packages) {
|
|
66
|
+
const results = [];
|
|
67
|
+
for (const { package: pkg, path: pathToSave } of packages) {
|
|
68
|
+
const result = await this.install(pkg, pathToSave);
|
|
69
|
+
results.push({ package: pkg, ...result });
|
|
70
|
+
}
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static _copyRecursive(src, dest) {
|
|
75
|
+
if (!fs.existsSync(src)) return;
|
|
76
|
+
|
|
77
|
+
if (fs.statSync(src).isDirectory()) {
|
|
78
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
79
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
80
|
+
|
|
81
|
+
for (const entry of entries) {
|
|
82
|
+
const srcPath = path.join(src, entry.name);
|
|
83
|
+
const destPath = path.join(dest, entry.name);
|
|
84
|
+
|
|
85
|
+
if (entry.isDirectory()) {
|
|
86
|
+
this._copyRecursive(srcPath, destPath);
|
|
87
|
+
} else {
|
|
88
|
+
fs.copyFileSync(srcPath, destPath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
fs.copyFileSync(src, dest);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hackthedev/frontend-libs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple Frontend Lib installer",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "",
|
|
7
|
+
"main": "index.mjs",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"fs": "^0.0.1-security",
|
|
13
|
+
"path": "^0.12.7"
|
|
14
|
+
}
|
|
15
|
+
}
|