-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v1.0.1] Minor adjustments and fixes
- Loading branch information
Showing
8 changed files
with
170 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +1,164 @@ | ||
import esbuild from 'esbuild'; | ||
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals'; | ||
import path, { join } from 'path'; | ||
import fs, { existsSync, rmSync } from 'fs'; | ||
import _manifest from '../manifest.json'; | ||
import { Plugin } from 'replugged/dist/types/addon'; | ||
|
||
const manifest: Plugin = _manifest; | ||
|
||
const NODE_VERSION = '14'; | ||
const CHROME_VERSION = '91'; | ||
|
||
const globalModules = { | ||
replugged: { | ||
varName: 'replugged', | ||
namedExports: [ | ||
'Injector', | ||
'Logger', | ||
'webpack', | ||
'common', | ||
'notices', | ||
'commands', | ||
'settings', | ||
'quickCSS', | ||
'themes', | ||
'ignition', | ||
'plugins', | ||
'util', | ||
'types' | ||
], | ||
defaultExport: true | ||
} | ||
import esbuild from "esbuild"; | ||
import path, { join } from "path"; | ||
import fs, { existsSync, rmSync } from "fs"; | ||
import _manifest from "../manifest.json"; | ||
import { PluginManifest } from "replugged/dist/types/addon"; | ||
|
||
const manifest: PluginManifest = _manifest; | ||
|
||
const NODE_VERSION = "14"; | ||
const CHROME_VERSION = "91"; | ||
|
||
const globalModules: esbuild.Plugin = { | ||
name: "globalModules", | ||
setup: (build) => { | ||
build.onResolve({ filter: /^replugged.+$/ }, (args) => { | ||
if (args.kind !== "import-statement") return; | ||
|
||
return { | ||
errors: [ | ||
{ | ||
text: `Importing from a path (${args.path}) is not supported. Instead, please import from "replugged" and destructure the required modules.`, | ||
}, | ||
], | ||
}; | ||
}); | ||
|
||
build.onResolve({ filter: /^replugged$/ }, (args) => { | ||
if (args.kind !== "import-statement") return; | ||
|
||
return { | ||
path: args.path, | ||
namespace: "replugged", | ||
}; | ||
}); | ||
|
||
build.onLoad( | ||
{ | ||
filter: /.*/, | ||
namespace: "replugged", | ||
}, | ||
() => { | ||
return { | ||
contents: "module.exports = window.replugged", | ||
}; | ||
}, | ||
); | ||
}, | ||
}; | ||
|
||
const REPLUGGED_FOLDER_NAME = 'replugged'; | ||
const REPLUGGED_FOLDER_NAME = "replugged"; | ||
export const CONFIG_PATH = (() => { | ||
switch (process.platform) { | ||
case 'win32': | ||
return join(process.env.APPDATA || '', REPLUGGED_FOLDER_NAME); | ||
case 'darwin': | ||
return join(process.env.HOME || '', 'Library', 'Application Support', REPLUGGED_FOLDER_NAME); | ||
case "win32": | ||
return join(process.env.APPDATA || "", REPLUGGED_FOLDER_NAME); | ||
case "darwin": | ||
return join(process.env.HOME || "", "Library", "Application Support", REPLUGGED_FOLDER_NAME); | ||
default: | ||
if (process.env.XDG_CONFIG_HOME) { | ||
return join(process.env.XDG_CONFIG_HOME, REPLUGGED_FOLDER_NAME); | ||
} | ||
return join(process.env.HOME || '', '.config', REPLUGGED_FOLDER_NAME); | ||
return join(process.env.HOME || "", ".config", REPLUGGED_FOLDER_NAME); | ||
} | ||
})(); | ||
|
||
const install: esbuild.Plugin = { | ||
name: 'install', | ||
name: "install", | ||
setup: (build) => { | ||
build.onEnd(() => { | ||
if (!process.env.NO_INSTALL) { | ||
const dest = join(CONFIG_PATH, 'plugins', manifest.id); | ||
const dest = join(CONFIG_PATH, "plugins", manifest.id); | ||
if (existsSync(dest)) { | ||
rmSync(dest, { recursive: true }); | ||
} | ||
fs.cpSync('dist', dest, { recursive: true }); | ||
console.log('Installed updated version'); | ||
fs.cpSync("dist", dest, { recursive: true }); | ||
console.log("Installed updated version"); | ||
} | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
const watch = process.argv.includes('--watch'); | ||
const watch = process.argv.includes("--watch"); | ||
|
||
const common: esbuild.BuildOptions = { | ||
absWorkingDir: path.join(__dirname, '..'), | ||
absWorkingDir: path.join(__dirname, ".."), | ||
bundle: true, | ||
minify: false, | ||
sourcemap: true, | ||
format: 'cjs' as esbuild.Format, | ||
logLevel: 'info', | ||
format: "cjs" as esbuild.Format, | ||
logLevel: "info", | ||
watch, | ||
plugins: [install] | ||
plugins: [install], | ||
}; | ||
|
||
const targets = []; | ||
|
||
if ('renderer' in manifest) { | ||
if ("renderer" in manifest) { | ||
targets.push( | ||
esbuild.build({ | ||
...common, | ||
entryPoints: [manifest.renderer], | ||
platform: 'browser', | ||
platform: "browser", | ||
target: `chrome${CHROME_VERSION}`, | ||
outfile: 'dist/renderer.js', | ||
format: 'esm' as esbuild.Format, | ||
plugins: [globalExternals(globalModules), install] | ||
}) | ||
outfile: "dist/renderer.js", | ||
format: "esm" as esbuild.Format, | ||
plugins: [globalModules, install], | ||
}), | ||
); | ||
|
||
manifest.renderer = 'renderer.js'; | ||
manifest.renderer = "renderer.js"; | ||
} | ||
|
||
if ('preload' in manifest) { | ||
if ("preload" in manifest) { | ||
targets.push( | ||
esbuild.build({ | ||
...common, | ||
entryPoints: [manifest.preload], | ||
platform: 'node', | ||
platform: "node", | ||
target: [`node${NODE_VERSION}`, `chrome${CHROME_VERSION}`], | ||
outfile: 'dist/preload.js', | ||
external: ['electron'] | ||
}) | ||
outfile: "dist/preload.js", | ||
external: ["electron"], | ||
}), | ||
); | ||
|
||
manifest.preload = 'preload.js'; | ||
manifest.preload = "preload.js"; | ||
} | ||
|
||
if ('main' in manifest) { | ||
if ("main" in manifest) { | ||
targets.push( | ||
esbuild.build({ | ||
...common, | ||
entryPoints: [manifest.main], | ||
platform: 'node', | ||
platform: "node", | ||
target: `node${NODE_VERSION}`, | ||
outfile: 'dist/main.js', | ||
external: ['electron'] | ||
}) | ||
outfile: "dist/main.js", | ||
external: ["electron"], | ||
}), | ||
); | ||
|
||
manifest.main = 'main.js'; | ||
manifest.main = "main.js"; | ||
} | ||
|
||
if ('plaintextPatches' in manifest) { | ||
if ("plaintextPatches" in manifest) { | ||
targets.push( | ||
esbuild.build({ | ||
...common, | ||
entryPoints: [manifest.plaintextPatches], | ||
platform: 'browser', | ||
platform: "browser", | ||
target: `chrome${CHROME_VERSION}`, | ||
outfile: 'dist/plaintextPatches.js', | ||
format: 'esm' as esbuild.Format, | ||
plugins: [globalExternals(globalModules), install] | ||
}) | ||
outfile: "dist/plaintextPatches.js", | ||
format: "esm" as esbuild.Format, | ||
plugins: [globalModules, install], | ||
}), | ||
); | ||
|
||
manifest.plaintextPatches = 'plaintextPatches.js'; | ||
manifest.plaintextPatches = "plaintextPatches.js"; | ||
} | ||
|
||
if (!fs.existsSync('dist')) { | ||
fs.mkdirSync('dist'); | ||
if (!fs.existsSync("dist")) { | ||
fs.mkdirSync("dist"); | ||
} | ||
|
||
fs.writeFileSync('dist/manifest.json', JSON.stringify(manifest)); | ||
fs.writeFileSync("dist/manifest.json", JSON.stringify(manifest)); | ||
|
||
Promise.all(targets); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import asar from '@electron/asar'; | ||
import { readFileSync } from 'fs'; | ||
import { Plugin } from 'replugged/dist/types/addon'; | ||
import asar from "@electron/asar"; | ||
import { readFileSync } from "fs"; | ||
import { PluginManifest } from "replugged/dist/types/addon"; | ||
|
||
const manifest = JSON.parse(readFileSync('manifest.json', 'utf-8')) as Plugin; | ||
const manifest = JSON.parse(readFileSync("manifest.json", "utf-8")) as PluginManifest; | ||
const outputName = `${manifest.id}.asar`; | ||
|
||
asar.createPackage('dist', outputName); | ||
asar.createPackage("dist", outputName); |
Oops, something went wrong.