forked from cloudinary/js-url-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentryPointsLib.ts
54 lines (43 loc) · 1.49 KB
/
entryPointsLib.ts
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
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* This file contains utility functions related to creating ./dist entry-points (such as @base/actions/adjust)
*/
const fs = require('fs');
// All of our package.jsons need to contain this property to allow tree shaking
const commonPackageProperties = {
sideEffects: false
};
/**
* Creates the npm entry-point for the UMD Bundle
* Allows users to import from '@base/bundles/umd'
*/
function createUMDBundleEntryPoint() {
const packageJson = Object.assign({
"types": `../../index.d.ts`,
"main": `./base.js`
}, commonPackageProperties);
// create umd
fs.writeFileSync(
`dist/bundles/umd/package.json`,
JSON.stringify(packageJson, null, '\t')
);
}
/**
* @description Since only ./dist/ is packaged to npm, we need to copy a proper package.json file to it
* That will allow `import {TransformableImage} from '@cloudinary/url-gen`
*/
function copyPackageJson(fileDestination = 'dist') {
const projectJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
delete projectJson.scripts;
delete projectJson.devDependencies;
projectJson.main = './bundles/umd/base.js';
projectJson.browser = './index.js';
projectJson.module = './index.js';
projectJson.type = 'module',
Object.assign(projectJson, commonPackageProperties);
fs.writeFileSync(`./${fileDestination}/package.json`, JSON.stringify(projectJson, null, '\t'));
}
module.exports = {
copyPackageJson,
createUMDBundleEntryPoint
};