-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpost-build-script.js
45 lines (39 loc) · 1.41 KB
/
post-build-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
//! Target directory
const distDir = path.resolve(__dirname, '../dist');
const srcPackageJsonFilePath = path.resolve(__dirname, '../package.json');
const targetPackageJsonFilePath = path.join(distDir, 'package.json');
const srcResourcesDir = path.join(__dirname, '../resources');
const targetResourcesDir = path.join(distDir, 'resources');
function copyPackageJson(srcPackageJsonFilePath, targetPackageJsonFilePath) {
fs.copyFileSync(srcPackageJsonFilePath, targetPackageJsonFilePath);
}
function copyResources(srcDir, targetDir) {
fs.cpSync(srcDir, targetDir, {recursive: true});
}
async function recursiveChmod(dir, mode) {
const files = await fs.promises.readdir(dir);
for (const file of files) {
const filePath = `${dir}/${file}`;
const stats = await fs.promises.stat(filePath);
if (stats.isDirectory()) {
await recursiveChmod(filePath, mode);
} else {
await fs.promises.chmod(filePath, mode);
}
}
}
// Usage
console.time('Copy package.json');
copyPackageJson(srcPackageJsonFilePath, targetPackageJsonFilePath);
console.time('Copy resources');
copyResources(srcResourcesDir, targetResourcesDir);
console.time('Update permissions');
await recursiveChmod(distDir, 0o755);