-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
212e8a7
commit 0e557a6
Showing
14 changed files
with
200 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = __importDefault(require("../utils/index")); | ||
var Shell = require("shelljs"); | ||
var chalk = require("chalk"); | ||
var privatePrefix = "@xsyx"; | ||
var privateResource = "https://mirrors.xsyxxd.com/repository/npm-group/"; | ||
module.exports = function (arg, mode) { | ||
var pkg = require(process.cwd() + "/package.json"); | ||
console.log(chalk.green("🌵 正在由HaYa-CLI代理安装 npm 包....")); | ||
index_1.default.each(pkg.dependencies, eachHandler); | ||
index_1.default.each(pkg.devDependencies, eachHandler); | ||
}; | ||
function eachHandler(_a) { | ||
var key = _a.key, originObject = _a.originObject; | ||
var name = key; | ||
// const reg = /^(@xsyx)/ | ||
var reg = new RegExp("(^" + privatePrefix + "/)", "i"); | ||
/* 拿到版本号,并去掉修饰符 */ | ||
var version = originObject[name]; | ||
/* shell 语法: npm install [<@scope>/]<name>@<version range> */ | ||
if (reg.test(name)) { | ||
Shell.exec("npm install " + name + "@\"" + version + "\" --registry " + privateResource); | ||
} | ||
else { | ||
Shell.exec("npm install " + name + "@\"" + version + "\" --registry https://registry.npmjs.org/"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Utils from "../utils/index"; | ||
const Shell = require("shelljs"); | ||
const chalk = require("chalk"); | ||
const privatePrefix = "@xsyx"; | ||
const privateResource = "https://mirrors.xsyxxd.com/repository/npm-group/"; | ||
|
||
interface Mode { | ||
[key: string]: boolean; | ||
} | ||
declare interface EachIterator { | ||
key: string; | ||
index: number; | ||
array: Array<any>; | ||
originObject: Record<string, any>; | ||
} | ||
module.exports = (arg: string, mode: Mode) => { | ||
const pkg = require(`${process.cwd()}/package.json`); | ||
console.log(chalk.green("🌵 正在由HaYa-CLI代理安装 npm 包....")); | ||
|
||
Utils.each(pkg.dependencies, eachHandler); | ||
Utils.each(pkg.devDependencies, eachHandler); | ||
}; | ||
|
||
function eachHandler({ key, originObject }: EachIterator) { | ||
const name = key; | ||
// const reg = /^(@xsyx)/ | ||
const reg = new RegExp(`(^${privatePrefix}\/)`, "i"); | ||
/* 拿到版本号,并去掉修饰符 */ | ||
const version = originObject[name]; | ||
/* shell 语法: npm install [<@scope>/]<name>@<version range> */ | ||
if (reg.test(name)) { | ||
Shell.exec( | ||
`npm install ${name}@"${version}" --registry ${privateResource}` | ||
); | ||
} else { | ||
Shell.exec( | ||
`npm install ${name}@"${version}" --registry https://registry.npmjs.org/` | ||
); | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
declare interface Utils { | ||
safeRequire: (path: string) => null | Record<string, any>; | ||
each: (obj: object, iteratorFn: (...args: any) => void) => void; | ||
} | ||
const safeRequire = (path: string) => { | ||
try { | ||
return require(path); | ||
} catch (e) { | ||
return null; | ||
} | ||
}; | ||
module.exports = { | ||
safeRequire, | ||
}; | ||
|
||
export {}; | ||
function each(obj: object, iteratorFn: (...args: any) => void) { | ||
Reflect.ownKeys(obj).forEach((key, index, array) => { | ||
iteratorFn({ | ||
key, | ||
index, | ||
array, | ||
originObject: obj, | ||
}); | ||
}); | ||
} | ||
|
||
// module.exports = { | ||
// safeRequire, | ||
// each | ||
// }; | ||
|
||
export default { | ||
safeRequire, | ||
each, | ||
} as Utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1 @@ | ||
declare const safeRequire: any; | ||
declare const path: any; | ||
declare const pkg: any; | ||
declare const appName: any; | ||
declare const appVersion: any; | ||
declare const fs: any; | ||
declare const v: Date; | ||
declare const buildDate: () => string; | ||
declare const defaultInject: () => string; | ||
interface WriteOptions { | ||
injectData?: string | Function; | ||
position?: POSITION; | ||
fileName?: string; | ||
filePath?: string; | ||
content?: string; | ||
} | ||
declare enum POSITION { | ||
Banner = "banner", | ||
Footer = "footer" | ||
} | ||
/** | ||
* rules .css: | ||
* - type = assets | ||
* - data = source | ||
* | ||
* rules .js: | ||
* - type = chunk | ||
* - data = code | ||
*/ | ||
declare const CSS_RULE: { | ||
type: string; | ||
data: string; | ||
}; | ||
declare const JS_RULE: { | ||
type: string; | ||
data: string; | ||
}; | ||
declare function writeBuildInfoInsteadRollUpOptionsForVite(opts?: WriteOptions): { | ||
name: string; | ||
generateBundle: (options: any, bundle: any, isWrite: boolean) => Promise<void>; | ||
writeBundle: () => Promise<void>; | ||
}; | ||
declare function findAssetFileInjectCode(assetInfo: any, ext: string, injectData: string | Function, position: string): void; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export {}; | ||
declare interface Utils { | ||
safeRequire: (path: string) => null | Record<string, any>; | ||
each: (obj: object, iteratorFn: (...args: any) => void) => void; | ||
} | ||
declare const _default: Utils; | ||
export default _default; |