2023-03-16 17:58:21 +03:00
|
|
|
#!/usr/bin/env zx
|
|
|
|
import 'zx/globals';
|
|
|
|
|
2023-05-18 03:36:59 +03:00
|
|
|
import { createRequire } from 'node:module';
|
2023-03-16 17:58:21 +03:00
|
|
|
import path from 'node:path';
|
|
|
|
|
2023-05-18 03:36:59 +03:00
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
|
2023-03-16 17:58:21 +03:00
|
|
|
const repoRootDir = path.join(__dirname, '..', '..', '..');
|
|
|
|
const electronRootDir = path.join(__dirname, '..');
|
|
|
|
const publicDistDir = path.join(electronRootDir, 'resources');
|
2023-07-18 19:53:10 +03:00
|
|
|
const affineCoreDir = path.join(repoRootDir, 'apps', 'core');
|
|
|
|
const affineCoreOutDir = path.join(affineCoreDir, 'dist');
|
2023-03-16 17:58:21 +03:00
|
|
|
const publicAffineOutDir = path.join(publicDistDir, `web-static`);
|
2023-05-17 20:37:28 +03:00
|
|
|
const releaseVersionEnv = process.env.RELEASE_VERSION || '';
|
2023-03-16 17:58:21 +03:00
|
|
|
|
|
|
|
console.log('build with following dir', {
|
|
|
|
repoRootDir,
|
|
|
|
electronRootDir,
|
|
|
|
publicDistDir,
|
2023-07-18 19:53:10 +03:00
|
|
|
affineSrcDir: affineCoreDir,
|
|
|
|
affineSrcOutDir: affineCoreOutDir,
|
2023-03-16 17:58:21 +03:00
|
|
|
publicAffineOutDir,
|
|
|
|
});
|
|
|
|
|
2023-05-17 20:37:28 +03:00
|
|
|
// step 0: check version match
|
2023-05-18 03:36:59 +03:00
|
|
|
const electronPackageJson = require(`${electronRootDir}/package.json`);
|
2023-05-17 20:37:28 +03:00
|
|
|
if (releaseVersionEnv && electronPackageJson.version !== releaseVersionEnv) {
|
|
|
|
throw new Error(
|
|
|
|
`Version mismatch, expected ${releaseVersionEnv} but got ${electronPackageJson.version}`
|
|
|
|
);
|
|
|
|
}
|
2023-03-16 17:58:21 +03:00
|
|
|
// copy web dist files to electron dist
|
|
|
|
|
2023-04-15 20:24:57 +03:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
$.shell = 'powershell.exe';
|
|
|
|
$.prefix = '';
|
|
|
|
}
|
2023-04-13 16:37:50 +03:00
|
|
|
|
2023-08-14 18:40:00 +03:00
|
|
|
$.env.DISTRIBUTION = 'desktop';
|
|
|
|
|
2023-04-21 13:06:54 +03:00
|
|
|
cd(repoRootDir);
|
2023-03-16 17:58:21 +03:00
|
|
|
|
2023-06-14 13:40:13 +03:00
|
|
|
// step 1: build web (nextjs) dist
|
2023-04-21 13:06:54 +03:00
|
|
|
if (!process.env.SKIP_WEB_BUILD) {
|
2023-07-27 15:56:59 +03:00
|
|
|
await $`yarn -T run build:plugins`;
|
2023-08-14 18:40:00 +03:00
|
|
|
await $`yarn nx build @affine/core`;
|
2023-09-01 06:34:18 +03:00
|
|
|
|
|
|
|
// step 1.5: amend sourceMappingURL to allow debugging in devtools
|
|
|
|
await glob('**/*.{js,css}', { cwd: affineCoreOutDir }).then(files => {
|
|
|
|
return files.map(async file => {
|
|
|
|
const dir = path.dirname(file);
|
|
|
|
const fullpath = path.join(affineCoreOutDir, file);
|
|
|
|
let content = await fs.readFile(fullpath, 'utf-8');
|
|
|
|
// replace # sourceMappingURL=76-6370cd185962bc89.js.map
|
|
|
|
// to # sourceMappingURL=assets://./{dir}/76-6370cd185962bc89.js.map
|
|
|
|
content = content.replace(/# sourceMappingURL=(.*)\.map/g, (_, p1) => {
|
|
|
|
return `# sourceMappingURL=assets://./${dir}/${p1}.map`;
|
|
|
|
});
|
|
|
|
await fs.writeFile(fullpath, content);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-07-20 20:20:29 +03:00
|
|
|
await fs.move(affineCoreOutDir, publicAffineOutDir, { overwrite: true });
|
2023-04-21 13:06:54 +03:00
|
|
|
}
|
|
|
|
|
2023-06-14 13:40:13 +03:00
|
|
|
// step 2: update app-updater.yml content with build type in resources folder
|
2023-05-16 06:34:54 +03:00
|
|
|
if (process.env.BUILD_TYPE === 'internal') {
|
|
|
|
const appUpdaterYml = path.join(publicDistDir, 'app-update.yml');
|
|
|
|
const appUpdaterYmlContent = await fs.readFile(appUpdaterYml, 'utf-8');
|
|
|
|
const newAppUpdaterYmlContent = appUpdaterYmlContent.replace(
|
|
|
|
'AFFiNE',
|
|
|
|
'AFFiNE-Releases'
|
|
|
|
);
|
|
|
|
await fs.writeFile(appUpdaterYml, newAppUpdaterYmlContent);
|
|
|
|
}
|