Skip to content

Commit

Permalink
fix(deletion-script): fix script encoding on windows (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
cberthou committed Apr 13, 2021
1 parent 8c474c9 commit c4b69e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -176,6 +176,7 @@
"styled-components": "^5.2.3",
"triple-beam": "^1.3.0",
"uuid": "8.3.2",
"windows-1252": "^1.0.0",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.2",
"winston-transport": "^4.4.0",
Expand Down
17 changes: 15 additions & 2 deletions src/exporters/deletion-script/deletion-script-exporter.ts
Expand Up @@ -15,15 +15,28 @@ import {
import { TFunction } from "react-i18next";
import translations from "translations/translations";
import { showInFolder } from "util/file-system/file-system-util";
import { isWindows } from "../../util/os/os-util";
import { encode } from "windows-1252";

const prepareElementsToDelete = compose(
map(startPathFromOneLevelAbove),
removeChildrenPath,
getElementsToDeleteFromStore
);

const curriedWriteFile = (filePath: string) => (data: string) =>
fs.promises.writeFile(filePath, data);
const windowsFileWriter = (path: string) =>
compose(
(binaryString: string) =>
fs.promises.writeFile(path, binaryString, "binary"),
encode
);

const unixFileWriter = (path: string) => (data: string) =>
fs.promises.writeFile(path, data);

const getFileWriter = () => (isWindows() ? windowsFileWriter : unixFileWriter);

const curriedWriteFile = getFileWriter();

const extractParamsFromState = (state: StoreState) => ({
originalPath: getWorkspaceMetadataFromStore(state).originalPath,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -11251,6 +11251,11 @@ winattr@^3.0.0:
dependencies:
fswin "^3.18.918"

windows-1252@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/windows-1252/-/windows-1252-1.0.0.tgz#721d9467d4da172d2b8dd2a56094b04355fe5976"
integrity sha1-ch2UZ9TaFy0rjdKlYJSwQ1X+WXY=

winston-daily-rotate-file@^4.5.2:
version "4.5.2"
resolved "https://registry.yarnpkg.com/winston-daily-rotate-file/-/winston-daily-rotate-file-4.5.2.tgz#abe72bc8973dcc294faff54ae9a589180cf92866"
Expand Down

0 comments on commit c4b69e4

Please sign in to comment.