Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

3h1-cli

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3h1-cli - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

0

docs/拉取基础开发框架.md

@@ -0,0 +0,0 @@ # 三禾一前端开发脚手架

2

index.js

@@ -27,3 +27,3 @@ const pkg = require("./package.json");

.description("三禾一脚手架")
.option("-N,--name <name>", "创建项目名")
// .option("-N,--name <name>", "创建项目名")
.action(async (name, options) => {

@@ -30,0 +30,0 @@ await create(name, options);

@@ -0,0 +0,0 @@ const path = require("path");

const inquirer = require("inquirer");
const ora = require("ora");
const { getRepoList } = require("./https.js");
const prompts = require("prompts");

@@ -38,15 +39,27 @@ async function wrapLoading(fn, message, ...args) {

// 1)从远程拉取模板数据
const repoList = await wrapLoading(getRepoList, "加载模版中...");
if (!repoList) return;
// const repoList = await wrapLoading(getRepoList, "加载模版中...");
// if (!repoList) return;
// 过滤
const repos = repoList.reduce((acc, cur) => {
// 兼容过滤id写法
if (cur.id) {
acc.push(cur.name);
}
return acc;
}, []);
// const repos = repoList.reduce((acc, cur) => {
// // 兼容过滤id写法
// if (cur.id) {
// acc.push(cur.name);
// }
// return acc;
// }, []);
const repos = [
{
title: "插件模版",
value: "git@git.3h1china.com:cbb/framework/shy-admin-vben.git",
},
{
title: "基础框架",
value: "git@git.3h1china.com:cbb/framework/shy-admin-vben.git",
},
];
// 2)用户选择自己新下载的模板名称
const { repo } = await inquirer.prompt({
const { repo } = await prompts({
name: "repo",

@@ -53,0 +66,0 @@ type: "list",

@@ -15,3 +15,3 @@ // 获取远程模版信息

return axios({
url: "http://121.40.104.98:9090/api/v4/groups/code-template/projects",
url: "git@git.3h1china.com:cbb/framework/shy-admin-vben.git",
headers: {

@@ -18,0 +18,0 @@ "PRIVATE-TOKEN": "ZzHjMKP53pDE81_UV4mn",

const Client = require("ssh2-sftp-client");
const client = new Client();
const fse = require('fs-extra')
const path = require('path');
const { Logger } = require('../../utils/index')
const fse = require("fs-extra");
const path = require("path");
const { Logger } = require("../../utils/index");

@@ -16,10 +16,37 @@ async function connect(host, port, username, password) {

async function moveFilesToNewDirectory(remoteDir, destDir) {
// Ensure destination directory exists
try {
await client.mkdir(destDir, true); // The second argument true makes it recursive
} catch (err) {
if (err.code !== 4) {
// 4 means the directory already exists
throw err;
}
}
const fileList = await client.list(remoteDir);
for (const file of fileList) {
const sourceFilePath = `${remoteDir}/${file.name}`;
const destFilePath = `${destDir}/${file.name}`;
if (file.type === "-") {
// type '-' means it's a file
await client.rename(sourceFilePath, destFilePath);
} else if (file.type === "d") {
// type 'd' means it's a directory
// Recursively move files in sub-directory
await moveFilesToNewDirectory(sourceFilePath, destFilePath);
await client.rmdir(sourceFilePath); // Remove the directory after moving its contents
}
}
}
async function rename(remoteDir) {
const prefix = new Date()
.toISOString()
.slice(2, 19)
.replace(/[-:T]/g, "");
await client.rename(remoteDir, `${remoteDir}-${prefix}`);
const prefix = new Date().toISOString().slice(2, 19).replace(/[-:T]/g, "");
await client.rename(`${remoteDir}/*`, `${remoteDir}-${prefix}/*`);
Logger.success(`新备份目录:${remoteDir}-${prefix}`);
await client.rename(`${remoteDir}-new`, remoteDir);
await client.rename(`${remoteDir}-new/*`, `${remoteDir}/*`);
}

@@ -32,9 +59,11 @@

} else {
const newRemoteDir = `${remoteDir}-new`;
if ((await client.exists(newRemoteDir)) === "d") {
await client.rmdir(newRemoteDir, true);
}
await client.uploadDir(localDir, newRemoteDir, uploadFilter);
const prefix = new Date().toISOString().slice(2, 19).replace(/[-:T]/g, "");
const destDir = `${remoteDir}-${prefix}`;
await client.mkdir(`${remoteDir}-${prefix}`);
await moveFilesToNewDirectory(remoteDir, destDir);
Logger.success(`新备份目录:${destDir}`);
await client.uploadDir(localDir, remoteDir, uploadFilter);
Logger.success(`${remoteDir}上传成功!`);
await rename(remoteDir);
}

@@ -58,8 +87,3 @@ }

if (dirList.length < maxLen) return;
await removeDir(
dirList
.sort()
.reverse()
.slice(maxLen),
);
await removeDir(dirList.sort().reverse().slice(maxLen));
}

@@ -76,9 +100,16 @@ }

async function deploy(options) {
const connectOptions = ["host", "port", "username", "password"].filter((key) => !options[key]);
if (connectOptions.length) return Logger.error(`Linux SSH账户${connectOptions.join(",")}参数不能为空`);
const connectOptions = ["host", "port", "username", "password"].filter(
(key) => !options[key]
);
if (connectOptions.length)
return Logger.error(`Linux SSH账户${connectOptions.join(",")}参数不能为空`);
const pathOptions = ["localDir", "remoteDir"].filter((key) => !options.hasOwnProperty(key));
if (pathOptions.length) return Logger.error(`地址${pathOptions.join(",")}参数不能为空`);
const pathOptions = ["localDir", "remoteDir"].filter(
(key) => !options.hasOwnProperty(key)
);
if (pathOptions.length)
return Logger.error(`地址${pathOptions.join(",")}参数不能为空`);
const { host, port, username, password, localDir, remoteDir, limit } = options;
const { host, port, username, password, localDir, remoteDir, limit } =
options;
try {

@@ -98,8 +129,8 @@ await connect(host, port, username, password);

module.exports = async (args, options = {}) => {
const currPath = process.cwd();
const fileName = options?.file ? `${options.file}.json` : 'ftp-config.json';
const currPath = process.cwd();
const fileName = options?.file ? `${options.file}.json` : "ftp-config.json";
const ftpConfig = path.resolve(currPath, fileName);
const result = fse.pathExistsSync(ftpConfig);
if (!result) {
Logger.error(`${fileName}不存在!请使用shy ftp init创建`)
Logger.error(`${fileName}不存在!请使用shy ftp init创建`);
return;

@@ -110,2 +141,2 @@ }

deploy(config);
}
};
{
"name": "3h1-cli",
"version": "0.0.5",
"version": "0.0.6",
"description": "三禾一工具库",

@@ -18,2 +18,3 @@ "main": "index.js",

"ora": "5.4",
"prompts": "^2.4.2",
"shelljs": "^0.8.4",

@@ -39,2 +40,2 @@ "ssh2-sftp-client": "^7.1.0"

}
}
}

@@ -0,0 +0,0 @@ # 三禾一工具助手3h1-cli

@@ -1,3 +0,3 @@

const fse = require('fs-extra')
const {resolve} = require('path')
const fse = require("fs-extra");
const { resolve } = require("path");
const chalk = require("chalk");

@@ -7,11 +7,11 @@ const log = console.log;

const excludeDirs = {
'.git': true,
'node_modules': true
}
".git": true,
node_modules: true,
};
module.exports = {
filterDir: (dir = '', isDeep = true, obj = null, isNest = false) => {
filterDir: (dir = "", isDeep = true, obj = null, isNest = false) => {
const currPath = process.cwd();
const filterAssets = (dir = '', isDeep = true, obj = null) => {
const filterAssets = (dir = "", isDeep = true, obj = null) => {
const result = fse.readdirSync(resolve(currPath, dir));

@@ -21,8 +21,8 @@ if (!obj) {

dirs: [],
files: []
}
files: [],
};
}
return result.reduce((acc, curr) => {
if (curr.startsWith('.') || excludeDirs[curr]) return acc;
if (curr.startsWith(".") || excludeDirs[curr]) return acc;
const currName = dir ? `${dir}/${curr}` : curr;

@@ -36,3 +36,3 @@ const newPath = resolve(currPath, currName);

filename: curr,
filepath: newPath
filepath: newPath,
};

@@ -42,3 +42,8 @@

if (isNest) {
const { dirs, files } = filterAssets(currName, isDeep, null, isNest);
const { dirs, files } = filterAssets(
currName,
isDeep,
null,
isNest
);
item.dirs = dirs;

@@ -51,6 +56,6 @@ item.files = files;

acc[isDir ? 'dirs' : 'files'].push(item);
acc[isDir ? "dirs" : "files"].push(item);
return acc;
}, obj);
}
}, obj);
};
return filterAssets(dir, isDeep, obj, isNest);

@@ -68,3 +73,3 @@ },

},
}
}
},
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc