Socket
Socket
Sign inDemoInstall

relation2-cli

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relation2-cli - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

113

dist/command/check.js

@@ -10,11 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import filenamify from "filenamify";
import fse from "fs-extra";
import pick from "lodash/pick.js";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { groupByKey, RelationServer } from "relation2-core";
import { RelationServer } from "relation2-core";
import stringifyJsonScriptContent from "stringify-json-script-content";
import baseDirname from "../baseDirname.js";
const pkgInfo = JSON.parse(fs.readFileSync(path.resolve(baseDirname, "..", "package.json")).toString());
const pkgInfo = JSON.parse(fse.readFileSync(path.resolve(baseDirname, "..", "package.json")).toString());
export default function (program) {

@@ -24,38 +22,22 @@ program

.option("--from <string>", "")
.option("--output <boolean>", "", "json")
.option("--to <string>", "")
.option("--output <boolean>", "", "html")
.action((opts) => __awaiter(this, void 0, void 0, function* () {
let from;
if (opts.from) {
if (path.isAbsolute(opts.from)) {
from = opts.from;
}
else {
from = path.join(process.cwd(), opts.from);
}
}
const relationServer = new RelationServer();
const relations = yield relationServer.filter((relation) => {
return (path.join(relationServer.workingDirectory, relation.fromBaseDir, relation.fromPath) === from);
});
const resultGroupByKey = groupByKey(relations);
const relations = this.filter((relation) => relation.fromAbsolutePath === relation.getAbsolutePath(opts.from) &&
relation.toAbsolutePath === relation.getAbsolutePath(opts.to));
const relationViewerData = yield relationServer.getRelationViewerData(relations);
if (opts.output === "html") {
yield outputHtml(resultGroupByKey, relationServer);
yield outputHtml(relationViewerData);
return;
}
yield outputJson(resultGroupByKey, relationServer);
}));
}
function outputHtml(resultGroupByKey, relationServer) {
function outputHtml(relationViewerData) {
return __awaiter(this, void 0, void 0, function* () {
const resultPath = path.join(process.cwd(), "relation-check-result");
fse.emptyDirSync(resultPath);
const results = [];
for (const result of Object.entries(resultGroupByKey)) {
const data = yield getViewCheckResult(result, relationServer);
results.push({
key: data.key,
id: data.id,
});
const escapedViewCheckResultsJSONString = stringifyJsonScriptContent(data, null, 2);
const html = `
const escapedRelationViewerDataJSONString = stringifyJsonScriptContent(relationViewerData, null, 2);
const relationFromTo = `${relationViewerData.fromPath} - ${relationViewerData.toPath}`;
const html = `
<!DOCTYPE html>

@@ -66,3 +48,3 @@ <html lang="en">

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${data.id} - Relation</title>
<title>${relationFromTo} - Relation</title>
</head>

@@ -72,7 +54,7 @@ <body>

</div>
<script id="viewCheckResultsText" type="application/json">
${escapedViewCheckResultsJSONString}
<script id="escapedRelationViewerDataJSONString" type="application/json">
${escapedRelationViewerDataJSONString}
</script>
<script>
window.__VIEW_CHECK_RESULTS__ = JSON.parse(document.getElementById('viewCheckResultsText').textContent);
window.__RELATION_VIEWER_DATA__ = JSON.parse(document.getElementById('escapedRelationViewerDataJSONString').textContent);
</script>

@@ -82,62 +64,5 @@ <script src="https://cdn.jsdelivr.net/npm/relation2-page@${pkgInfo.version}/dist/relationPreviewView.js"></script>

</html>`;
fse.writeFileSync(path.join(resultPath, `${data.id}.html`), html);
}
const resultsJSONString = JSON.stringify(Array.from(results), null, 2);
fse.writeFileSync(path.join(resultPath, "check-results-data.json"), resultsJSONString);
const fileName = filenamify(relationFromTo);
fse.writeFileSync(path.join(resultPath, `${fileName}.html`), html);
});
}
function outputJson(resultGroupByKey, relationServer) {
return __awaiter(this, void 0, void 0, function* () {
const resultPath = path.join(process.cwd(), "relation-check-result");
fse.emptyDirSync(resultPath);
const results = [];
// TODO: fix find relation-page
fse.copySync(path.join(baseDirname, "..", "node_modules", "relation2-page", "dist"), resultPath, {
overwrite: true,
});
const previewsPath = path.join(resultPath, "previews");
fse.mkdirSync(previewsPath);
for (const result of Object.entries(resultGroupByKey)) {
const data = yield getViewCheckResult(result, relationServer);
results.push({
key: data.key,
id: data.id,
dirty: data.checkResults.some((checkResult) => checkResult.dirty),
});
const dataJSONString = JSON.stringify(data, null, 2);
fse.writeFileSync(path.join(previewsPath, `${data.id}.json`), dataJSONString);
}
const resultsJSONString = JSON.stringify(Array.from(results), null, 2);
fse.writeFileSync(path.join(resultPath, "check-results-data.json"), resultsJSONString);
});
}
function getViewCheckResult(result, relationServer) {
return __awaiter(this, void 0, void 0, function* () {
const [key, checkResults] = result;
const fileContents = yield relationServer.getFileContentsByKey(key);
const viewCheckResults = checkResults.map((checkResult) => {
return pick(checkResult, [
"id",
"fromRev",
"fromBaseDir",
"fromPath",
"fromRange",
"toRev",
"toBaseDir",
"toPath",
"toRange",
]);
});
return Object.assign(Object.assign({ key, id: crypto
.createHash("sha1")
.update(JSON.stringify(checkResults))
.digest("hex"), checkResults: viewCheckResults, dirty: result.dirty }, pick(checkResults[0], [
"fromPath",
"fromBaseDir",
"toPath",
"toBaseDir",
"currentFromRev",
"currentToRev",
])), { fileContents });
});
}

23

dist/command/create.js

@@ -1,2 +0,11 @@

import { createRelations } from "relation2-core";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { RelationServer } from "relation2-core";
export default function (program) {

@@ -9,5 +18,11 @@ program

.option("--path <string>", "", "")
.action((opts) => {
createRelations(opts);
});
.action((opts) => __awaiter(this, void 0, void 0, function* () {
const relationServer = new RelationServer();
const relations = yield relationServer.read();
const newRelations = yield relationServer.createMarkdownRelations({
fromAbsolutePath: opts.srcPath,
toAbsolutePath: opts.path,
});
relationServer.write([...relations, ...newRelations]);
}));
}

@@ -1,13 +0,7 @@

import fse from "fs-extra";
import { getInfo } from "relation2-core";
const { readFileSync, writeFileSync, ensureFileSync } = fse;
import { RelationServer } from "relation2-core";
export default function (program) {
program.command("init").action((options) => {
const { relationFilePath } = getInfo(options);
ensureFileSync(relationFilePath);
const relationBuffer = readFileSync(relationFilePath);
if (!relationBuffer.toString()) {
writeFileSync(relationFilePath, "[]");
}
const relationServer = new RelationServer();
relationServer.init();
});
}

@@ -22,12 +22,16 @@ import { RelationServer } from "relation2-core";

.option("--id <string>")
.option("--srcRev <string>", "source reversion", "HEAD")
.option("--rev <string>", "reversion", "HEAD")
.option("--srcPath <string>", "", "")
.option("--path <string>", "", "")
.option("--srcRange <string>", "startLine,endLine", getRange)
.option("--range <string>", "startLine,endLine", getRange)
.option("--fromPath <string>", "", "")
.option("--toPath <string>", "", "")
.option("--fromRange <string>", "startLine,endLine", getRange)
.option("--toRange <string>", "startLine,endLine", getRange)
.action((opts) => {
const relationServer = new RelationServer();
relationServer.updateById(opts.id, opts);
relationServer.updateById(opts.id, (relation) => {
relation.fromPath = opts.fromPath;
relation.toPath = opts.toPath;
relation.fromRange = opts.fromRange;
relation.toRange = opts.toRange;
return relation;
});
});
}
{
"name": "relation2-cli",
"version": "0.0.21",
"version": "0.0.22",
"type": "module",

@@ -23,6 +23,7 @@ "bin": "./dist/index.js",

"diff": "^5.0.0",
"filenamify": "^5.1.1",
"fs-extra": "^10.1.0",
"nanoid": "^4.0.0",
"relation2-core": "0.0.21",
"relation2-page": "0.0.21",
"relation2-core": "0.0.22",
"relation2-page": "0.0.22",
"remark-parse": "^10.0.1",

@@ -65,3 +66,3 @@ "simple-git": "^3.10.0",

},
"gitHead": "85bfeadcb3b3be51cfe50cb8e730d0a9881856a5"
"gitHead": "ff66f5b80081b3a6a64a716180589e77aa46cfb5"
}
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