<commit_before>import { _, _Promise, exec, getCurrentBranchName, cwd, consoleColor, io, packageHelper } from '../lib'
import show from './show'
import * as Listr from 'listr'
import { Observable } from 'rxjs'
import { listenerCount } from 'cluster'
/**
 * 安装node项目库
 */
export default {
    /**
     * 启动
     */
    async start(data) {
        /**
         * 查找所有nodejs项目
         */
        consoleColor.start('rimraf **/node_modules')

        await Promise.all(
            ['**/node_modules'].map(
                pattern => io.rimraf(pattern)
            )
        )

        const pathModels = await show.findProjectPaths()
        let tasks = []
        let tool = data.yarn ? 'yarn' : 'npm'
        const simpleProjects = []
        const complexProjects = []
        for (let pathModel of pathModels) {

            const packageJson = await packageHelper.get(io.pathTool.resolve(pathModel.path))
            const { dependencies, devDependencies } = packageJson
            const packages = { ...dependencies, ...devDependencies }

            const isComplex = Object.values(packages).some((url: String) => url.trim().indexOf('file:') === 0)
            let cmdStr = ''
            if (data.yarn) {
                cmdStr = `${tool} install --no-save --no-lockfile`
            }
            else {
                cmdStr = `${tool} install  --no-save --no-shrinkwrap --no-package-lock`
            }
            const title = `${tool} install @ ${pathModel.path}`
            const target = isComplex ? complexProjects : simpleProjects
            target.push({ ...pathModel, cmdStr, title })
        }

        const simpleTasks = new Listr([
            ...simpleProjects.map(n => {
                return { title: n.title, task: () => exec(n.cmdStr, { cwd: n.path, preventDefault: true }).catch(error => { }) }
            })
        ], { concurrent: data.concurrent || 2 })
        const complexTasks = new Listr([
            ...complexProjects.map(n => {
                return { title: n.title, task: () => exec(n.cmdStr, { cwd: n.path, preventDefault: true }).catch(error => { }) }
            })
        ])
        if (simpleProjects.length > 0) {
            tasks.push({
                title: '安装普通工程',
                task: () => {
                    return simpleTasks
                }
            })
        }
        if (complexProjects.length > 0) {
            tasks.push({
                title: '安装有文件级依赖工程',
                task: () => {
                    return complexTasks
                }
            })
        }

        const taskManager = new Listr(tasks)
        await taskManager.run()
        consoleColor.green(`${tool} install 完毕\n\n`, true)
    },
    command: [
        '默认执行 yarn install',
        {
            npm: {
                alias: 'n',
                describe: '使用npm安装库',
                boolean: true,
                default: false
            },
            concurrent: {
                alias: 'c',
                describe: '普通工程并发安装数',
                number: true,
                default: 2
            }
        }
    ]
}<commit_msg>npm-lock<commit_after>import { _, _Promise, exec, getCurrentBranchName, cwd, consoleColor, io, packageHelper } from '../lib'
import show from './show'
import * as Listr from 'listr'
import { Observable } from 'rxjs'
import { listenerCount } from 'cluster'
/**
 * 安装node项目库
 */
export default {
    /**
     * 启动
     */
    async start(data) {
        consoleColor.start('rimraf **/node_modules')
        await Promise.all(
            ['**/node_modules'].map(
                pattern => io.rimraf(pattern)
            )
        )

        const pathModels = await show.findProjectPaths()
        let tasks = []
        let tool = data.yarn ? 'yarn' : 'npm'
        const simpleProjects = []
        const complexProjects = []
        for (let pathModel of pathModels) {

            const packageJson = await packageHelper.get(io.pathTool.resolve(pathModel.path))
            const { dependencies, devDependencies } = packageJson
            const packages = { ...dependencies, ...devDependencies }

            const isComplex = Object.values(packages).some((url: String) => url.trim().indexOf('file:') === 0)
            let cmdStr = ''
            if (data.yarn) {
                cmdStr = `${tool} install --no-save --no-lockfile`
            }
            else {
                cmdStr = `${tool} install  --no-save --no-shrinkwrap --no-package-lock`
            }
            const title = `${tool} install @ ${pathModel.path}`
            const target = isComplex ? complexProjects : simpleProjects
            target.push({ ...pathModel, cmdStr, title })
        }

        const simpleTasks = new Listr([
            ...simpleProjects.map(n => {
                return { title: n.title, task: () => exec(n.cmdStr, { cwd: n.path, preventDefault: true }).catch(error => { }) }
            })
        ], { concurrent: data.concurrent || 2 })
        const complexTasks = new Listr([
            ...complexProjects.map(n => {
                return { title: n.title, task: () => exec(n.cmdStr, { cwd: n.path, preventDefault: true }).catch(error => { }) }
            })
        ])
        if (simpleProjects.length > 0) {
            tasks.push({
                title: '安装普通工程',
                task: () => {
                    return simpleTasks
                }
            })
        }
        if (complexProjects.length > 0) {
            tasks.push({
                title: '安装有文件级依赖工程',
                task: () => {
                    return complexTasks
                }
            })
        }

        const taskManager = new Listr(tasks)
        await taskManager.run()
        consoleColor.green(`${tool} install 完毕\n\n`, true)
    },
    command: [
        '默认执行 yarn install',
        {
            npm: {
                alias: 'n',
                describe: '使用npm安装库',
                boolean: true,
                default: false
            },
            concurrent: {
                alias: 'c',
                describe: '普通工程并发安装数',
                number: true,
                default: 2
            }
        }
    ]
}
{'fraction_non_alphanumeric': 0.13087901394745377, 'fraction_numerical': 0.001621796951021732, 'mean_word_length': 1.404288499025341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3184408', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1731, 'n_words': 383}