Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@bochilteam/scraper/scripts/write-package.js
1113 views
1
const fs = require('fs')
2
const path = require('path')
3
4
const { promisify } = require('util')
5
const fsAccess = promisify(fs.access)
6
7
const fileExists = async (filePath) =>
8
fsAccess(filePath)
9
.then(() => true)
10
.catch(() => false)
11
12
const libPath = path.join(__dirname, '../lib')
13
14
async function writePackageJson () {
15
const libExists = await fileExists(libPath)
16
if (!libExists) {
17
console.error('@BochilTeam/scraper:', 'Lib folder not found after compiling TypeScript')
18
process.exit(1)
19
}
20
const libCjs = path.join(libPath, 'cjs')
21
const libCjsExists = await fileExists(libCjs)
22
if (libCjsExists) {
23
const packageJson = JSON.stringify({ type: 'commonjs' }, null, 2)
24
await fs.promises.writeFile(path.join(libCjs, 'package.json'), packageJson)
25
} else console.warn('@BochilTeam/scraper:', 'CJS folder not found')
26
const libEsm = path.join(libPath, 'esm')
27
const libEsmExists = await fileExists(libEsm)
28
if (libEsmExists) {
29
const packageJson = JSON.stringify({ type: 'module' }, null, 2)
30
await fs.promises.writeFile(path.join(libEsm, 'package.json'), packageJson)
31
} else console.warn('@BochilTeam/scraper:', 'ESM folder not found')
32
33
const typesPath = path.join(libPath, '@types')
34
const typesExists = await fileExists(typesPath)
35
36
if (!typesExists && !libEsmExists && !libCjsExists) {
37
console.error('@BochilTeam/scraper:', 'No compiled TypeScript files found')
38
process.exit(1)
39
}
40
}
41
42
if (require.main === module) writePackageJson()
43
44