This repository was archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_dist.js
More file actions
55 lines (48 loc) · 2.07 KB
/
prepare_dist.js
File metadata and controls
55 lines (48 loc) · 2.07 KB
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
// This script is a modification of the original prepDist.js, courtesy of Apollo GraphQL.
// Copied from https://github.com/apollographql/apollo-client/blob/dda7952ca66b403bf76d9407b949e9f698f6bef8/config/prepareDist.js
//
// The Speechly client source that is published to npm is located in the
// "dist" directory. This utility script is called when building Speechly client,
// to make sure the "dist" directory is prepared for publishing.
//
// This script will:
//
// - Delete unnecessary type definition files, which are rolled up by api-extractor.
// - Copy the current root package.json into "dist" after adjusting it for
// publishing.
// - Copy the supporting files from the root into "dist" (e.g. `README.MD`,
// `LICENSE`, etc.).
const fs = require('fs')
const packageJson = require('./package.json')
const srcDir = `${__dirname}`
const destDir = `${srcDir}/lib`
// The root package.json is marked as private to prevent publishing
// from happening in the root of the project. This sets the package back to
// public so it can be published from the "dist" directory.
packageJson.private = false
// Remove package.json items that we don't need to publish
delete packageJson.scripts
delete packageJson.bundlesize
delete packageJson.files
// The root package.json points to the CJS/ESM source in "dist", to support
// on-going package development (e.g. running tests, supporting npm link, etc.).
// When publishing from "dist" however, we need to update the package.json
// to point to the files within the same directory.
const distPackageJson =
JSON.stringify(
packageJson,
(_key, value) => {
if (typeof value === 'string' && value.startsWith('./lib/')) {
const parts = value.split('/')
parts.splice(1, 1) // remove dist
return parts.join('/')
}
return value
},
2,
) + '\n'
// Save the modified package.json to "dist"
fs.writeFileSync(`${destDir}/package.json`, distPackageJson)
// Copy supporting files into "dist"
fs.copyFileSync(`${srcDir}/README.md`, `${destDir}/README.md`)
fs.copyFileSync(`${srcDir}/LICENSE`, `${destDir}/LICENSE`)