Initial Commit 2

This commit is contained in:
Ducko 2021-01-22 21:26:27 +00:00
parent 6103f666e5
commit e431adf20b
5 changed files with 6198 additions and 1 deletions

4
.gitignore vendored
View file

@ -1 +1,5 @@
node_modules
.cache
clones
modules

6103
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -15,5 +15,9 @@
"bugs": {
"url": "https://github.com/GooseMod/MS2Builder/issues"
},
"homepage": "https://github.com/GooseMod/MS2Builder#readme"
"homepage": "https://github.com/GooseMod/MS2Builder#readme",
"dependencies": {
"parcel-bundler": "^1.12.4"
},
"type": "module"
}

View file

@ -0,0 +1,82 @@
import ModuleRepos from './modules.js';
import Parcel from 'parcel-bundler';
import { rmSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const clonesDir = `${__dirname.replace('/src', '')}/clones`;
const modulesDir = `${__dirname.replace('/src', '')}/modules`;
const resetDir = (dir) => {
rmSync(dir, { recursive: true, force: true });
mkdirSync(dir);
};
resetDir(clonesDir);
resetDir(modulesDir);
import { exec } from 'child_process';
const parcelOptions = {
minify: true,
watch: false,
sourceMaps: false,
outDir: modulesDir
};
let moduleJson = [];
for (const repo of ModuleRepos) {
console.log(repo);
const url = `https://github.com/${repo.split('@')[0]}.git`;
const commitHash = repo.split('@')[1];
const name = repo.split('@')[0];
const cloneDir = `${clonesDir}/${name}`;
console.log('Cloning...');
await new Promise((res) => exec(`git clone ${url} ${cloneDir}`, res));
console.log('Checkout...');
process.chdir(cloneDir);
await new Promise((res) => exec(`git checkout ${commitHash}`, res))
const manifest = JSON.parse(readFileSync(`${cloneDir}/goosemodModule.json`));
console.log(manifest);
const outFile = `${manifest.name.replace(/ /g, '_').toLowerCase()}.js`;
const bundler = new Parcel(`${cloneDir}/${manifest.main}`, Object.assign(parcelOptions, {
outFile
}));
const bundle = await bundler.bundle();
const outPath = `${modulesDir}/${outFile}`;
let jsCode = readFileSync(outPath, 'utf8');
jsCode = `${jsCode};parcelRequire('${manifest.main.split('/').pop()}').default`; // Make eval return the index module's default export
console.log(jsCode);
writeFileSync(outPath, jsCode);
moduleJson.push({
name: manifest.name,
description: manifest.description,
version: manifest.version,
tags: manifest.tags,
authors: manifest.authors
});
}

4
src/modules.js Normal file
View file

@ -0,0 +1,4 @@
export default
[
'GooseMod/GMExampleModule@7848c0986bb30c2afac9e77e191bd172a2d02f73'
];