#!/bin/bash

# 设置npm的prefix配置
npm config set prefix "D:\NodeJS\node_global"
if [ $? -ne 0 ]; then
    echo "设置npm prefix时出错，请检查！"
    exit 1
fi

# 设置npm的cache配置
npm config set cache "D:\NodeJS\node_cache"
if [ $? -ne 0 ]; then
    echo "设置npm cache时出错，请检查！"
    exit 1
fi

# 设置npm的registry和sass_binary_site
npm config set registry https://registry.npmmirror.com/ && npm config set sass_binary_site https://npmmirror.com/mirrors/node-sass
if [ $? -ne 0 ]; then
    echo "设置npm registry和sass_binary_site时出错，请检查！"
    exit 1
fi

# 获取npm当前的registry
npm config get registry
if [ $? -ne 0 ]; then
    echo "获取npm registry时出错，请检查！"
    exit 1
fi

# 全局安装yarn
npm install yarn -g
if [ $? -ne 0 ]; then
    echo "安装yarn时出错，请检查！"
    exit 1
fi

# 设置yarn的registry和sass_binary_site
yarn config set registry https://registry.npmmirror.com/ && yarn config set sass_binary_site https://npmmirror.com/mirrors/node-sass
if [ $? -ne 0 ]; then
    echo "设置yarn registry和sass_binary_site时出错，请检查！"
    exit 1
fi

# 获取yarn当前的registry
yarn config get registry
if [ $? -ne 0 ]; then
    echo "获取yarn registry时出错，请检查！"
    exit 1
fi

# 设置npm脚本前置node路径
npm config set scripts-prepend-node-path true
if [ $? -ne 0 ]; then
    echo "设置npm scripts-prepend-node-path时出错，请检查！"
    exit 1
fi

# 设置yarn忽略引擎检查
yarn config set ignore-engines true
if [ $? -ne 0 ]; then
    echo "设置yarn ignore-engines时出错，请检查！"
    exit 1
fi

echo "所有配置和安装操作已完成。"
    