-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathcopyFiles.mjs
79 lines (67 loc) · 1.99 KB
/
copyFiles.mjs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// TODO: Unify with core
/* eslint-disable no-console */
import path from 'path';
import fse from 'fs-extra';
import {
includeFileInBuild,
createModulePackages,
typescriptCopy,
createPackageFile,
} from '@mui/monorepo/scripts/copyFilesUtils.mjs';
const packagePath = process.cwd();
const buildPath = path.join(packagePath, './build');
const srcPath = path.join(packagePath, './src');
async function prepend(file, string) {
const data = await fse.readFile(file, 'utf8');
await fse.writeFile(file, string + data, 'utf8');
}
async function addLicense(packageData) {
const license = `/**
* ${packageData.name} v${packageData.version}
*
* @license ${packageData.license === 'MIT' ? 'MIT' : 'MUI X Commercial'}
* This source code is licensed under the ${
packageData.license === 'MIT' ? 'MIT' : 'commercial'
} license found in the
* LICENSE file in the root directory of this source tree.
*/
`;
await Promise.all(
[
'./index.js',
'./modern/index.js',
'./node/index.js',
'./umd/material-ui.development.js',
'./umd/material-ui.production.min.js',
].map(async (file) => {
try {
await prepend(path.resolve(buildPath, file), license);
} catch (err) {
if (err.code === 'ENOENT') {
console.log(`Skipped license for ${file}`);
} else {
throw err;
}
}
}),
);
}
async function run() {
try {
const packageData = await createPackageFile();
const filesToCopy = ['./README.md', '../../CHANGELOG.md'];
const hasLicenseFileInPackage = await fse.exists(path.join(packagePath, 'LICENSE'));
if (hasLicenseFileInPackage) {
filesToCopy.push('./LICENSE');
}
await Promise.all(filesToCopy.map((file) => includeFileInBuild(file)));
await addLicense(packageData);
// TypeScript
await typescriptCopy({ from: srcPath, to: buildPath });
await createModulePackages({ from: srcPath, to: buildPath });
} catch (err) {
console.error(err);
process.exit(1);
}
}
run();