Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
refactor: Re-add mkdirp
Browse files Browse the repository at this point in the history
  • Loading branch information
p2kmgcl authored and Pablo Molina committed Jan 12, 2021
1 parent 5d8c991 commit 34e7f09
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"@liferay/npm-bundler": "3.0.1-pre.1",
"@types/mkdirp": "^1.0.1",
"@types/node-fetch": "^2.5.7",
"babel-loader": "^8.1.0",
"chalk": "^4.1.0",
Expand All @@ -60,6 +61,7 @@
"glob": "^7.1.1",
"jszip": "^3.1.5",
"mime-types": "^2.1.26",
"mkdirp": "^1.0.4",
"ncp": "^2.0.0",
"node-fetch": "^2.6.1",
"rimraf": "^3.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/export/export.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import glob from 'glob';
import JSZip from 'jszip';
import mkdirp from 'mkdirp';
import ncp from 'ncp';
import path from 'path';
import rimraf from 'rimraf';
Expand Down Expand Up @@ -34,7 +34,7 @@ export default async function exportProject(

try {
await extractZip(new JSZip(await api.exportZip(groupId)), tmpDir.name);
fs.mkdirSync(tmpSrc);
mkdirp.sync(tmpSrc);

// Move generated categories (fragments, page-templates...) to a
// single src directory
Expand Down
5 changes: 3 additions & 2 deletions src/utils/extract-zip.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import fs from 'fs';
import JSZip from 'jszip';
import mkdirp from 'mkdirp';
import path from 'path';

export const extractZip = async (
zip: JSZip,
destinationPath: string
): Promise<void> => {
if (!fs.existsSync(destinationPath)) {
fs.mkdirSync(destinationPath, { recursive: true });
mkdirp.sync(destinationPath);
} else if (!fs.statSync(destinationPath).isDirectory()) {
throw new Error(`${destinationPath} exists and is not a directory`);
}
Expand All @@ -19,7 +20,7 @@ export const extractZip = async (
const directoryPath = path.dirname(filePath);

if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath, { recursive: true });
mkdirp.sync(directoryPath);
}

fs.writeFileSync(filePath, await data.async('nodebuffer'));
Expand Down
15 changes: 7 additions & 8 deletions src/utils/project-content/write-project-content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import mkdirp from 'mkdirp';
import path from 'path';
import util from 'util';

Expand Down Expand Up @@ -27,7 +28,7 @@ export default async function writeProjectContent(
'projectContent must be a valid project object'
);

fs.mkdirSync(path.resolve(projectBasePath, 'src'), { recursive: true });
mkdirp.sync(path.resolve(projectBasePath, 'src'));

await _updateJSON(
path.resolve(projectBasePath, 'package.json'),
Expand Down Expand Up @@ -65,9 +66,7 @@ export default async function writeProjectContent(
}

const _updateFile = async (filePath: string, content: string | Buffer) => {
fs.mkdirSync(filePath.substring(0, filePath.lastIndexOf(path.sep)), {
recursive: true,
});
mkdirp.sync(filePath.substring(0, filePath.lastIndexOf(path.sep)));
await writeFilePromise(filePath, content);
};

Expand All @@ -87,7 +86,7 @@ const _writeFragment = async (
collection: ICollection,
fragment: IFragment
) => {
fs.mkdirSync(fragmentBasePath, { recursive: true });
mkdirp.sync(fragmentBasePath);

await _updateJSON(
path.resolve(fragmentBasePath, 'fragment.json'),
Expand Down Expand Up @@ -138,7 +137,7 @@ const _writeFragmentComposition = async (
collection: ICollection,
fragmentComposition: IFragmentComposition
) => {
fs.mkdirSync(fragmentBasePath, { recursive: true });
mkdirp.sync(fragmentBasePath);

await _updateJSON(
path.resolve(fragmentBasePath, 'fragment-composition.json'),
Expand All @@ -160,7 +159,7 @@ const _writeCollection = async (
collectionBasePath: string,
collection: ICollection
) => {
fs.mkdirSync(path.resolve(collectionBasePath), { recursive: true });
mkdirp.sync(path.resolve(collectionBasePath));

await _updateJSON(
path.resolve(collectionBasePath, 'collection.json'),
Expand Down Expand Up @@ -196,7 +195,7 @@ const _writePageTemplate = async (
pageTemplateBasePath: string,
pageTemplate: IPageTemplate
) => {
fs.mkdirSync(pageTemplateBasePath, { recursive: true });
mkdirp.sync(pageTemplateBasePath);

await _updateFile(
path.resolve(pageTemplateBasePath, `${pageTemplate.metadata.type}.json`),
Expand Down
3 changes: 2 additions & 1 deletion src/utils/temporary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import mkdirp from 'mkdirp';
import os from 'os';
import path from 'path';
import rimraf from 'rimraf';
Expand All @@ -13,7 +14,7 @@ let nextTemporaryId = 0;

export function createTemporaryDirectory(): Element {
const name = getTemporaryName();
fs.mkdirSync(name, { recursive: true });
mkdirp.sync(name);

return {
name,
Expand Down
5 changes: 2 additions & 3 deletions src/utils/write-zip.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fs from 'fs';
import JSZip from 'jszip';
import mkdirp from 'mkdirp';
import path from 'path';

export default function writeZip(zip: JSZip, filePath: string): Promise<void> {
fs.mkdirSync(filePath.substring(0, filePath.lastIndexOf(path.sep)), {
recursive: true,
});
mkdirp.sync(filePath.substring(0, filePath.lastIndexOf(path.sep)));

return new Promise((resolve) =>
zip
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,13 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/mkdirp@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-1.0.1.tgz#0930b948914a78587de35458b86c907b6e98bbf6"
integrity sha512-HkGSK7CGAXncr8Qn/0VqNtExEE+PHMWb+qlR1faHMao7ng6P3tAaoWWBMdva0gL5h4zprjIO89GJOLXsMcDm1Q==
dependencies:
"@types/node" "*"

"@types/ncp@^2.0.0":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/ncp/-/ncp-2.0.4.tgz#16c9e7fa2c849d429a1b142648987164b06bf490"
Expand Down

0 comments on commit 34e7f09

Please sign in to comment.