🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@dreamdt/cli

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dreamdt/cli - npm Package Compare versions

Package was removed
Sorry, it seems this package was removed from the registry
Comparing version
0.0.3
to
0.0.4
+12
.editorconfig
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
import semver from 'semver';
import chalk from 'chalk';
import inquirer from 'inquirer';
import axios from 'axios';
import { compareVersions } from './compare-version.js';
/**
* 检查 node 版本号
* @param {*} wanted 要验证的 node 版本号
*/
export async function checkNodeVersion(wanted) {
const processVersion = process.version;
if (!semver.satisfies(processVersion, wanted)) {
console.log(chalk.red(`您正在使用 Node ${processVersion}, 但这个版本的要求是 Node ${wanted}。\n建议您更换 Node 版本到 v14.x.x。`));
const { next } = await inquirer.prompt([
{
'name': 'next',
'type': 'list',
'message': '你可以:',
'pageSize': 15,
'loop': false,
'choices': [
{ 'name': '下载Node安装包', 'value': 'down' },
{ 'name': '忽略并继续', 'value': false }
]
}
]);
if (next === 'down') {
// 获取 node 18 版本的下载地址,并打开
let res = await axios.get('https://nodejs.org/dist/');
const html = res.data;
let versionList = html.match(/v14\.\d{1,2}\.\d{1,2}/g);
let latest;
if (Array.isArray(versionList)) {
versionList.sort(compareVersions);
latest = versionList[versionList.length - 1];
}
console.log(`请访问 ${chalk.blue(`https://nodejs.org/dist/${latest}/`)} 下载Node安装包`);
exit(0);
}
}
}
// 定义一个比较版本号的函数
export function compareVersions(version1, version2) {
// 去掉前缀 'v',然后按照 '.' 分割版本号字符串
const nums1 = version1.substring(1).split('.').map(Number);
const nums2 = version2.substring(1).split('.').map(Number);
// 依次比较每一位数字
for (let i = 0; i < Math.min(nums1.length, nums2.length); i++) {
if (nums1[i] !== nums2[i]) {
return nums1[i] - nums2[i];
}
}
// 版本号长度不一样时,较长的版本号较大
return nums1.length - nums2.length;
}
import { expect } from 'chai';
import sinon from 'sinon';
import { checkNodeVersion } from '../lib/check-node-version.js';
describe('dreamcli', () => {
let consoleLogStub;
beforeEach(() => {
consoleLogStub = sinon.stub(console, 'log');
});
afterEach(() => {
consoleLogStub.restore();
});
// 测试版本命令
it('should print the version', () => {
dreamcli();
});
it('should print the version', () => {
// checkNodeVersion('16');
// 我的判断 node 版本函数里使用了交互式问题,让用户选择是否下载 node,这个应该如何写测试用例?
})
})
+26
-5
{
"name": "@dreamdt/cli",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"type": "module",
"main": "bin/index.js",

@@ -10,3 +11,3 @@ "bin": {

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha test/ -r chai/register-expect.js"
},

@@ -16,8 +17,28 @@ "keywords": [

],
"author": "",
"license": "MIT",
"author": "dreamdt",
"license": "ISC",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"engines": {
"node": "^12.10.0 || 13.x.x || 20.x.x",
"npm": "^10.5.0"
},
"dependencies": {
"axios": "^1.6.8",
"boxen": "^7.1.1",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"inquirer": "^9.2.19",
"semver": "^7.6.0"
},
"devDependencies": {
"chai": "^5.1.0",
"mocha": "^10.4.0",
"sinon": "^17.0.1"
},
"volta": {
"node": "20.12.2"
}
}
}