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

hlink

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hlink - npm Package Compare versions

Comparing version 0.5.3-beta.4 to 0.6.0-next.1

lib/bins/index.js

152

lib/cli.js
#!/usr/bin/env node
'use strict';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var meow_1 = __importDefault(require("meow"));
var chalk_1 = __importDefault(require("chalk"));
var path_1 = __importDefault(require("path"));
var fs_extra_1 = __importDefault(require("fs-extra"));
var index_1 = __importDefault(require("./index"));
var config_1 = __importDefault(require("./config"));
var paths = __importStar(require("./config/paths"));
var utils_1 = require("./utils");
var execa_1 = __importDefault(require("execa"));
var os_1 = __importDefault(require("os"));
var rm_1 = __importDefault(require("./rm"));
var cli = (0, meow_1.default)("\n QQ\u53CD\u9988\u7FA4\u53F7\uFF1A" + chalk_1.default.cyanBright('807101297') + "\n\n \u7528\u6CD5:\n $ hlink [--Options] [sourceDir] destPath\n " + chalk_1.default.gray('备份hlink目录缓存等 备份路径') + "\n $ hlink backup /path/to/back\n " + chalk_1.default.gray('还原hlink目录缓存等 还原路径') + "\n $ hlink restore /path/to/restore\n " + chalk_1.default.gray('移除源文件及通过hlink创建的相关硬链') + "\n $ hlink rm /path/to/rm\n\n \u53EF\u914D\u7F6E\u9009\u9879:\n --saveMode,-s \u4FDD\u5B58\u6A21\u5F0F,\u9ED8\u8BA4\u4E3A\u6A21\u5F0F0\n " + chalk_1.default.gray("saveMode=1 \u4FDD\u5B58\u4E00\u7EA7\u76EE\u5F55\n saveMode=0 \u4FDD\u5B58\u539F\u6709\u7684\u76F8\u5BF9\u6E90\u5730\u5740\u7684\u8DEF\u5F84") + "\n\n --includeExtname,-i \u5305\u542B\u7684\u6269\u5C55\u540D,\u591A\u4E2A\u7528','\u9694\u5F00\n " + chalk_1.default.gray("\u5982\u679C\u4E0D\u914D\u7F6E\u8BE5\u9879,\u4F1A\u91C7\u7528\u4EE5\u4E0B\u7B56\u7565\n * 1. \u914D\u7F6E\u4E86excludeExtnam,\u5219\u94FE\u63A5\u6587\u4EF6\u4E3A\u6392\u9664\u540E\u7684\u5176\u4ED6\u6587\u4EF6\n * 2. \u672A\u914D\u7F6EexcludeExtname,\u5219\u94FE\u63A5\u6587\u4EF6\u4E3A\u76EE\u5F55\u4E0B\u7684\u6240\u6709\u6587\u4EF6") + "\n\n --excludeExtname,-e \u6392\u9664\u7684\u6269\u5C55\u540D,\u591A\u4E2A\u7528','\u9694\u5F00\u5982\u679C\u914D\u7F6E\u4E86" + chalk_1.default.cyan('includeExtname') + "\u5219\u8BE5\u914D\u7F6E\u65E0\u6548\n\n --maxFindLevel,-m \u67E5\u627E\u6587\u4EF6\u7684\u6700\u5927\u5C42\u7EA7,\u9ED8\u8BA44\u5C42\n --delete,-d \u5220\u9664\u76EE\u6807\u5730\u5740\u6240\u6709\u786C\u94FE,\u9ED8\u8BA4\u4E3Afalse\n --generateConfig,-g \u751F\u6210config\u6587\u4EF6,\u53EF\u4EE5\u4F7F\u7528 hlink -g \u67E5\u770B\u8DEF\u5F84\n --removeConfig,-r \u5220\u9664\u914D\u7F6E\u6587\u4EF6\n --configPath,-c \u6307\u5B9A\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84,\u8BF7\u4F7F\u7528\u7EDD\u5BF9\u8DEF\u5F84\n --openCache,-o \u662F\u5426\u6253\u5F00\u7F13\u5B58,\u9ED8\u8BA4\u4E3Atrue, \u4F1A\u6253\u5F00\n \u6253\u5F00\u540E,\u6BCF\u6B21\u786C\u94FE\u540E\u4F1A\u628A\u5BF9\u5E94\u6587\u4EF6\u5B58\u5165\u7F13\u5B58,\u5C31\u7B97\u4E0B\u6B21\u5220\u9664\u786C\u94FE\uFF0C\u4E5F\u4E0D\u4F1A\u8FDB\u884C\u786C\u94FE\n\n --mkdirIfSingle \u662F\u5426\u4E3A\u72EC\u7ACB\u6587\u4EF6\u521B\u5EFA\u540C\u540D\u6587\u4EF6\u5939,\u9ED8\u8BA4\u4E3Atrue,\u4F1A\u521B\u5EFA\n\n \u4F8B\u5B50:\n " + chalk_1.default.grey('# 创建 /share/download 下面文件到目标地址 /share/movie') + "\n $ hlink /share/download /share/movie\n\n " + chalk_1.default.grey('# 删除 /share/download 中文件在 /share/movie 下面的对应硬链的文件') + "\n $ hlink -d /share/download /share/movie\n\n " + chalk_1.default.grey('# 交互删除(推荐)') + "\n $ hlink -d\n\n " + chalk_1.default.grey('# 生成配置文件') + "\n $ hlink -g", {
import meow from 'meow';
import bins from './bins/index.js';
var hlink = bins.hlink, rm = bins.rm, backup = bins.backup, restore = bins.restore;
process.env.NODE_OPTIONS = '--experimental-specifier-resolution=node';
var cli = meow({
autoHelp: false,
booleanDefault: undefined,
importMeta: import.meta,
flags: {
saveMode: {
type: 'string',
type: 'number',
alias: 's'

@@ -45,3 +39,3 @@ },

type: 'string',
default: '',
"default": '',
alias: 'i'

@@ -51,10 +45,14 @@ },

type: 'string',
default: '',
"default": '',
alias: 'e'
},
maxFindLevel: {
type: 'string',
openCache: {
type: 'boolean',
alias: 'o'
},
mkdirIfSingle: {
type: 'boolean',
alias: 'm'
},
delete: {
"delete": {
type: 'boolean',

@@ -75,74 +73,38 @@ alias: 'd'

},
openCache: {
watch: {
type: 'boolean',
alias: 'o',
default: undefined
alias: 'w'
},
mkdirIfSingle: {
all: {
type: 'boolean',
default: undefined
},
backup: {
type: 'string',
default: undefined
},
restore: {
type: 'string',
default: undefined
alias: 'a'
}
}
});
var flags = cli.flags;
var _a = cli.input, _command = _a[0], _path = _a[1];
var _a = cli.flags, help = _a.help, watch = _a.watch, all = _a.all, flags = __rest(_a, ["help", "watch", "all"]);
var _b = cli.input, _command = _b[0], inputs = _b.slice(1);
switch (_command) {
case 'backup':
if (!_path) {
utils_1.log.warn('请输入需要备份的路径', chalk_1.default.cyan('hlink backup 路径'));
break;
}
execa_1.default.sync('cp', ['-r', paths.hlinkHomeDir, flags.backup]);
backup(inputs[0]);
break;
case 'restore':
if (!_path) {
utils_1.log.warn('请输入需要还原的文件路径', chalk_1.default.cyan('hlink restore 路径'));
break;
}
execa_1.default.sync('cp', [
'-r',
flags.restore.indexOf('.hlink')
? flags.restore
: path_1.default.join(flags.restore, '.hlink'),
os_1.default.homedir()
]);
restore(inputs[0]);
break;
case 'remove':
case 'rm':
(0, rm_1.default)(_path);
rm(inputs, {
watch: watch,
help: help,
all: all
});
break;
default:
if (flags.r) {
if (fs_extra_1.default.existsSync(flags.c || paths.configPath)) {
fs_extra_1.default.unlinkSync(flags.c || paths.configPath);
utils_1.log.success('移除配置文件成功');
console.log();
}
else {
utils_1.log.warn('您并没有创建配置文件');
console.log();
}
}
else if ('g' in flags) {
(0, config_1.default)(!!flags.g
? path_1.default.isAbsolute(flags.g)
? path_1.default.join(flags.g, paths.configName)
: path_1.default.join(process.cwd(), flags.g, paths.configName)
: undefined);
}
else {
(0, index_1.default)(cli.input, flags);
}
hlink(cli.input, __assign(__assign({}, flags), { help: help }));
}
process.on('SIGINT', function () {
utils_1.log.info('由于你手动中断, 已硬链的文件不会进行缓存');
process.exit();
if (global.printOnExit) {
console.log();
global.printOnExit();
}
process.exit(0);
});

@@ -1,13 +0,8 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs_extra_1 = __importDefault(require("fs-extra"));
var path_1 = __importDefault(require("path"));
var os_1 = __importDefault(require("os"));
import fs from 'fs-extra';
import path from 'path';
import os from 'os';
var Config = /** @class */ (function () {
function Config(jsonFilename, defaultValue, saveDir) {
if (saveDir === void 0) { saveDir = path_1.default.join(os_1.default.homedir(), '.hlink'); }
this.jsonPath = path_1.default.join(saveDir, jsonFilename);
function Config(filename, defaultValue, saveDir) {
saveDir = saveDir || path.join(os.homedir(), '.hlink');
this.jsonPath = path.join(saveDir, filename);
this.saveDir = saveDir;

@@ -17,20 +12,32 @@ this.defaultValue = defaultValue;

Config.prototype.write = function (content) {
var _this = this;
var saveDir = this.saveDir;
if (!fs_extra_1.default.existsSync(saveDir)) {
fs_extra_1.default.ensureDirSync(saveDir);
if (!fs.existsSync(saveDir)) {
fs.ensureDirSync(saveDir);
}
fs_extra_1.default.writeJSONSync(this.jsonPath, content, {
spaces: 2
});
this.cacheRead = content;
if (this.timeoutHandle) {
clearTimeout(this.timeoutHandle);
}
this.timeoutHandle = setTimeout(function () {
_this.cacheRead = undefined;
fs.writeJSONSync(_this.jsonPath, content, {
spaces: 2
});
}, 20);
};
Config.prototype.read = function () {
var mapJson = this.jsonPath;
if (!fs_extra_1.default.existsSync(this.jsonPath)) {
if (!fs.existsSync(this.jsonPath)) {
this.write(this.defaultValue);
return this.defaultValue;
}
return fs_extra_1.default.readJSONSync(mapJson);
if (this.cacheRead) {
return this.cacheRead;
}
this.cacheRead = fs.readJSONSync(mapJson);
return fs.readJSONSync(mapJson);
};
return Config;
}());
exports.default = Config;
export default Config;
{
"name": "hlink",
"version": "0.5.3-beta.4",
"version": "0.6.0-next.1",
"description": "hlink",

@@ -11,2 +11,3 @@ "license": "MIT",

},
"type": "module",
"bin": {

@@ -16,18 +17,14 @@ "hlink": "./lib/cli.js"

"engines": {
"node": ">=10"
"node": ">=12"
},
"scripts": {
"test": "xo && ava",
"start": "chmod +x ./lib/cli.js && ./lib/cli.js -c hlink.config.js",
"new": "rm -rf ./destDir && npm run start",
"delete": "chmod +x ./lib/cli.js && ./lib/cli.js -d",
"rm": "chmod +x ./lib/cli.js && ./lib/cli.js rm sourceDir/a.copy.iso",
"help": "chmod +x ./lib/cli.js && ./lib/cli.js --help",
"dev": "tsc -w",
"clean": "rm -rf lib",
"cp": "cp src/config/hlink.config.tpl lib/config/hlink.config.tpl",
"cp": "cp src/hlink.config.tpl lib/hlink.config.tpl",
"build": "npm run clean && tsc && npm run cp",
"prepublishOnly": "npm run build",
"np": "np --no-cleanup --no-tests --no-yarn",
"np:beta": "np --tag=beta --any-branch --no-cleanup --no-tests --no-yarn"
"np:beta": "np --tag=beta --any-branch --no-cleanup --no-tests --no-yarn",
"np:next": "np --tag=next --any-branch --no-cleanup --no-tests --no-yarn"
},

@@ -47,3 +44,5 @@ "files": [

"@types/node": "^14.14.25",
"ansi-escapes": "^5.0.0",
"chalk": "^4.1.0",
"chokidar": "^3.5.2",
"execa": "^2.1.0",

@@ -53,4 +52,6 @@ "fs-extra": "^9.0.1",

"inquirer": "^7.3.3",
"meow": "^5.0.0",
"single-line-log": "^1.1.2"
"meow": "^10.1.2",
"progress": "^2.0.3",
"single-line-log": "^1.1.2",
"wrap-ansi": "^8.0.1"
},

@@ -60,2 +61,3 @@ "devDependencies": {

"@types/single-line-log": "^1.1.0",
"@types/wrap-ansi": "^8.0.1",
"@typescript-eslint/eslint-plugin": "^4.14.2",

@@ -62,0 +64,0 @@ "ava": "^2.1.0",

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