|
| 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(); |
0 commit comments