Skip to content

Commit

Permalink
chore(cli): remove cloning logic for components (bigcommerce#839)
Browse files Browse the repository at this point in the history
* chore(cli): remove cloning logic for components

* fix: remove instructions we don't need
  • Loading branch information
jorgemoya authored May 1, 2024
1 parent a1c334b commit 0e5e513
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-roses-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/create-catalyst": patch
---

Remove cloning logic for components.
80 changes: 14 additions & 66 deletions packages/create-catalyst/src/utils/clone-catalyst.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk';
import { readFile, writeFile } from 'fs/promises';
import { copySync, ensureDir, readJsonSync, removeSync, writeJsonSync } from 'fs-extra/esm';
import { ensureDir, readJsonSync, removeSync, writeJsonSync } from 'fs-extra/esm';
import { downloadTemplate } from 'giget';
import merge from 'lodash.merge';
import { join } from 'path';
Expand Down Expand Up @@ -33,21 +33,6 @@ export const cloneCatalyst = async ({
},
);

await spinner(
downloadTemplate(`github:bigcommerce/catalyst/packages/components#${ghRef}`, {
dir: join(projectDir, 'tmp'),
offline: false,
}),
{
text: 'Cloning Catalyst components...',
successText: 'Catalyst components cloned successfully',
failText: (err) => chalk.red(`Failed to clone Catalyst components: ${err.message}`),
},
);

copySync(join(projectDir, 'tmp/src/components'), join(projectDir, 'components', 'ui'));
copySync(join(projectDir, 'tmp/tailwind.config.js'), join(projectDir, 'tailwind.config.js'));

switch (codeEditor) {
case 'vscode':
await ensureDir(join(projectDir, '.vscode'));
Expand All @@ -71,29 +56,16 @@ export const cloneCatalyst = async ({
scripts: z.object({}).passthrough().optional(),
dependencies: z.object({}).passthrough(),
devDependencies: z.object({}).passthrough(),
private: z.boolean().optional(),
exports: z.object({}).passthrough().optional(),
sideEffects: z.boolean().optional(),
peerDependencies: z.object({}).passthrough().optional(),
})
.passthrough()
.parse(
merge(
{},
readJsonSync(join(projectDir, 'tmp/package.json')),
readJsonSync(join(projectDir, 'package.json')),
{ name: projectName, description: '' },
),
merge({}, readJsonSync(join(projectDir, 'package.json')), {
name: projectName,
description: '',
}),
);

delete packageJson.private;
delete packageJson.exports;
delete packageJson.sideEffects;
delete packageJson.peerDependencies; // will go away
delete packageJson.dependencies['@bigcommerce/components']; // will go away
delete packageJson.dependencies['@bigcommerce/catalyst-client'];
delete packageJson.devDependencies.react; // will go away
delete packageJson.devDependencies['react-dom']; // will go away
delete packageJson.devDependencies['@bigcommerce/eslint-config-catalyst'];

if (!includeFunctionalTests) {
Expand All @@ -103,42 +75,20 @@ export const cloneCatalyst = async ({

writeJsonSync(join(projectDir, 'package.json'), packageJson, { spaces: 2 });

const tsConfigJson = z
.object({
compilerOptions: z
.object({
declaration: z.boolean().optional(),
declarationMap: z.boolean().optional(),
paths: z
.object({
'@bigcommerce/components/*': z.string().array().optional(),
})
.passthrough(),
})
.passthrough(),
include: z.array(z.string()).optional(),
})
.passthrough()
.parse(
merge(
{},
readJsonSync(join(projectDir, 'tmp/tsconfig.json')),
readJsonSync(join(projectDir, 'tsconfig.json')),
),
);

delete tsConfigJson.compilerOptions.declaration;
delete tsConfigJson.compilerOptions.declarationMap;

tsConfigJson.compilerOptions.paths['@bigcommerce/components/*'] = ['./components/ui/*'];

if (!includeFunctionalTests) {
const tsConfigJson = z
.object({
include: z.array(z.string()).optional(),
})
.passthrough()
.parse(readJsonSync(join(projectDir, 'tsconfig.json')));

tsConfigJson.include = tsConfigJson.include?.filter(
(include) => !['tests/**/*', 'playwright.config.ts'].includes(include),
);
}

writeJsonSync(join(projectDir, 'tsconfig.json'), tsConfigJson, { spaces: 2 });
writeJsonSync(join(projectDir, 'tsconfig.json'), tsConfigJson, { spaces: 2 });
}

if (!includeFunctionalTests) {
const eslint = (await readFile(join(projectDir, '.eslintrc.cjs'), { encoding: 'utf-8' }))
Expand All @@ -150,6 +100,4 @@ export const cloneCatalyst = async ({
removeSync(join(projectDir, 'tests'));
removeSync(join(projectDir, 'playwright.config.ts'));
}

removeSync(join(projectDir, 'tmp'));
};

0 comments on commit 0e5e513

Please sign in to comment.