-
Notifications
You must be signed in to change notification settings - Fork 31
/
files.js
43 lines (38 loc) · 1.26 KB
/
files.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
import fs from 'file-system';
import splitFile from 'split-file';
import del from 'del';
import tar from 'tar';
import logger from './logger';
import { meteorNowBuildPath, tarFileName } from './constants';
import { getArg } from './args';
const encoding = 'utf8';
export const readFile = path => fs.readFileSync(path, encoding);
export const writeFile = (path, data) => fs.writeFileSync(path, data, encoding);
export const deletePath = path => del(path, { force: true });
export const renameFile = (oldPath, newPath) => fs.renameSync(oldPath, newPath);
// split meteor bundle into pieces
export const prepareBundle = async () => {
const bundlePath = `${meteorNowBuildPath}/${tarFileName}`;
await tar.x({
file: bundlePath,
cwd: meteorNowBuildPath,
}, ['bundle/programs/server/package.json']);
try {
if (getArg('nosplit')) {
renameFile(bundlePath, `${meteorNowBuildPath}/bundle.tar.gz`);
} else {
logger.debug('splitting bundle');
await splitFile.splitFileBySize(
`${meteorNowBuildPath}/${tarFileName}`,
999999,
);
await deletePath(bundlePath);
}
} catch (e) {
logger.error(e);
}
};
export const clearBuildFolder = () => {
logger.debug('clearing build folder');
return deletePath(meteorNowBuildPath);
};