<commit_before>// @flow
import webpack from 'webpack'
import config from './webpack.complieConfig'
import fs from 'fs'
import React from 'react'
import ReactDOMServer from 'react-dom/server'

const htmlElement: any = React.createElement(require('./build-html'))
let html: string = ReactDOMServer.renderToStaticMarkup(htmlElement)
html = `<!DOCTYPE html>\n${html}`

const createPublicDir = (path: string): void => {
    try {
        fs.accessSync(path, fs.constants.R_OK)
        try {
            fs.accessSync("../public", fs.constants.R_OK)
            try {
                fs.accessSync("../public/api", fs.constants.R_OK)
                fs.writeFileSync("../public/api/config.json", fs.readFileSync(path))
                return 'create /api/config.json'
            } catch (e) {
                fs.mkdirSync("../public/api")
                fs.writeFileSync("../public/api/config.json", fs.readFileSync(path))
                return 'create /api/config.json error 3'
            }
        } catch (e) {
            fs.mkdirSync("../public")
            fs.mkdirSync("../public/api")
            fs.writeFileSync("../public/api/config.json", fs.readFileSync(path))
            return 'create /api/config.json error 2'
        }
    } catch (e) {
        throw e
    }
}

const htmlCompiled = (config: any) => {
    return new Promise((resolve, reject) => {
        webpack(config, (err, stats) => {
            if (err || stats.hasErrors()) {
                reject('can not webpacking')
            }
            fs.writeFileSync('../public/index.html', html)
            resolve('create index.html')
        })
    })
}

const build = async (path: string, config: any) => {
    try {
        createPublicDir(path)
        await htmlCompiled(config)
        return 'build success'
    } catch (e) {
        throw e
    }
}

//build('../lib/api/config.json', config(process.env.npm_lifecycle_event))

export default build<commit_msg>edit build.js<commit_after>// @flow
import webpack from 'webpack'
import config from './webpack.complieConfig'
import fs from 'fs'
import React from 'react'
import ReactDOMServer from 'react-dom/server'

const htmlElement: any = React.createElement(require('./build-html'))
let html: string = ReactDOMServer.renderToStaticMarkup(htmlElement)
html = `<!DOCTYPE html>\n${html}`

const createPublicDir = (path: string): void => {
    try {
        fs.accessSync(path, fs.constants.R_OK)
        try {
            fs.accessSync("../public", fs.constants.R_OK)
            try {
                fs.accessSync("../public/api", fs.constants.R_OK)
                fs.writeFileSync("../public/api/config.json", fs.readFileSync(path))
                return 'create /api/config.json'
            } catch (e) {
                fs.mkdirSync("../public/api")
                fs.writeFileSync("../public/api/config.json", fs.readFileSync(path))
                return 'create /api/config.json error 3'
            }
        } catch (e) {
            fs.mkdirSync("../public")
            fs.mkdirSync("../public/api")
            fs.writeFileSync("../public/api/config.json", fs.readFileSync(path))
            return 'create /api/config.json error 2'
        }
    } catch (e) {
        throw e
    }
}

const htmlCompiled = (config: any) => {
    return new Promise((resolve, reject) => {
        webpack(config, (err, stats) => {
            if (err || stats.hasErrors()) {
                reject('can not webpacking')
            }
            fs.writeFileSync('../public/index.html', html)
            resolve('create index.html')
        })
    })
}

const build = async (path: string, config: any) => {
    try {
        createPublicDir(path)
        await htmlCompiled(config)
        return 'build success'
    } catch (e) {
        throw e
    }
}

build('../lib/api/config.json', config(process.env.npm_lifecycle_event))

export default build
{'fraction_non_alphanumeric': 0.14664948453608248, 'fraction_numerical': 0.0010309278350515464, 'mean_word_length': 2.0487038491751766, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2299061', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1148, 'n_words': 242}