AFFiNE/packages/frontend/templates/build.mjs
Peng Xiao 3978b2dfd2
refactor(core): onboarding using new transformer api (#5412)
Use new `transformer` to import onboarding json templates.

The json files are generated via this gist
https://gist.github.com/pengx17/ef92c305ac23123803a1a6a20e31f822

Not using the all-in-one `ZipTransformer` to import onboarding via a zip file.
1. The main concerns is that we still need to serve the blob resources via CDN to reduce user's blob usage. Otherwise the user will get the onboarding images being uploaded to cloud server every time he creates a new workspace. In this PR we extracted parts of the code from `ZipTransformer` in blocksuite and mute some code for uploading blobs.
2. it maybe not necessary to use zip for loading snapshots.

This PR is a short term solution. whether or not to tune the transformer api design may need further discussions.

fix TOV-264
2023-12-28 13:59:21 +00:00

31 lines
821 B
JavaScript

import fs from 'fs';
import * as glob from 'glob';
import path from 'path';
// purpose: bundle all json files into one json file in onboarding folder
const __dirname = new URL('.', import.meta.url).pathname;
const jsonFiles = glob.sync('./*.json', {
cwd: path.resolve(__dirname, 'onboarding'),
});
const imports = jsonFiles
.map((fileName, index) => {
return `import json_${index} from './onboarding/${fileName}';`;
})
.join('\n');
const exports = `export const onboarding = {
${jsonFiles
.map((fileName, index) => {
return `'${fileName}': json_${index}`;
})
.join(',\n')}
}`;
const template = `/* eslint-disable simple-import-sort/imports */
// Auto generated, do not edit manually
${imports}\n\n${exports}`;
fs.writeFileSync(path.resolve(__dirname, 'templates.gen.ts'), template);