mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
Initial Commit 2
This commit is contained in:
parent
6103f666e5
commit
e431adf20b
5 changed files with 6198 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1 +1,5 @@
|
|||
node_modules
|
||||
.cache
|
||||
|
||||
clones
|
||||
modules
|
||||
|
|
6103
package-lock.json
generated
Normal file
6103
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||
}
|
||||
|
|
82
src/index.js
82
src/index.js
|
@ -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
4
src/modules.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export default
|
||||
[
|
||||
'GooseMod/GMExampleModule@7848c0986bb30c2afac9e77e191bd172a2d02f73'
|
||||
];
|
Loading…
Reference in a new issue