mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
Compare commits
13 commits
3fb7cbb447
...
5cf8fdf942
Author | SHA1 | Date | |
---|---|---|---|
5cf8fdf942 | |||
4469096b7b | |||
9817fd9cce | |||
51407b9720 | |||
21f501ed56 | |||
1ceaa42fd1 | |||
0c62c9b764 | |||
f2b397fdbc | |||
e6e0e54913 | |||
4d1016516b | |||
3f561aff35 | |||
95d3c0b7a4 | |||
46ec3f8c35 |
9 changed files with 213 additions and 39 deletions
7
moduleWrappers/electron/clipboard.js
Normal file
7
moduleWrappers/electron/clipboard.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export const writeText = (text) => { // Write text to clipboard
|
||||||
|
return DiscordNative.clipboard.copy(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const readText = () => { // Read text from clipboard
|
||||||
|
return DiscordNative.clipboard.read();
|
||||||
|
};
|
1
moduleWrappers/electron/index.js
Normal file
1
moduleWrappers/electron/index.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * as clipboard from './clipboard';
|
|
@ -8,6 +8,8 @@ export const registerSettings = (id, { label, render, category }) => {
|
||||||
const FormTitle = goosemodScope.webpackModules.findByDisplayName('FormTitle');
|
const FormTitle = goosemodScope.webpackModules.findByDisplayName('FormTitle');
|
||||||
const FormSection = goosemodScope.webpackModules.findByDisplayName('FormSection');
|
const FormSection = goosemodScope.webpackModules.findByDisplayName('FormSection');
|
||||||
|
|
||||||
|
if (!Settings.settingStores[category]) Settings.makeStore(category);
|
||||||
|
|
||||||
goosemodScope.patcher.inject(id, SettingsView.prototype, 'getPredicateSections', (_, sections) => {
|
goosemodScope.patcher.inject(id, SettingsView.prototype, 'getPredicateSections', (_, sections) => {
|
||||||
const logout = sections.find((c) => c.section === 'logout');
|
const logout = sections.find((c) => c.section === 'logout');
|
||||||
if (!logout) return sections;
|
if (!logout) return sections;
|
||||||
|
@ -22,7 +24,7 @@ export const registerSettings = (id, { label, render, category }) => {
|
||||||
element: () => React.createElement(FormSection, { },
|
element: () => React.createElement(FormSection, { },
|
||||||
React.createElement(FormTitle, { tag: 'h2' }, finalLabel),
|
React.createElement(FormTitle, { tag: 'h2' }, finalLabel),
|
||||||
|
|
||||||
render({
|
React.createElement(render, {
|
||||||
...Settings.settingStores[category]
|
...Settings.settingStores[category]
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
16
package.json
16
package.json
|
@ -2,26 +2,34 @@
|
||||||
"name": "ms2builder",
|
"name": "ms2builder",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Builder for Module Store v2.",
|
"description": "Builder for Module Store v2.",
|
||||||
|
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"theme": "node ./scripts/add.js theme"
|
"theme": "node ./scripts/add.js theme",
|
||||||
|
"pccompatcheck": "node ./scripts/pccompatCheck.js"
|
||||||
},
|
},
|
||||||
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/GooseMod/MS2Builder.git"
|
"url": "git+https://github.com/GooseMod/MS2Builder.git"
|
||||||
},
|
},
|
||||||
|
|
||||||
"author": "GooseMod",
|
"author": "GooseMod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/GooseMod/MS2Builder/issues"
|
"url": "https://github.com/GooseMod/MS2Builder/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/GooseMod/MS2Builder#readme",
|
"homepage": "https://github.com/GooseMod/MS2Builder#readme",
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"glob": "^7.1.6",
|
"glob": "^7.1.6",
|
||||||
"parcel-bundler": "^1.12.4",
|
"parcel-bundler": "^1.12.4",
|
||||||
"sass": "^1.32.8"
|
"sass": "^1.32.8"
|
||||||
},
|
},
|
||||||
|
|
||||||
"alias": {
|
"alias": {
|
||||||
"@goosemod/patcher": "./moduleWrappers/goosemod/patcher.js",
|
"@goosemod/patcher": "./moduleWrappers/goosemod/patcher.js",
|
||||||
"@goosemod/webpack": "./moduleWrappers/goosemod/webpack.js",
|
"@goosemod/webpack": "./moduleWrappers/goosemod/webpack.js",
|
||||||
|
@ -29,13 +37,17 @@
|
||||||
"@goosemod/reactUtils": "./moduleWrappers/goosemod/reactUtils.js",
|
"@goosemod/reactUtils": "./moduleWrappers/goosemod/reactUtils.js",
|
||||||
"@goosemod/toast": "./moduleWrappers/goosemod/toast.js",
|
"@goosemod/toast": "./moduleWrappers/goosemod/toast.js",
|
||||||
"@goosemod/settings": "./moduleWrappers/goosemod/settings.js",
|
"@goosemod/settings": "./moduleWrappers/goosemod/settings.js",
|
||||||
|
|
||||||
"powercord/entities": "./moduleWrappers/powercord/entities.js",
|
"powercord/entities": "./moduleWrappers/powercord/entities.js",
|
||||||
"powercord/injector": "./moduleWrappers/powercord/injector.js",
|
"powercord/injector": "./moduleWrappers/powercord/injector.js",
|
||||||
"powercord/webpack": "./moduleWrappers/powercord/webpack.js",
|
"powercord/webpack": "./moduleWrappers/powercord/webpack.js",
|
||||||
"powercord/util": "./moduleWrappers/powercord/util.js",
|
"powercord/util": "./moduleWrappers/powercord/util.js",
|
||||||
"powercord/components/settings": "./moduleWrappers/powercord/components/settings/index.js",
|
"powercord/components/settings": "./moduleWrappers/powercord/components/settings/index.js",
|
||||||
|
|
||||||
"_powercord/global": "./moduleWrappers/powercord/global/index.js"
|
"_powercord/global": "./moduleWrappers/powercord/global/index.js",
|
||||||
|
|
||||||
|
"electron": "./moduleWrappers/electron/index.js"
|
||||||
},
|
},
|
||||||
|
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,36 @@
|
||||||
import { createInterface } from 'readline';
|
import { createInterface } from 'readline';
|
||||||
import { readFileSync, writeFileSync } from 'fs';
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
|
|
||||||
|
import { exec as _exec } from 'child_process';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
|
||||||
|
const exec = promisify(_exec);
|
||||||
|
|
||||||
const rl = createInterface({
|
const rl = createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
|
|
||||||
const [ type1, type2, repo ] = process.argv.slice(2);
|
|
||||||
|
|
||||||
console.log(type1, type2, repo);
|
const [ type1, type2, repo, subpath ] = process.argv.slice(2);
|
||||||
|
|
||||||
|
console.log(type1, type2, repo, subpath);
|
||||||
|
|
||||||
|
const ask = async (prompt) => {
|
||||||
|
return await new Promise((resp) => {
|
||||||
|
rl.question(prompt, (ans) => {
|
||||||
|
resp(ans);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const repeatAsk = async (prompt) => {
|
const repeatAsk = async (prompt) => {
|
||||||
const answers = [];
|
const answers = [];
|
||||||
|
|
||||||
const ask = async () => {
|
|
||||||
return await new Promise((resp) => {
|
|
||||||
rl.question(prompt, (ans) => {
|
|
||||||
resp(ans);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
let ans;
|
let ans;
|
||||||
|
|
||||||
while (ans !== '') {
|
while (ans !== '') {
|
||||||
ans = await ask();
|
ans = await ask(prompt);
|
||||||
if (ans === '') break;
|
if (ans === '') break;
|
||||||
|
|
||||||
answers.push(ans);
|
answers.push(ans);
|
||||||
|
@ -57,6 +63,16 @@ switch (type1) {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'bd': {
|
||||||
|
file = `src/modules/ports/themes/bdThemes.js`;
|
||||||
|
js = ` ['${repo}', '', '${subpath}', 'bdTheme', {
|
||||||
|
authors: ${JSON.stringify(authors)},
|
||||||
|
images: ${JSON.stringify(images)}
|
||||||
|
}],`;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -73,4 +89,26 @@ contents = contents.join('\n');
|
||||||
|
|
||||||
writeFileSync(file, contents);
|
writeFileSync(file, contents);
|
||||||
|
|
||||||
|
const shouldCommit = await new Promise((resp) => {
|
||||||
|
rl.question(`Continue with automated Git (Y/N) > `, (ans) => {
|
||||||
|
resp(ans);
|
||||||
|
});
|
||||||
|
}) === 'Y';
|
||||||
|
|
||||||
|
if (shouldCommit) {
|
||||||
|
console.log('Building...');
|
||||||
|
|
||||||
|
await exec(`node src/index.js`);
|
||||||
|
|
||||||
|
console.log('Committing...');
|
||||||
|
|
||||||
|
await exec(`git add dist ${file}`);
|
||||||
|
|
||||||
|
await exec(`git commit -m "[(Auto) Add Theme (${type2.toUpperCase()}Theme)] ${repo}"`);
|
||||||
|
|
||||||
|
console.log('Pushing...');
|
||||||
|
|
||||||
|
await exec(`git push`);
|
||||||
|
}
|
||||||
|
|
||||||
rl.close();
|
rl.close();
|
82
scripts/pccompatCheck.js
Normal file
82
scripts/pccompatCheck.js
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import { exec } from 'child_process';
|
||||||
|
|
||||||
|
import { join, dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import { existsSync, readFileSync } from 'fs';
|
||||||
|
|
||||||
|
import glob from 'glob';
|
||||||
|
|
||||||
|
function underline(text) {
|
||||||
|
return `\x1b[4m${text}\x1b[0m`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
const { alias } = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
|
||||||
|
|
||||||
|
|
||||||
|
const clonesDir = join(__dirname, '..', 'clones');
|
||||||
|
|
||||||
|
const [ repo ] = process.argv.slice(2);
|
||||||
|
|
||||||
|
const cloneDir = join(clonesDir, repo);
|
||||||
|
const url = `https://github.com/${repo}.git`;
|
||||||
|
|
||||||
|
console.log(cloneDir, url);
|
||||||
|
|
||||||
|
if (!existsSync(cloneDir)) {
|
||||||
|
await new Promise((res) => exec(`git clone ${url} ${cloneDir}`, res));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
for (const jsFile of glob.sync(`${cloneDir}/**/*.js`).concat(glob.sync(`${cloneDir}/**/*.jsx`))) {
|
||||||
|
console.log(underline(jsFile.replace(cloneDir, '')));
|
||||||
|
|
||||||
|
const js = readFileSync(jsFile, 'utf8');
|
||||||
|
|
||||||
|
let match;
|
||||||
|
const importRegex = /{ *(.*,*) *} *= *require\(('|"|`)(.*)('|"|`)\)/g;
|
||||||
|
|
||||||
|
while ((match = importRegex.exec(js)) !== null) {
|
||||||
|
let [ _1, imports, _2, requirePath, _3 ] = match;
|
||||||
|
imports = imports.trim();
|
||||||
|
|
||||||
|
if (requirePath.includes('.')) continue;
|
||||||
|
|
||||||
|
const aliasPath = alias[requirePath];
|
||||||
|
|
||||||
|
if (!aliasPath) {
|
||||||
|
console.log('No alias', requirePath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const aliasJS = readFileSync(join(__dirname, '..', aliasPath), 'utf8');
|
||||||
|
|
||||||
|
for (let imp of imports.split(',')) {
|
||||||
|
imp = imp.trim().split(':')[0];
|
||||||
|
|
||||||
|
const searchRegex = new RegExp(`^export.*${imp}.*$`, 'gm');
|
||||||
|
|
||||||
|
const searchMatch = aliasJS.match(searchRegex);
|
||||||
|
|
||||||
|
if (!searchMatch) {
|
||||||
|
if (requirePath === 'powercord/webpack') {
|
||||||
|
const webpackJS = readFileSync(join(__dirname, '..', '..', 'GooseMod', 'src', 'util', 'discord', 'webpackModules.js'), 'utf8');
|
||||||
|
|
||||||
|
if (imp.startsWith('getModule') || webpackJS.includes(`obj.common.${imp}`)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requirePath === 'powercord/injector') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('No export', requirePath, imp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log();
|
||||||
|
}
|
42
src/index.js
42
src/index.js
|
@ -103,25 +103,29 @@ for (const parentRepo of ModuleRepos) {
|
||||||
|
|
||||||
const name = repo[0];
|
const name = repo[0];
|
||||||
const cloneDir = `${clonesDir}/${name}`;
|
const cloneDir = `${clonesDir}/${name}`;
|
||||||
const moduleDir = repo[2] || '';
|
let moduleDir = repo[2] || '';
|
||||||
|
|
||||||
if (previous.includes(repo)) {
|
try {
|
||||||
let currentModule = currentRepoJson.modules.filter((x) => x.github.repo === repo[0]);
|
if (previous.includes(repo)) {
|
||||||
if (currentModule.length > 1) {
|
let currentModule = currentRepoJson.modules.filter((x) => x.github.repo === repo[0]);
|
||||||
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
if (currentModule.length > 1) {
|
||||||
|
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
||||||
|
|
||||||
currentModule = currentModule.find((x) => x.name === manifest.name);
|
currentModule = currentModule.find((x) => x.name === manifest.name);
|
||||||
} else {
|
} else {
|
||||||
currentModule = currentModule[0];
|
currentModule = currentModule[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleJson.modules.push(currentModule);
|
||||||
|
|
||||||
|
process.stdout.write('[SKIP] ');
|
||||||
|
|
||||||
|
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
moduleJson.modules.push(currentModule);
|
console.log('Cache fail', repo[0], e);
|
||||||
|
|
||||||
process.stdout.write('[SKIP] ');
|
|
||||||
|
|
||||||
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let githubInfo = getGithubInfo(repo[0]);
|
let githubInfo = getGithubInfo(repo[0]);
|
||||||
|
@ -155,7 +159,11 @@ for (const parentRepo of ModuleRepos) {
|
||||||
await new Promise((res) => exec(`git checkout ${commitHash}`, res));
|
await new Promise((res) => exec(`git checkout ${commitHash}`, res));
|
||||||
|
|
||||||
if (preprocessor) {
|
if (preprocessor) {
|
||||||
(await import(`./preprocessors/${preprocessor}.js`)).default(`${cloneDir}${moduleDir}`, repo);
|
const preOut = (await import(`./preprocessors/${preprocessor}.js`)).default(`${cloneDir}${moduleDir}`, repo);
|
||||||
|
|
||||||
|
if (preOut !== undefined) {
|
||||||
|
moduleDir = preOut;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
const manifest = JSON.parse(readFileSync(`${cloneDir}${moduleDir}/goosemodModule.json`));
|
||||||
|
|
|
@ -12,9 +12,11 @@ export default (themePath, repo) => {
|
||||||
|
|
||||||
let match;
|
let match;
|
||||||
while ((match = metaReg.exec(content)) !== null) {
|
while ((match = metaReg.exec(content)) !== null) {
|
||||||
const [_, key, value] = match;
|
let [_, key, value] = match;
|
||||||
if (key === 'import') break;
|
if (key === 'import') break;
|
||||||
|
|
||||||
|
value = value.trim();
|
||||||
|
|
||||||
// console.log(key, value);
|
// console.log(key, value);
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
|
import { join } from 'path';
|
||||||
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
||||||
|
|
||||||
import sass from 'sass';
|
import sass from 'sass';
|
||||||
|
import glob from 'glob';
|
||||||
|
|
||||||
export default (manifestPath, repo) => {
|
export default (manifestPath, repo) => {
|
||||||
|
const baseDir = join(manifestPath, '..');
|
||||||
|
|
||||||
const pcManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
const pcManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||||
|
|
||||||
let manifest = {
|
let manifest = {
|
||||||
main: '../index.js',
|
main: 'index.js',
|
||||||
tags: ['port'],
|
tags: ['port'],
|
||||||
|
|
||||||
name: pcManifest.name,
|
name: pcManifest.name,
|
||||||
|
@ -15,9 +20,6 @@ export default (manifestPath, repo) => {
|
||||||
authors: [ pcManifest.author ]
|
authors: [ pcManifest.author ]
|
||||||
};
|
};
|
||||||
|
|
||||||
rmSync(manifestPath);
|
|
||||||
mkdirSync(manifestPath);
|
|
||||||
|
|
||||||
let content = readFileSync(pcManifest.main || 'index.js', 'utf8');//.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
|
let content = readFileSync(pcManifest.main || 'index.js', 'utf8');//.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
|
||||||
|
|
||||||
content = content.replace(`module.exports = `, `export default new `);
|
content = content.replace(`module.exports = `, `export default new `);
|
||||||
|
@ -29,7 +31,7 @@ export default (manifestPath, repo) => {
|
||||||
if (path.split('.').pop() === 'scss') {
|
if (path.split('.').pop() === 'scss') {
|
||||||
css = (sass.renderSync({ file: path })).css.toString('utf8');
|
css = (sass.renderSync({ file: path })).css.toString('utf8');
|
||||||
} else {
|
} else {
|
||||||
css = readFileSync(sync);
|
css = readFileSync(path, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
css = css.replace(/\\/g, '\\\\').replace(/\`/g, '\`'); // Escape backticks
|
css = css.replace(/\\/g, '\\\\').replace(/\`/g, '\`'); // Escape backticks
|
||||||
|
@ -37,8 +39,28 @@ export default (manifestPath, repo) => {
|
||||||
return `this.loadStylesheet(\`${css}\`)`;
|
return `this.loadStylesheet(\`${css}\`)`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const jsCode = `import powercord from '_powercord/global';\n` + content;
|
writeFileSync(join(baseDir, `index.js`), content);
|
||||||
|
|
||||||
writeFileSync(`${manifestPath}/goosemodModule.json`, JSON.stringify(manifest));
|
for (const jsFile of glob.sync(`${baseDir}/**/*.js`)) {
|
||||||
writeFileSync(`${manifestPath}/../index.js`, jsCode);
|
console.log(jsFile);
|
||||||
|
let content = readFileSync(jsFile, 'utf8');
|
||||||
|
|
||||||
|
/* Here we preappend some JS to each file to match context and fix some weird bundler bugs:
|
||||||
|
- Import our own Powercord global
|
||||||
|
- Fix dynamic imports (like using require("powercord/" + someVariable)) causing errors (due to no static analyse). Do this because some plugins use it for PC + VZ compat with the same JS
|
||||||
|
*/
|
||||||
|
|
||||||
|
content = `import powercord from '_powercord/global';
|
||||||
|
require.cache['powercord/entities'] = require('powercord/entities');
|
||||||
|
require.cache['powercord/components/settings'] = require('powercord/components/settings');
|
||||||
|
require.cache['powercord/webpack'] = require('powercord/webpack');
|
||||||
|
|
||||||
|
${content}`;
|
||||||
|
|
||||||
|
writeFileSync(jsFile, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync(join(baseDir, `goosemodModule.json`), JSON.stringify(manifest));
|
||||||
|
|
||||||
|
return '';
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue