[PCPlugin] Fix loadStylesheet CSS-only not working (2)
This commit is contained in:
parent
46ec3f8c35
commit
95d3c0b7a4
|
@ -1,4 +1,5 @@
|
||||||
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
||||||
|
import sass from 'sass';
|
||||||
|
|
||||||
export default (manifestPath, repo) => {
|
export default (manifestPath, repo) => {
|
||||||
const pcManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
const pcManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||||
|
@ -19,21 +20,21 @@ export default (manifestPath, repo) => {
|
||||||
|
|
||||||
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 = class`, `export default new class`);
|
content = content.replace(`module.exports = `, `export default new `);
|
||||||
content = content.replace(/this\.loadStylesheet\(['"`](.*)['"`]\)/g, (_, relative) => {
|
content = content.replace(/this\.loadStylesheet\(['"`](.*)['"`]\)/g, (_, relative) => {
|
||||||
const path = manifestPath.split('/').slice(0, -1).join('/') + relative;
|
const path = manifestPath.split('/').slice(0, -1).concat('').join('/') + relative;
|
||||||
|
|
||||||
let css;
|
let css;
|
||||||
|
|
||||||
if (path.split('.').pop() === 'scss') {
|
if (path.split('.').pop() === 'scss') {
|
||||||
css = (sass.renderSync({ file: path })).css;
|
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
|
||||||
|
|
||||||
return `this.loadStyleSheet(\`${css}\`)`;
|
return `this.loadStylesheet(\`${css}\`)`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const jsCode = `import powercord from '_powercord/global';\n` + content;
|
const jsCode = `import powercord from '_powercord/global';\n` + content;
|
||||||
|
|
Loading…
Reference in New Issue