Skip to content

Commit

Permalink
feat: publish
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed Jun 15, 2024
1 parent 1b233a5 commit 3bf21cf
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.temp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion .publish/publish.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"publishName":"birds-of-a-feather-0219923154d2c7df0ed4d2029b1e02c8","packageName":"birds-of-a-feather","hash":"0219923154d2c7df0ed4d2029b1e02c8","config":{"name":"飞鸟","preview":"@/imgs/preview.png","author":"猫头猫","iframe":{"app":"@/iframes/app.html"},"hash":"0219923154d2c7df0ed4d2029b1e02c8"},"id":"V52fVc-ztv1cG_mxgFs4f"},{"publishName":"darkmode-c0238407c96c524901448792c7dea789","packageName":"darkmode","hash":"c0238407c96c524901448792c7dea789","config":{"name":"暗黑模式","preview":"#000","author":"猫头猫","description":"暗黑模式,好黑啊。","hash":"c0238407c96c524901448792c7dea789"},"id":"Jh53eoHmKOL0lQOw7T4ji"},{"publishName":"fliqlo-1c22f4d7cd525e5fd300c72d77cdb93e","packageName":"fliqlo","hash":"1c22f4d7cd525e5fd300c72d77cdb93e","config":{"name":"fliqlo","preview":"@/imgs/preview.png","description":"类似fliqlo的效果","author":"猫头猫","iframe":{"app":"@/iframes/app.html"},"hash":"1c22f4d7cd525e5fd300c72d77cdb93e"},"id":"RpUgsCFv2uNOQEpxaMfag"},{"publishName":"night-star-7d743fe3c120b98c91c56db9dc6329fa","packageName":"night-star","hash":"7d743fe3c120b98c91c56db9dc6329fa","config":{"name":"星夜","preview":"@/assets/night_sky_stars_linear_gradient_hd_8k_anime_style_8013dbdf-270b-4f00-b981-5745e056aae3.png","description":"背景图片","author":"猫头猫","hash":"7d743fe3c120b98c91c56db9dc6329fa"},"id":"EIY5V7tND8S8udI_qqAdO"},{"publishName":"rainy-season-13a6dee9c7e8c3d89f22570d63938405","packageName":"rainy-season","hash":"13a6dee9c7e8c3d89f22570d63938405","config":{"name":"雨季","preview":"@/imgs/preview.png","iframe":{"app":"@/iframes/app.html"},"author":"猫头猫","hash":"13a6dee9c7e8c3d89f22570d63938405"},"id":"fqDKd1xoZ6_flNjhsRi9T"},{"publishName":"sakura-c487bf32e75aa5d59e2bef0ada6d2327","packageName":"sakura","hash":"c487bf32e75aa5d59e2bef0ada6d2327","config":{"name":"樱花","preview":"@/imgs/preview.png","iframe":{"app":"@/iframes/app.html"},"author":"猫头猫","hash":"c487bf32e75aa5d59e2bef0ada6d2327"},"id":"4C3iJxQc5o-9QEIF7Ih0_"},{"publishName":"word-rain-11dc84296d4308b28a4b182a0debbd26","packageName":"word-rain","hash":"11dc84296d4308b28a4b182a0debbd26","config":{"name":"Hacker","preview":"@/imgs/preview.png","iframe":{"app":"@/iframes/app.html"},"author":"猫头猫","description":"背景源代码:https://codesandbox.io/embed/word-rain-e4itf","hash":"11dc84296d4308b28a4b182a0debbd26"},"id":"_Cv5IxWH8WIUd24j-RQgy"}]
[{"publishName":"birds-of-a-feather-9af3beedd42c542631dc3eeba593de2c","packageName":"birds-of-a-feather","hash":"9af3beedd42c542631dc3eeba593de2c","config":{"name":"飞鸟","preview":"@/imgs/preview.png","author":"猫头猫","iframe":{"app":"@/iframes/app.html"},"id":"V52fVc-ztv1cG_mxgFs4f"},"id":"V52fVc-ztv1cG_mxgFs4f"},{"publishName":"darkmode-ab289de60695955be65d5b9eae86cee7","packageName":"darkmode","hash":"ab289de60695955be65d5b9eae86cee7","config":{"name":"暗黑模式","preview":"#000","author":"猫头猫","description":"暗黑模式,好黑啊。","id":"Jh53eoHmKOL0lQOw7T4ji"},"id":"Jh53eoHmKOL0lQOw7T4ji"},{"publishName":"fliqlo-dc12edbff95da5745709ec2440f543d1","packageName":"fliqlo","hash":"dc12edbff95da5745709ec2440f543d1","config":{"name":"fliqlo","preview":"@/imgs/preview.png","description":"类似fliqlo的效果","author":"猫头猫","iframe":{"app":"@/iframes/app.html"},"id":"RpUgsCFv2uNOQEpxaMfag"},"id":"RpUgsCFv2uNOQEpxaMfag"},{"publishName":"night-star-e85237fa4afd8da1101835c36c9811b9","packageName":"night-star","hash":"e85237fa4afd8da1101835c36c9811b9","config":{"name":"星夜","preview":"@/assets/night_sky_stars_linear_gradient_hd_8k_anime_style_8013dbdf-270b-4f00-b981-5745e056aae3.png","description":"背景图片","author":"猫头猫","id":"EIY5V7tND8S8udI_qqAdO"},"id":"EIY5V7tND8S8udI_qqAdO"},{"publishName":"rainy-season-ae8cef0d32657fe8f2962ae4e5ab43ae","packageName":"rainy-season","hash":"ae8cef0d32657fe8f2962ae4e5ab43ae","config":{"name":"雨季","preview":"@/imgs/preview.png","iframe":{"app":"@/iframes/app.html"},"author":"猫头猫","id":"fqDKd1xoZ6_flNjhsRi9T"},"id":"fqDKd1xoZ6_flNjhsRi9T"},{"publishName":"sakura-a31547fc71e5cd14a685cc6739304d7d","packageName":"sakura","hash":"a31547fc71e5cd14a685cc6739304d7d","config":{"name":"樱花","preview":"@/imgs/preview.png","iframe":{"app":"@/iframes/app.html"},"author":"猫头猫","id":"4C3iJxQc5o-9QEIF7Ih0_"},"id":"4C3iJxQc5o-9QEIF7Ih0_"},{"publishName":"word-rain-c21838312c1f0c6d81a469c65ecf480e","packageName":"word-rain","hash":"c21838312c1f0c6d81a469c65ecf480e","config":{"name":"Hacker","preview":"@/imgs/preview.png","iframe":{"app":"@/iframes/app.html"},"author":"猫头猫","description":"背景源代码:https://codesandbox.io/embed/word-rain-e4itf","id":"_Cv5IxWH8WIUd24j-RQgy"},"id":"_Cv5IxWH8WIUd24j-RQgy"}]
Binary file not shown.
Binary file not shown.
Binary file not shown.
49 changes: 32 additions & 17 deletions .scripts/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ async function publish() {
await rimraf('./.publish/*', {
'glob': true
});
await rimraf('./.temp/*', {
'glob': true
});

const metaConfig = await fs.readFile("./meta.json", 'utf-8');
const meta = safeParse(metaConfig);
Expand All @@ -28,9 +31,31 @@ async function publish() {
})).filter(it => it.isDirectory() && !it.name.startsWith('.') && !exceptionFolders.includes(it.name)).sort((a, b) => a.name.localeCompare(b.name));
const themeConfigs = await Promise.all(validFolders.map(async folder => {
try {
const configFile = await fs.readFile(`./${folder.name}/config.json`, 'utf-8');
const themeMeta = meta[folder.name] || {};
meta[folder.name] = themeMeta;

// INIT META
if (!themeMeta.id) {
themeMeta.id = nanoid();
}

// copy to temp folder
await fs.cp(`./${folder.name}`, `./.temp/${folder.name}`, {
recursive: true
});


const hash = CryptoJS.MD5(configFile).toString(CryptoJS.enc.Hex);
const rawConfig = JSON.parse(await fs.readFile(`./${folder.name}/config.json`, 'utf-8'));

const mergedConfig = {
...rawConfig,
...themeMeta
};

const mergedConfigStr = JSON.stringify(mergedConfig);
await fs.writeFile(`./.temp/${folder.name}/config.json`, mergedConfigStr, 'utf-8');

const hash = CryptoJS.MD5(mergedConfigStr).toString(CryptoJS.enc.Hex);

const archive = archiver('zip');
const outputName = `${folder.name}-${hash}`;
Expand All @@ -44,33 +69,23 @@ async function publish() {


archive.pipe(output);
archive.directory(`./${folder.name}`, false);
archive.directory(`./.temp/${folder.name}`, false);
archive.finalize();
await promise;

const config = JSON.parse(configFile);
config.hash = hash;

// meta
const themeMeta = meta[folder.name] || {};
if (!themeMeta.id) {
themeMeta.id = nanoid();
}

meta[folder.name] = themeMeta;

return {
publishName: outputName,
packageName: folder.name,
hash,
config,
...themeMeta,
config: mergedConfig,
...themeMeta
}

} catch(e) {
// ignore
console.log(2, e)
return null;
} finally {
await rimraf(`./.temp/${folder.name}`);
}
}))
await fs.writeFile('./.publish/publish.json', JSON.stringify(themeConfigs), 'utf-8');
Expand Down

0 comments on commit 3bf21cf

Please sign in to comment.