Skip to content

Commit

Permalink
skip package.json from copying
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed Jul 6, 2024
1 parent 10a808f commit e340ecb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
30 changes: 20 additions & 10 deletions create-extension-cli/create-extension.js

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

2 changes: 1 addition & 1 deletion create-extension-cli/create-extension.js.map

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

17 changes: 17 additions & 0 deletions src/dev/create-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const TARGET_EXTENSION_DIR = "extension";
const TEMPLATE_FILE_SUFFIX = ".template.mjs";
const DEPLOYED_CONTRACTS_FILE = "deployedContracts.ts";
const YARN_LOCK_FILE = "yarn.lock";
const PACKAGE_JSON_FILE = "package.json";
const NEXTJS_DIR = "nextjs";

const prettyLog = {
info: (message: string, indent = 0) => console.log(chalk.cyan(`${" ".repeat(indent)}${message}`)),
Expand Down Expand Up @@ -77,6 +79,8 @@ const findTemplateFiles = async (dir: string, templates: Set<string>) => {

const copyFiles = async (files: string[], projectName: string, projectPath: string, templates: Set<string>) => {
for (const file of files) {
const pathSegmentsOfFile = file.split(path.sep);

const sourcePath = path.resolve(projectPath, file);
const destPath = path.join(EXTERNAL_EXTENSIONS_DIR, projectName, TARGET_EXTENSION_DIR, file);

Expand All @@ -99,6 +103,19 @@ const copyFiles = async (files: string[], projectName: string, projectPath: stri
continue;
}

const isRootPackageJson = pathSegmentsOfFile.length === 1 && pathSegmentsOfFile[0] === PACKAGE_JSON_FILE;
const isNextJsPackageJson =
pathSegmentsOfFile.includes(NEXTJS_DIR) && pathSegmentsOfFile.includes(PACKAGE_JSON_FILE);
const isSolidityFrameworkPackageJson =
(pathSegmentsOfFile.includes(SOLIDITY_FRAMEWORKS.HARDHAT) ||
pathSegmentsOfFile.includes(SOLIDITY_FRAMEWORKS.FOUNDRY)) &&
pathSegmentsOfFile.includes(PACKAGE_JSON_FILE);
if (isRootPackageJson || isNextJsPackageJson || isSolidityFrameworkPackageJson) {
prettyLog.warning(`Skipping file: ${file}`, 2);
prettyLog.info(`Please manyally just add new scripts or dependencies in: ${destPath}`, 3);
continue;
}

await createDirectories(file, projectName);
await ncpPromise(sourcePath, destPath);
prettyLog.success(`Copied: ${file}`, 2);
Expand Down

0 comments on commit e340ecb

Please sign in to comment.