Skip to content
Open
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
2 changes: 0 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"prettier": "^2.7.1",
"semver": "7.5.2",
"semver-diff": "^3.1.1",
"temp": "^0.9.4",
"tslib": "^2.6.2"
},
"devDependencies": {
Expand All @@ -90,7 +89,6 @@
"@types/pluralize": "^0.0.29",
"@types/prettier": "^2.7.3",
"@types/semver": "^7.5.8",
"@types/temp": "^0.9.1",
"@vitest/ui": "^2.1.8",
"tsup": "^6.7.0",
"typescript": "^5.8.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import { getResourcePath } from "@utils/resource";
import spinner from "@utils/spinner";
import { uppercaseFirstChar } from "@utils/text";
import execa from "execa";
import { mkdtempSync } from "fs";
import {
copySync,
mkdirSync,
moveSync,
pathExistsSync,
removeSync,
unlinkSync,
} from "fs-extra";
import inquirer from "inquirer";
import { tmpdir } from "os";
import { join } from "path";
import { plural } from "pluralize";
import temp from "temp";
import { getCommandRootDir } from "./get-command-root-dir";

export const defaultActions = ["list", "create", "edit", "show"];
Expand Down Expand Up @@ -97,9 +99,6 @@ export const createResources = async (
// create temp dir
const tempDir = generateTempDir();

// copy template files
copySync(sourceDir, tempDir);

const compileParams = {
resourceName,
resource,
Expand All @@ -108,34 +107,39 @@ export const createResources = async (
isNextJs,
};

// compile dir
compileDir(tempDir, compileParams);

// delete ignored actions
if (customActions) {
defaultActions.forEach((action) => {
if (!customActions.includes(action)) {
unlinkSync(`${tempDir}/${action}.tsx`);
}
});
}

// create desctination dir
mkdirSync(destinationPath, { recursive: true });

// copy to destination
const destinationResourcePath = `${destinationPath}/${resourceFolderName}`;

let moveSyncOptions = {};
try {
// copy template files
copySync(sourceDir, tempDir);

// empty dir override
if (pathExistsSync(destinationResourcePath)) {
moveSyncOptions = { overwrite: true };
}
moveSync(tempDir, destinationResourcePath, moveSyncOptions);
// compile dir
compileDir(tempDir, compileParams);

// clear temp dir
temp.cleanupSync();
// delete ignored actions
if (customActions) {
defaultActions.forEach((action) => {
if (!customActions.includes(action)) {
unlinkSync(`${tempDir}/${action}.tsx`);
}
});
}

// create desctination dir
mkdirSync(destinationPath, { recursive: true });

let moveSyncOptions = {};

// empty dir override
if (pathExistsSync(destinationResourcePath)) {
moveSyncOptions = { overwrite: true };
}
moveSync(tempDir, destinationResourcePath, moveSyncOptions);
} finally {
if (pathExistsSync(tempDir)) {
removeSync(tempDir);
}
}

// if use Next.js, generate page files. This makes easier to use the resource
if (isNextJs) {
Expand Down Expand Up @@ -182,8 +186,7 @@ export const createResources = async (
};

const generateTempDir = (): string => {
temp.track();
return temp.mkdirSync("resource");
return mkdtempSync(join(tmpdir(), "refine-resource-"));
};

/**
Expand Down
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

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