Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversion #24

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/manual-deprecate-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Deprecate versions

on:
workflow_dispatch:
inputs:
version-expression:
description: version number (semver format) or range to deprecate
required: true
type: string
rationale:
description: explain why this version is deprecated. No message content will un-deprecate the version
type: string

jobs:
deprecate:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"

- name: Change version
run: npm deprecate xml2json-disassembler@$"${{ github.event.inputs.version-expression }}" "${{ github.event.inputs.rationale }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"tslib": "^2.6.2",
"xml-disassembler": "^1.3.10"
"xml-disassembler": "^1.3.11"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 8 additions & 16 deletions src/service/deleteReassembledXML.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
"use strict";

import { readdir, rm } from "node:fs/promises";
import { stat, readdir, rm } from "node:fs/promises";
import { join } from "node:path/posix";
import {
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

export async function deleteReassembledXML(
disassembledPath: string,
): Promise<void> {
const tasks: (() => Promise<void>)[] = [];
const files = await readdir(disassembledPath, { withFileTypes: true });
const concurrencyLimit = getConcurrencyThreshold();

const files = await readdir(disassembledPath);
for (const file of files) {
const subFilePath = join(disassembledPath, file.name);

if (file.isFile() && subFilePath.endsWith(".xml")) {
tasks.push(() => rm(subFilePath));
} else if (file.isDirectory()) {
tasks.push(() => deleteReassembledXML(subFilePath));
const filePath = join(disassembledPath, file);
const fileStat = await stat(filePath);
if (fileStat.isFile() && filePath.endsWith(".xml")) {
await rm(filePath);
} else if (fileStat.isDirectory()) {
await deleteReassembledXML(filePath);
}
}
await withConcurrencyLimit(tasks, concurrencyLimit);
}
22 changes: 7 additions & 15 deletions src/service/json2xmlReassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import { stat, readdir } from "node:fs/promises";
import { join } from "node:path/posix";
import {
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

import { logger } from "@src/index";
import { reassembleHandler } from "@src/service/reassembleHandler";
Expand Down Expand Up @@ -38,19 +34,15 @@ export class JsonToXmlReassembler {
}

async processFile(filePath: string): Promise<void> {
const tasks: (() => Promise<void>)[] = [];
const files = await readdir(filePath, { withFileTypes: true });
const concurrencyLimit = getConcurrencyThreshold();

const files = await readdir(filePath);
for (const file of files) {
const subFilePath = join(filePath, file.name);

if (file.isFile() && subFilePath.endsWith(".json")) {
tasks.push(() => transform2XML(subFilePath));
} else if (file.isDirectory()) {
tasks.push(() => this.processFile(subFilePath));
const subFilePath = join(filePath, file);
const subFileStat = await stat(subFilePath);
if (subFileStat.isFile() && subFilePath.endsWith(".json")) {
await transform2XML(subFilePath);
} else if (subFileStat.isDirectory()) {
await this.processFile(subFilePath);
}
}
await withConcurrencyLimit(tasks, concurrencyLimit);
}
}
34 changes: 13 additions & 21 deletions src/service/transform2JSON.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
"use strict";

import { readdir, rm, writeFile } from "node:fs/promises";
import { readdir, rm, stat, writeFile } from "node:fs/promises";
import { join } from "node:path/posix";
import {
parseXML,
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";
import { parseXML } from "xml-disassembler";

import { logger } from "@src/index";

export async function transform2JSON(xmlPath: string): Promise<void> {
const tasks: (() => Promise<void>)[] = [];
const files = await readdir(xmlPath, { withFileTypes: true });
const concurrencyLimit = getConcurrencyThreshold();
const foldersToRemote = [];

for (const subFile of files) {
const subFilePath = join(xmlPath, subFile.name);
if (subFile.isDirectory()) {
tasks.push(() => transform2JSON(subFilePath));
} else if (subFile.isFile() && subFilePath.endsWith(".xml")) {
tasks.push(() => writeJSON(subFilePath));
foldersToRemote.push(subFilePath);
const subFiles = await readdir(xmlPath);
for (const subFile of subFiles) {
const subFilePath = join(xmlPath, subFile);
if ((await stat(subFilePath)).isDirectory()) {
await transform2JSON(subFilePath);
} else if (
(await stat(subFilePath)).isFile() &&
subFilePath.endsWith(".xml")
) {
await writeJSON(subFilePath);
await rm(subFilePath);
}
}
await withConcurrencyLimit(tasks, concurrencyLimit);
const deleteTasks = foldersToRemote.map((filePath) => () => rm(filePath));
await withConcurrencyLimit(deleteTasks, concurrencyLimit);
}

async function writeJSON(xmlPath: string): Promise<void> {
Expand Down
42 changes: 15 additions & 27 deletions src/service/xml2jsonDisassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import { existsSync } from "node:fs";
import { stat, readdir } from "node:fs/promises";
import { resolve, join, basename, dirname, extname } from "node:path/posix";
import {
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

import { logger } from "@src/index";
import { disassembleHandler } from "@src/service/disassembleHandler";
Expand All @@ -27,44 +23,36 @@ export class XmlToJsonDisassembler {
postPurge = false,
ignorePath = ".xmldisassemblerignore",
} = xmlAttributes;
const concurrencyLimit = getConcurrencyThreshold();
const tasks = [];
const fileStat = await stat(filePath);

if (fileStat.isFile()) {
const resolvedPath = resolve(filePath);
if (!resolvedPath.endsWith(".xml")) {
logger.error(`The file path is not an XML file: ${resolvedPath}`);
logger.error(`The file path is not an XML file: ${resolvedPath}`);
return;
}
tasks.push(() =>
this.processFile({
filePath: resolvedPath,
uniqueIdElements,
prePurge,
postPurge,
ignorePath,
}),
);
await this.processFile({
filePath: resolvedPath,
uniqueIdElements,
prePurge,
postPurge,
ignorePath,
});
} else if (fileStat.isDirectory()) {
const subFiles = await readdir(filePath);
for (const subFile of subFiles) {
const subFilePath = join(filePath, subFile);
if (subFilePath.endsWith(".xml")) {
tasks.push(() =>
this.processFile({
filePath: subFilePath,
uniqueIdElements,
prePurge,
postPurge,
ignorePath,
}),
);
await this.processFile({
filePath: subFilePath,
uniqueIdElements,
prePurge,
postPurge,
ignorePath,
});
}
}
}

await withConcurrencyLimit(tasks, concurrencyLimit);
}

async processFile(xmlAttributes: {
Expand Down
Loading