2021-02-12 17:06:15 +00:00
|
|
|
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
|
|
|
|
|
|
|
export default (manifestPath, repo) => {
|
|
|
|
const pcManifest = JSON.parse(readFileSync(manifestPath));
|
|
|
|
|
|
|
|
const manifest = {
|
|
|
|
main: 'index.js',
|
|
|
|
tags: ['theme', 'port'],
|
|
|
|
|
|
|
|
name: pcManifest.name,
|
|
|
|
description: pcManifest.description,
|
|
|
|
|
|
|
|
version: pcManifest.version,
|
2021-03-07 15:38:12 +00:00
|
|
|
authors: [pcManifest.author],
|
2021-02-12 17:06:15 +00:00
|
|
|
};
|
|
|
|
|
2021-03-07 15:38:12 +00:00
|
|
|
rmSync(manifestPath);
|
|
|
|
mkdirSync(manifestPath);
|
|
|
|
|
|
|
|
if (pcManifest.theme.split('.').pop() === 'scss') {
|
|
|
|
const cssPath = pcManifest.theme.split('.').slice(0, -1).concat('css').join('.');
|
|
|
|
|
|
|
|
const compiled = sass.renderSync({ file: pcManifest.theme }).css;
|
|
|
|
writeFileSync(cssPath, compiled);
|
|
|
|
|
|
|
|
pcManifest.theme = cssPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = readFileSync(pcManifest.theme, 'utf8');
|
2021-02-12 17:06:15 +00:00
|
|
|
|
|
|
|
const jsCode = `// Generated by MS2Builder - pcTheme preprocessor / porter
|
|
|
|
let style;
|
|
|
|
|
|
|
|
export default {
|
|
|
|
goosemodHandlers: {
|
|
|
|
onImport: async () => {
|
|
|
|
style = document.createElement("style");
|
|
|
|
document.head.appendChild(style);
|
|
|
|
style.appendChild(
|
|
|
|
document.createTextNode(
|
|
|
|
\`${content}\`
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2021-03-07 15:38:12 +00:00
|
|
|
|
2021-02-12 17:06:15 +00:00
|
|
|
onRemove: async () => {
|
|
|
|
style.remove();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};`;
|
|
|
|
|
|
|
|
writeFileSync(`${themePath}/goosemodModule.json`, JSON.stringify(manifest));
|
|
|
|
writeFileSync(`${themePath}/index.js`, jsCode);
|
|
|
|
};
|