Skip to content

Commit

Permalink
feat: add src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajera committed Apr 28, 2023
1 parent 847274b commit 4f6a606
Show file tree
Hide file tree
Showing 69 changed files with 84 additions and 61 deletions.
40 changes: 27 additions & 13 deletions packages/create-bison-app/tasks/copyFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ const { copyDirectoryWithTemplate } = require('../utils/copyDirectoryWithTemplat

const templateFolder = path.join(__dirname, '..', 'template');
const fromPath = (file) => path.join(templateFolder, file);
const fromSrcPath = (file) => path.join(templateFolder, 'src', file);

/**
* Copies files based on variables and a target folder
*/
async function copyFiles({ variables, targetFolder }) {
const toPath = (file) => path.join(targetFolder, file);
const toSrcPath = (file) => path.join(targetFolder, 'src', file);

// Files to render when using Heroku
const isHeroku = variables.host.name === 'heroku';
Expand Down Expand Up @@ -51,10 +53,10 @@ async function copyFiles({ variables, targetFolder }) {

copyDirectoryWithTemplate(fromPath('.github'), toPath('.github'), variables),

copyDirectoryWithTemplate(fromPath('pages'), toPath('pages'), variables),
copyDirectoryWithTemplate(fromSrcPath('pages'), toSrcPath('pages'), variables),
copyDirectoryWithTemplate(fromPath('prisma'), toPath('prisma'), variables),

copyDirectoryWithTemplate(fromPath('server'), toPath('server'), variables),
copyDirectoryWithTemplate(fromSrcPath('server'), toSrcPath('server'), variables),

copyDirectoryWithTemplate(fromPath('tests'), toPath('tests'), variables),

Expand All @@ -65,23 +67,13 @@ async function copyFiles({ variables, targetFolder }) {
'__mocks__',
'_templates',
'.vscode',
'components',
'context',
'hooks',
'layouts',
'lib',
'prisma',
'public',
'scripts',
'services',
'styles',
'types',
'utils',
'.eslintrc.js',
'.hygen.js',
'.nvmrc',
'.tool-versions',
'constants.ts',
'jest.config.js',
'playwright.config.ts',
'next-env.d.ts',
Expand All @@ -90,7 +82,6 @@ async function copyFiles({ variables, targetFolder }) {
'tsconfig.cjs.json',
'tailwind.config.js',
'postcss.config.js',
'config.ts',
],
targetFolder,
{
Expand All @@ -100,6 +91,29 @@ async function copyFiles({ variables, targetFolder }) {
parents: true,
}
),

cpy(
[
'components',
'context',
'hooks',
'layouts',
'lib',
'services',
'styles',
'types',
'utils',
'config.ts',
'constants.ts',
],
path.join(targetFolder, 'src'),
{
cwd: path.join(templateFolder, 'src'),
dot: true,
// preserve path
parents: true,
}
),
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Prisma, Role } from '@prisma/client';

import { seedUsers } from '~/prisma/seeds/users';
import { hashPassword } from '@/services/auth';
import { seedUsers } from '@/prisma/seeds/users';
import { prisma } from '@/lib/prisma';

// HR: Hey, we've had a few more employees join -- can you create an account for them?!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export function LoggedOutLayout({ children }: Props) {
<div className="flex justify-between items-center p-4">
<Logo />

<Link href="/login" passHref>
<a className={buttonVariants({ variant: 'outline' })} href="/login">
Login
</a>
<Link className={buttonVariants({ variant: 'outline' })} href="/login" passHref>
Login
</Link>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/create-bison-app/template/tests/e2e/auth.play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Role } from '@prisma/client';

import { loginAs } from './helpers';

import { resetDB } from '@/tests/helpers/db';
import { resetDB } from '~/tests/helpers/db';
import { disconnect } from '@/lib/prisma';

test.beforeEach(async () => resetDB());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FullConfig } from '@playwright/test';

import { prisma } from '@/lib/prisma';
import { getSchema } from '@/tests/helpers/db';
import { getSchema } from '~/tests/helpers/db';
import { config } from '@/config';

async function globalTeardown(_config: FullConfig) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-bison-app/template/tests/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Role } from '@prisma/client';
import { encode as encodeJwt } from 'next-auth/jwt';
import { nanoid } from 'nanoid';

import { UserFactory } from '@/tests/factories/user';
import playwrightConfig from '@/playwright.config';
import { UserFactory } from '~/prisma/factories/user';
import playwrightConfig from '~/playwright.config';
import { config } from '@/config';

const chance = new Chance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Role } from '@prisma/client';

import { resetDB, disconnect, trpcRequest } from '@/tests/helpers';
import { UserFactory } from '@/tests/factories/user';
import { resetDB, disconnect, trpcRequest } from '~/tests/helpers';
import { UserFactory } from '~/prisma/factories/user';

beforeEach(async () => resetDB());
afterAll(async () => disconnect());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { trpcRequest, resetDB, disconnect } from '@/tests/helpers';
import { UserFactory } from '@/tests/factories/user';
import { trpcRequest, resetDB, disconnect } from '~/tests/helpers';
import { UserFactory } from '~/prisma/factories/user';

beforeEach(async () => resetDB());
afterAll(async () => disconnect());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Role } from '@prisma/client';

import { resetDB, disconnect, trpcRequest } from '@/tests/helpers';
import { UserFactory } from '@/tests/factories/user';
import { resetDB, disconnect, trpcRequest } from '~/tests/helpers';
import { UserFactory } from '~/prisma/factories/user';

beforeEach(async () => resetDB());
afterAll(async () => disconnect());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/

import { render } from '@/tests/utils';
import { render } from '~/tests/utils';
import { CenteredBoxForm } from '@/components/CenteredBoxForm';

describe('CenteredBoxForm', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/

import { render } from '@/tests/utils';
import { render } from '~/tests/utils';
import { ErrorText } from '@/components/ErrorText';

describe('ErrorText', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @jest-environment jsdom
*/

import { render } from '@/tests/utils';
import { render } from '~/tests/utils';
import { Logo } from '@/components/Logo';
import '@/tests/matchMedia.mock';
import '~/tests/matchMedia.mock';

describe('Logo', () => {
it('loads', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @jest-environment jsdom
*/

import { render } from '@/tests/utils';
import '@/tests/matchMedia.mock';
import { render } from '~/tests/utils';
import '~/tests/matchMedia.mock';
import { Nav } from '@/components/Nav';

describe('Nav', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/

import { render, waitFor, userEvent, fireEvent, act } from '@/tests/utils';
import { render, waitFor, userEvent, fireEvent, act } from '~/tests/utils';
import { SignUpForm } from '@/components/auth/SignUpForm';

// need this in order to use `act`
Expand Down
2 changes: 1 addition & 1 deletion packages/create-bison-app/template/tests/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NextRouter } from 'next/router';
import fetch from 'cross-fetch';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import '@testing-library/jest-dom/extend-expect';
import '@/tests/matchMedia.mock';
import '~/tests/matchMedia.mock';

import { AllProviders } from '@/components/AllProviders';
import type { AppRouter } from '@/server/routers/_app';
Expand Down
3 changes: 2 additions & 1 deletion packages/create-bison-app/template/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"rootDir": ".",
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
"~/*": ["./*"],
"@/*": ["./src/*"]
},
"incremental": true
},
Expand Down
24 changes: 10 additions & 14 deletions packages/create-bison-app/test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("cli", () => {
describe('cli', () => {
let createBisonApp;
let originalArgv;

Expand All @@ -7,8 +7,8 @@ describe("cli", () => {
// multiple times with different arguments.
jest.resetModules();

jest.mock("..");
createBisonApp = require("..");
jest.mock('..');
createBisonApp = require('..');

// Each test overwrites process arguments so store the original arguments
originalArgv = process.argv;
Expand All @@ -19,8 +19,8 @@ describe("cli", () => {
process.argv = originalArgv;
});

it("should create app with default configuration", async () => {
await runCreateBisonAppCommand("appName1", "--acceptDefaults");
it('should create app with default configuration', async () => {
await runCreateBisonAppCommand('appName1', '--acceptDefaults');

expect(createBisonApp).toHaveBeenCalledTimes(1);
expect(createBisonApp.mock.calls[0][0]).toMatchInlineSnapshot(`
Expand All @@ -45,12 +45,8 @@ describe("cli", () => {
`);
});

it("should create app with default configuration and override with any arguments", async () => {
await runCreateBisonAppCommand(
"appName2",
"--acceptDefaults",
"--db.dev.name=custom"
);
it('should create app with default configuration and override with any arguments', async () => {
await runCreateBisonAppCommand('appName2', '--acceptDefaults', '--db.dev.name=custom');

expect(createBisonApp).toHaveBeenCalledTimes(1);
expect(createBisonApp.mock.calls[0][0]).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -84,11 +80,11 @@ describe("cli", () => {
*/
async function runCreateBisonAppCommand(appName, ...options) {
process.argv = [
"node", // Not used but required at this index in the array
"../cli.js", // Not used but required at this index in the array
'node', // Not used but required at this index in the array
'../cli.js', // Not used but required at this index in the array
appName, // App name positional argument
...options, // Any option arguments
];

return require("../cli");
return require('../cli');
}
Loading

0 comments on commit 4f6a606

Please sign in to comment.