Skip to content

Commit 1800a76

Browse files
committed
ci: set up ncc packaging
1 parent 705f8bf commit 1800a76

File tree

6 files changed

+103
-7
lines changed

6 files changed

+103
-7
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
node-version: 16.x
2020
cache: "npm"
2121
- run: npm ci
22-
- run: npm run build
22+
- run: npm run package
2323
- name: Zip build files
24-
run: cp action.yml out/action.yml && zip -r out.zip out
24+
run: cp action.yml dist/action.yml && zip -r dist.zip dist
2525
- uses: softprops/action-gh-release@v1
2626
name: Release
2727
if: startsWith(github.ref, 'refs/tags/')
2828
with:
29-
files: out.zip
29+
files: dist.zip

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
out
2+
build
3+
dist

build/index.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27+
return new (P || (P = Promise))(function (resolve, reject) {
28+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31+
step((generator = generator.apply(thisArg, _arguments || [])).next());
32+
});
33+
};
34+
var __importDefault = (this && this.__importDefault) || function (mod) {
35+
return (mod && mod.__esModule) ? mod : { "default": mod };
36+
};
37+
Object.defineProperty(exports, "__esModule", { value: true });
38+
const core = __importStar(require("@actions/core"));
39+
const simple_git_1 = __importDefault(require("simple-git"));
40+
const path_1 = __importDefault(require("path"));
41+
const fs = __importStar(require("fs"));
42+
const submoduleRegex = /([A-z0-9]+) (.*\/.*) .*/g;
43+
function getDirectorySize(directory) {
44+
return __awaiter(this, void 0, void 0, function* () {
45+
let totalSize = 0;
46+
const files = yield fs.promises.readdir(directory);
47+
for (const file of files) {
48+
const filePath = `${directory}/${file}`;
49+
const fileStat = yield fs.promises.stat(filePath);
50+
if (fileStat.isDirectory()) {
51+
totalSize += yield getDirectorySize(filePath);
52+
}
53+
else {
54+
totalSize += fileStat.size;
55+
}
56+
}
57+
return totalSize;
58+
});
59+
}
60+
function run() {
61+
return __awaiter(this, void 0, void 0, function* () {
62+
try {
63+
const git = (0, simple_git_1.default)();
64+
const submoduleList = yield git.subModule();
65+
for (const submoduleMatch of submoduleList.matchAll(submoduleRegex)) {
66+
const sha = submoduleMatch[1];
67+
const submodulePath = submoduleMatch[2];
68+
const infoFilePath = path_1.default.join(submodulePath, "info.json");
69+
const rawInfo = yield fs.promises.readFile(infoFilePath);
70+
const info = JSON.parse(rawInfo.toString());
71+
info.size = yield getDirectorySize(submodulePath);
72+
info.hasPlugin = fs.existsSync(path_1.default.join(submodulePath, "module", "plugin.lua"));
73+
fs.promises.writeFile(infoFilePath, JSON.stringify(info, null, " "));
74+
}
75+
}
76+
catch (error) {
77+
if (error instanceof Error)
78+
return core.setFailed(error.message);
79+
return core.setFailed(error);
80+
}
81+
});
82+
}
83+
run();

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"name": "lls-addons-action",
33
"version": "0.1.0",
44
"description": "GitHub Action for fetching LLS-Addon metadata",
5-
"main": "out/index.js",
5+
"main": "build/index.js",
66
"scripts": {
7-
"build": "tsc"
7+
"build": "tsc",
8+
"package": "ncc build src/index.ts"
89
},
910
"repository": {
1011
"type": "git",
@@ -22,6 +23,7 @@
2223
},
2324
"devDependencies": {
2425
"@types/node": "^18.11.18",
26+
"@vercel/ncc": "^0.36.0",
2527
"typescript": "^4.9.4"
2628
}
2729
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
44
"lib": ["ESNext"],
55
"module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6-
"outDir": "./out", /* Redirect output structure to the directory. */
6+
"outDir": "./build", /* Redirect output structure to the directory. */
77
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
88
"strict": true, /* Enable all strict type-checking options. */
99
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */

0 commit comments

Comments
 (0)