Skip to content

Commit fa447b4

Browse files
committed
20230319B
1 parent 5c0c26d commit fa447b4

File tree

4 files changed

+91
-57
lines changed

4 files changed

+91
-57
lines changed
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
{"name":"@hugoalh/ghactions-toolkit-powershell-nodejs-wrapper-distribution","version":"1.3.2","description":"A PowerShell module to provide a better and easier way for GitHub Actions to communicate with the runner machine, and the toolkit for developing GitHub Actions in PowerShell.","keywords":["gh-actions","ghactions","github-actions","PSEdition_Core","toolkit"],"homepage":"https://github.com/hugoalh-studio/ghactions-toolkit-powershell#readme","bugs":{"url":"https://github.com/hugoalh-studio/ghactions-toolkit-powershell/issues"},"license":"MIT","author":"hugoalh","type":"module","main":"./main.js","exports":{"import":"./main.js"},"repository":{"type":"git","url":"git+https://github.com/hugoalh-studio/ghactions-toolkit-powershell.git"},"dependencies":{"@actions/artifact":"^1.1.1","@actions/cache":"^3.2.1","@actions/core":"^1.10.0","@actions/tool-cache":"^2.0.1"},"engines":{"node":">=14.15.0"},"private":true}
1+
{
2+
"name": "@hugoalh/ghactions-toolkit-powershell-nodejs-wrapper-distribution",
3+
"version": "1.3.2",
4+
"description": "A PowerShell module to provide a better and easier way for GitHub Actions to communicate with the runner machine, and the toolkit for developing GitHub Actions in PowerShell.",
5+
"keywords": [
6+
"gh-actions",
7+
"ghactions",
8+
"github-actions",
9+
"PSEdition_Core",
10+
"toolkit"
11+
],
12+
"homepage": "https://github.com/hugoalh-studio/ghactions-toolkit-powershell#readme",
13+
"bugs": {
14+
"url": "https://github.com/hugoalh-studio/ghactions-toolkit-powershell/issues"
15+
},
16+
"license": "MIT",
17+
"author": "hugoalh",
18+
"type": "module",
19+
"main": "./main.js",
20+
"exports": {
21+
"import": "./main.js"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/hugoalh-studio/ghactions-toolkit-powershell.git"
26+
},
27+
"dependencies": {
28+
"@actions/artifact": "^1.1.1",
29+
"@actions/cache": "^3.2.1",
30+
"@actions/core": "^1.10.0",
31+
"@actions/tool-cache": "^2.0.1"
32+
},
33+
"engines": {
34+
"node": ">=14.15.0"
35+
},
36+
"private": true
37+
}

nodejs-wrapper-source/bundler.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { copyFile as fsCopyFile, readFile as fsReadFile, writeFile as fsWriteFile } from "node:fs/promises";
2+
import { dirname as pathDirName, join as pathJoin } from "node:path";
3+
import { existsSync as fsExistsSync } from "node:fs";
4+
import { fileURLToPath } from "node:url";
5+
import ncc from "@vercel/ncc";
6+
const packageFileName = "package.json"
7+
const packageLockFileName = "pnpm-lock.yaml";
8+
const inputDirectoryPath = pathDirName(fileURLToPath(import.meta.url));
9+
const inputScriptFileName = "main.js";
10+
const outputDirectoryPath = pathJoin(inputDirectoryPath, "../hugoalh.GitHubActionsToolkit/module/nodejs-wrapper");
11+
const outputBundledFileName = "bundled.js";
12+
const outputUnbundledFileName = "unbundled.js";
13+
async function getDirectoryItem(directoryPath) {
14+
try {
15+
return await fsReadDir(directoryPath, { withFileTypes: true });
16+
} catch {
17+
return [];
18+
}
19+
}
20+
21+
/* Clean up or initialize output directory (need to await in order to prevent race conditions). */
22+
if (fsExistsSync(outputDirectoryPath)) {
23+
for (const outputFile of await getDirectoryItem(outputDirectoryPath)) {
24+
await fsRemove(pathJoin(outputDirectoryPath, outputFile.name), { recursive: true });
25+
}
26+
} else {
27+
await fsMKDir(outputDirectoryPath, { recursive: true });
28+
}
29+
30+
/* Create bundle. */
31+
let { code } = await ncc(pathJoin(inputDirectoryPath, inputScriptFileName), {
32+
assetBuilds: false,
33+
cache: false,
34+
debugLog: false,
35+
license: "",
36+
minify: true,
37+
quiet: false,
38+
sourceMap: false,
39+
sourceMapRegister: false,
40+
target: "es2022",
41+
v8cache: false,
42+
watch: false
43+
});
44+
await fsWriteFile(pathJoin(outputDirectoryPath, outputBundledFileName), code, { encoding: "utf8" });
45+
await fsCopyFile(pathJoin(inputDirectoryPath, inputScriptFileName), pathJoin(outputDirectoryPath, outputUnbundledFileName))
46+
await fsCopyFile(pathJoin(inputDirectoryPath, packageLockFileName), pathJoin(outputDirectoryPath, packageLockFileName))
47+
let packageMeta = JSON.parse(await fsReadFile(pathJoin(inputDirectoryPath, packageFileName), { encoding: "utf8" }));
48+
delete packageMeta.scripts;
49+
delete packageMeta.devDependencies;
50+
packageMeta.name = `${packageMeta.name}-distribution`;
51+
await fsWriteFile(pathJoin(outputDirectoryPath, packageFileName), `${JSON.stringify(packageMeta, undefined, "\t")}\n`, { encoding: "utf8" });

nodejs-wrapper-source/bundler.ps1

Lines changed: 0 additions & 56 deletions
This file was deleted.

nodejs-wrapper-source/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"type": "git",
2525
"url": "git+https://github.com/hugoalh-studio/ghactions-toolkit-powershell.git"
2626
},
27+
"scripts": {
28+
"build": "node bundler.js"
29+
},
2730
"dependencies": {
2831
"@actions/artifact": "^1.1.1",
2932
"@actions/cache": "^3.2.1",

0 commit comments

Comments
 (0)