Path: blob/master/node_modules/@bochilteam/scraper/scripts/write-package.js
1113 views
const fs = require('fs')1const path = require('path')23const { promisify } = require('util')4const fsAccess = promisify(fs.access)56const fileExists = async (filePath) =>7fsAccess(filePath)8.then(() => true)9.catch(() => false)1011const libPath = path.join(__dirname, '../lib')1213async function writePackageJson () {14const libExists = await fileExists(libPath)15if (!libExists) {16console.error('@BochilTeam/scraper:', 'Lib folder not found after compiling TypeScript')17process.exit(1)18}19const libCjs = path.join(libPath, 'cjs')20const libCjsExists = await fileExists(libCjs)21if (libCjsExists) {22const packageJson = JSON.stringify({ type: 'commonjs' }, null, 2)23await fs.promises.writeFile(path.join(libCjs, 'package.json'), packageJson)24} else console.warn('@BochilTeam/scraper:', 'CJS folder not found')25const libEsm = path.join(libPath, 'esm')26const libEsmExists = await fileExists(libEsm)27if (libEsmExists) {28const packageJson = JSON.stringify({ type: 'module' }, null, 2)29await fs.promises.writeFile(path.join(libEsm, 'package.json'), packageJson)30} else console.warn('@BochilTeam/scraper:', 'ESM folder not found')3132const typesPath = path.join(libPath, '@types')33const typesExists = await fileExists(typesPath)3435if (!typesExists && !libEsmExists && !libCjsExists) {36console.error('@BochilTeam/scraper:', 'No compiled TypeScript files found')37process.exit(1)38}39}4041if (require.main === module) writePackageJson()424344