2021-02-12 17:06:15 +00:00
|
|
|
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
|
2021-03-02 14:17:56 +00:00
|
|
|
import sass from 'sass';
|
2021-02-12 17:06:15 +00:00
|
|
|
|
2021-07-17 19:49:12 +00:00
|
|
|
import generateThemeJS from './genericTheme.js';
|
|
|
|
|
|
|
|
export default async (manifestPath, repo) => {
|
2021-03-02 11:03:28 +00:00
|
|
|
const pcManifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
2021-02-12 17:06:15 +00:00
|
|
|
|
2021-03-02 15:03:12 +00:00
|
|
|
let manifest = {
|
2021-02-12 17:06:15 +00:00
|
|
|
main: 'index.js',
|
|
|
|
tags: ['theme', 'port'],
|
|
|
|
|
|
|
|
name: pcManifest.name,
|
|
|
|
description: pcManifest.description,
|
|
|
|
|
|
|
|
version: pcManifest.version,
|
2021-07-17 19:49: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('.');
|
|
|
|
|
2021-07-17 19:49:12 +00:00
|
|
|
const compiled = sass.renderSync({ file: pcManifest.theme }).css;
|
2021-03-07 15:38:12 +00:00
|
|
|
writeFileSync(cssPath, compiled);
|
|
|
|
|
|
|
|
pcManifest.theme = cssPath;
|
|
|
|
}
|
|
|
|
|
2021-06-20 11:16:56 +00:00
|
|
|
const content = readFileSync(pcManifest.theme, 'utf8');
|
2021-02-12 17:06:15 +00:00
|
|
|
|
2021-07-17 19:49:12 +00:00
|
|
|
const jsCode = await generateThemeJS(manifest, content, repo);
|
2021-02-12 17:06:15 +00:00
|
|
|
|
2021-03-02 11:03:28 +00:00
|
|
|
writeFileSync(`${manifestPath}/goosemodModule.json`, JSON.stringify(manifest));
|
|
|
|
writeFileSync(`${manifestPath}/index.js`, jsCode);
|
2021-02-12 17:06:15 +00:00
|
|
|
};
|