mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
[Feat] Separate repos
This commit is contained in:
parent
dfe62bdc22
commit
a71da298d5
2 changed files with 138 additions and 106 deletions
214
src/index.js
214
src/index.js
|
@ -27,7 +27,7 @@ const resetDir = (dir) => {
|
|||
|
||||
if (process.argv[2] === '-f') {
|
||||
resetDir(clonesDir);
|
||||
|
||||
|
||||
resetDir(distDir);
|
||||
resetDir(modulesDir);
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ let previous = [];
|
|||
if (existsSync(clonesDir)) {
|
||||
for (const cloneDir of glob.sync(`${clonesDir}/*/*`)) {
|
||||
process.chdir(cloneDir);
|
||||
|
||||
|
||||
const currentHash = await new Promise((res) => exec(`git rev-parse HEAD`, (err, stdout) => res(stdout.trim())));
|
||||
|
||||
|
||||
previous = previous.concat(ModuleRepos.filter((x) => x[0] === cloneDir.replace(`${clonesDir}/`, '') && x[1] === currentHash));
|
||||
}
|
||||
}
|
||||
|
@ -53,13 +53,11 @@ const parcelOptions = {
|
|||
logLevel: 0
|
||||
};
|
||||
|
||||
let moduleJson = [];
|
||||
|
||||
const githubCache = {};
|
||||
|
||||
const getGithubInfo = async (repo) => {
|
||||
if (githubCache[repo]) return githubCache[repo];
|
||||
|
||||
|
||||
const info = (await axios.get(`https://api.github.com/repos/${repo}`, {
|
||||
headers: {
|
||||
'Authorization': `token ${githubPAT}`
|
||||
|
@ -70,118 +68,126 @@ const getGithubInfo = async (repo) => {
|
|||
return info;
|
||||
};
|
||||
|
||||
for (const repo of ModuleRepos) {
|
||||
console.time(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||
for (const parentRepo of ModuleRepos) {
|
||||
let moduleJson = {
|
||||
modules: [],
|
||||
meta: parentRepo.meta
|
||||
};
|
||||
|
||||
const githubInfo = await getGithubInfo(repo[0]);
|
||||
|
||||
const name = repo[0];
|
||||
const cloneDir = `${clonesDir}/${name}`;
|
||||
|
||||
const moduleDir = repo[2] || '';
|
||||
|
||||
if (previous.includes(repo)) {
|
||||
for (const repo of parentRepo.modules) {
|
||||
console.time(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||
|
||||
const githubInfo = await getGithubInfo(repo[0]);
|
||||
|
||||
const name = repo[0];
|
||||
const cloneDir = `${clonesDir}/${name}`;
|
||||
|
||||
const moduleDir = repo[2] || '';
|
||||
|
||||
if (previous.includes(repo)) {
|
||||
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
||||
|
||||
const jsHash = createHash('sha512').update(readFileSync(`${modulesDir}/${manifest.name}.js`)).digest('hex');
|
||||
|
||||
moduleJson.push({
|
||||
name: manifest.name,
|
||||
description: manifest.description,
|
||||
version: manifest.version,
|
||||
tags: manifest.tags,
|
||||
authors: manifest.authors,
|
||||
hash: jsHash,
|
||||
|
||||
github: {
|
||||
stars: githubInfo.stargazers_count,
|
||||
repo: repo[0]
|
||||
}
|
||||
});
|
||||
|
||||
process.stdout.write('[SKIP] ');
|
||||
|
||||
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// console.log(repo);
|
||||
|
||||
const url = `https://github.com/${repo[0]}.git`;
|
||||
const commitHash = repo[1];
|
||||
|
||||
const preprocessor = repo[3];
|
||||
|
||||
// resetDir(cloneDir);
|
||||
// rmSync(cloneDir, { recursive: true, force: true });
|
||||
|
||||
await new Promise((res) => exec(`git clone ${url} ${cloneDir}`, res));
|
||||
|
||||
process.chdir(cloneDir);
|
||||
|
||||
const lastHash = await new Promise((res) => exec(`git rev-parse HEAD`, (err, stdout) => res(stdout.trim())));
|
||||
|
||||
await new Promise((res) => exec(`git checkout ${commitHash}`, res));
|
||||
|
||||
if (preprocessor) {
|
||||
(await import(`./preprocessors/${preprocessor}.js`)).default(`${cloneDir}${moduleDir}`, repo);
|
||||
}
|
||||
|
||||
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
||||
|
||||
const jsHash = createHash('sha512').update(readFileSync(`${modulesDir}/${manifest.name}.js`)).digest('hex');
|
||||
|
||||
moduleJson.push({
|
||||
|
||||
// console.log(manifest);
|
||||
|
||||
const outFile = `${manifest.name}.js`;
|
||||
|
||||
const bundler = new Parcel(`${cloneDir}${moduleDir}/${manifest.main}`, Object.assign(parcelOptions, {
|
||||
outFile
|
||||
}));
|
||||
|
||||
const bundle = await bundler.bundle();
|
||||
|
||||
const outPath = `${modulesDir}/${outFile}`;
|
||||
let jsCode = readFileSync(outPath, 'utf8');
|
||||
|
||||
jsCode = `${jsCode};parcelRequire('${bundle.entryAsset.basename}').default`; // Make eval return the index module's default export
|
||||
|
||||
// console.log(jsCode);
|
||||
|
||||
writeFileSync(outPath, jsCode);
|
||||
|
||||
const jsHash = createHash('sha512').update(jsCode).digest('hex');
|
||||
|
||||
const manifestJson = {
|
||||
name: manifest.name,
|
||||
description: manifest.description,
|
||||
|
||||
version: manifest.version,
|
||||
|
||||
tags: manifest.tags,
|
||||
|
||||
authors: manifest.authors,
|
||||
|
||||
hash: jsHash,
|
||||
|
||||
|
||||
github: {
|
||||
stars: githubInfo.stargazers_count,
|
||||
repo: repo[0]
|
||||
}
|
||||
});
|
||||
|
||||
process.stdout.write('[SKIP] ');
|
||||
|
||||
};
|
||||
|
||||
if (manifest.images) manifestJson.images = manifest.images;
|
||||
if (manifest.dependencies) manifestJson.dependencies = manifest.dependencies;
|
||||
|
||||
moduleJson.modules.push(manifestJson);
|
||||
|
||||
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// console.log(repo);
|
||||
|
||||
const url = `https://github.com/${repo[0]}.git`;
|
||||
const commitHash = repo[1];
|
||||
|
||||
const preprocessor = repo[3];
|
||||
|
||||
// resetDir(cloneDir);
|
||||
// rmSync(cloneDir, { recursive: true, force: true });
|
||||
|
||||
await new Promise((res) => exec(`git clone ${url} ${cloneDir}`, res));
|
||||
|
||||
process.chdir(cloneDir);
|
||||
|
||||
const lastHash = await new Promise((res) => exec(`git rev-parse HEAD`, (err, stdout) => res(stdout.trim())));
|
||||
|
||||
await new Promise((res) => exec(`git checkout ${commitHash}`, res));
|
||||
|
||||
if (preprocessor) {
|
||||
(await import(`./preprocessors/${preprocessor}.js`)).default(`${cloneDir}${moduleDir}`, repo);
|
||||
}
|
||||
|
||||
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
||||
|
||||
// console.log(manifest);
|
||||
|
||||
const outFile = `${manifest.name}.js`;
|
||||
|
||||
const bundler = new Parcel(`${cloneDir}${moduleDir}/${manifest.main}`, Object.assign(parcelOptions, {
|
||||
outFile
|
||||
}));
|
||||
|
||||
const bundle = await bundler.bundle();
|
||||
|
||||
const outPath = `${modulesDir}/${outFile}`;
|
||||
let jsCode = readFileSync(outPath, 'utf8');
|
||||
|
||||
jsCode = `${jsCode};parcelRequire('${bundle.entryAsset.basename}').default`; // Make eval return the index module's default export
|
||||
|
||||
// console.log(jsCode);
|
||||
|
||||
writeFileSync(outPath, jsCode);
|
||||
|
||||
const jsHash = createHash('sha512').update(jsCode).digest('hex');
|
||||
|
||||
const manifestJson = {
|
||||
name: manifest.name,
|
||||
description: manifest.description,
|
||||
|
||||
version: manifest.version,
|
||||
|
||||
tags: manifest.tags,
|
||||
|
||||
authors: manifest.authors,
|
||||
|
||||
hash: jsHash,
|
||||
|
||||
github: {
|
||||
stars: githubInfo.stargazers_count,
|
||||
repo: repo[0]
|
||||
|
||||
// console.log(lastHash);
|
||||
|
||||
if (lastHash !== commitHash) {
|
||||
console.log('[Warning] Commit hash in modules does not match latest commit in repo');
|
||||
}
|
||||
};
|
||||
|
||||
if (manifest.images) manifestJson.images = manifest.images;
|
||||
if (manifest.dependencies) manifestJson.dependencies = manifest.dependencies;
|
||||
|
||||
moduleJson.push(manifestJson);
|
||||
|
||||
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||
|
||||
// console.log(lastHash);
|
||||
|
||||
if (lastHash !== commitHash) {
|
||||
console.log('[Warning] Commit hash in modules does not match latest commit in repo');
|
||||
}
|
||||
|
||||
writeFileSync(`${distDir}/${parentRepo.filename}.json`, JSON.stringify(moduleJson));
|
||||
}
|
||||
|
||||
writeFileSync(`${distDir}/modules.json`, JSON.stringify(moduleJson));
|
||||
copyFileSync(`${__dirname.replace('/src', '')}/_headers`, `${distDir}/_headers`);
|
||||
copyFileSync(`${__dirname.replace('/src', '')}/_headers`, `${distDir}/_headers`);
|
|
@ -2,5 +2,31 @@ import goosemod from './goosemod.js';
|
|||
import ms2porter from './ms2porter.js';
|
||||
import bdThemes from './ports/bdThemes.js';
|
||||
|
||||
// export default bdThemes;
|
||||
export default goosemod.concat(ms2porter).concat(bdThemes);
|
||||
export default [
|
||||
{
|
||||
meta: {
|
||||
name: 'Store Core - GooseMod Modules',
|
||||
description: 'Officially published GooseMod modules.',
|
||||
},
|
||||
filename: 'goosemod',
|
||||
modules: goosemod
|
||||
},
|
||||
{
|
||||
meta: {
|
||||
name: 'Store Core - MS2Porter',
|
||||
description: 'Auto-ported MS1 (older) GooseMod modules.'
|
||||
},
|
||||
filename: 'ms2porter',
|
||||
modules: ms2porter
|
||||
},
|
||||
{
|
||||
meta: {
|
||||
name: 'Store Core - BD Themes',
|
||||
description: 'Auto-ported BD themes.'
|
||||
},
|
||||
filename: 'bdthemes',
|
||||
modules: bdThemes
|
||||
}
|
||||
];
|
||||
|
||||
// export default goosemod.concat(ms2porter).concat(bdThemes);
|
Loading…
Reference in a new issue