Skip to content

Commit

Permalink
feat(cli): Add package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Jul 17, 2024
1 parent 007b9d6 commit 678de05
Show file tree
Hide file tree
Showing 36 changed files with 371 additions and 309 deletions.
4 changes: 2 additions & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"geist": "^1.3.1",
"next": "15.0.0-rc.0",
"next-intl": "^3.15.5",
"next-intl": "^3.17.1",
"react": "19.0.0-rc.0",
"react-dom": "19.0.0-rc.0",
"vitnode-frontend": "workspace:*",
Expand All @@ -29,7 +29,7 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.19",
"eslint": "^8",
"eslint": "^8.57.0",
"eslint-config-typescript-vitnode": "workspace:*",
"graphql-tag": "^2.12.6",
"postcss": "^8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ yarn-error.log*
*.pem

# Docker
/docker
/docker

# Others
/backend/uploads/public/*
/backend/uploads/private/*
/backend/uploads/temp/*
!/backend/uploads/index.html
!/backend/uploads/public/index.html
!/backend/uploads/private/index.html
!/backend/uploads/temp/index.html
/backend/schema.gql

# Configuration
/backend/src/plugins/*/admin/database/migrations
/backend/src/plugins/core/
71 changes: 0 additions & 71 deletions packages/create-vitnode-app/templates/basic/backend/.gitignore

This file was deleted.

134 changes: 134 additions & 0 deletions packages/create-vitnode-app/templates/create-packages-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

interface PackageJSON {
name: string;
version: string;
private: boolean;
devDependencies?: Record<string, string>;
dependencies?: Record<string, string>;
scripts?: Record<string, string>;
workspaces?: string[];
}

export const createPackagesJSON = ({
appName,
root,
}: {
appName: string;
root: string;
}) => {
const pkg: PackageJSON = JSON.parse(
readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'),
);

const basePackageJSON: PackageJSON = {
name: appName,
version: '1.0.0',
private: true,
scripts: {
'config:init': 'vitnode-frontend init',
dev: 'vitnode-frontend init && turbo dev',
build: 'turbo build',
lint: 'turbo lint',
'lint:fix': 'turbo lint:fix',
},
dependencies: {
'drizzle-kit': '^0.22.8',
'drizzle-orm': '^0.31.4',
},
devDependencies: {
'eslint-config-typescript-vitnode': `^${pkg.version}`,
prettier: '^3.3.3',
'prettier-plugin-tailwindcss': '^0.6.5',
turbo: '^2.0.7',
typescript: '^5.4.5',
},
workspaces: ['apps/*'],
};

writeFileSync(
join(root, 'package.json'),
JSON.stringify(basePackageJSON, null, 2),
);

const frontendPackagesJSON: PackageJSON = {
name: 'frontend',
version: '1.0.0',
private: true,
scripts: {
dev: 'next dev --turbo',
build: 'next build',
start: 'next start',
lint: 'eslint .',
'lint:fix': 'eslint . --fix',
},
dependencies: {
next: '15.0.0-rc.0',
react: '19.0.0-rc.0',
'react-dom': '19.0.0-rc.0',
'next-intl': '^3.17.1',
'vitnode-frontend': `^${pkg.version}`,
},
devDependencies: {
'@types/node': '^20.14.11',
'@types/react': '^18.3.3',
'@types/react-dom': '^18.3.0',
eslint: '^8.57.0',
'eslint-config-typescript-vitnode': `^${pkg.version}`,
typescript: '^5.5.3',
},
};

writeFileSync(
join(root, 'apps', 'frontend', 'package.json'),
JSON.stringify(frontendPackagesJSON, null, 2),
);

const backendPackagesJSON: PackageJSON = {
name: 'backend',
version: '1.0.0',
private: true,
scripts: {
'config:init': 'vitnode-backend init',
build: 'nest build',
dev: 'vitnode-backend init && cross-env NODE_ENV=development nest start -w',
start: 'node dist/main',
lint: 'eslint .',
'lint:fix': 'eslint . --fix',
},
dependencies: {
'@nestjs/common': '^10.3.10',
'@nestjs/core': '^10.3.10',
'@nestjs/graphql': '^12.2.0',
'@react-email/components': '^0.0.21',
'reflect-metadata': '^0.2.2',
'vitnode-backend': `^${pkg.version}`,
},
devDependencies: {
'@nestjs/cli': '^10.4.2',
'@nestjs/platform-express': '^10.3.10',
'@nestjs/schematics': '^10.1.2',
'@types/express': '^4.17.21',
'@types/node': '^20.14.11',
'@types/pg': '^8.11.6',
'@types/react': '^18.3.3',
'cross-env': '^7.0.3',
'drizzle-kit': '^0.22.8',
'drizzle-orm': '^0.31.4',
eslint: '^8.57.0',
'eslint-config-typescript-vitnode': `^${pkg.version}`,
pg: '^8.12.0',
'source-map-support': '^0.5.21',
'ts-loader': '^9.5.1',
'ts-node': '^10.9.2',
'tsconfig-paths': '^4.2.0',
typescript: '^5.5.3',
},
};

writeFileSync(
join(root, 'apps', 'backend', 'package.json'),
JSON.stringify(backendPackagesJSON, null, 2),
);
};
20 changes: 18 additions & 2 deletions packages/create-vitnode-app/templates/create-vitnode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { cpSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { cpSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'fs';
import { join } from 'path';

import color from 'picocolors';

import { isFolderEmpty } from '../helpers/is-folder-empty';
import { CreateCliReturn } from '../cli';
import { createPackagesJSON } from './create-packages-json';

interface Args extends CreateCliReturn {
appName: string;
Expand Down Expand Up @@ -32,11 +33,20 @@ export const createVitNode = ({
}

process.chdir(root);
const packageJsonPath = join(root, 'package.json');

// Copy the basic template
cpSync(join(templatePath, 'basic'), root, { recursive: true });

// Create package.json
createPackagesJSON({
appName,
root,
});

// Rename files
renameSync(join(root, '.gitignore_template'), join(root, '.gitignore'));
renameSync(join(root, '.npmrc_template'), join(root, '.npmrc'));

// Change tailwind.config.ts based on package manager
if (packageManager === 'pnpm') {
const tailwindConfigPath = join(root, 'frontend', 'tailwind.config.ts');
Expand All @@ -54,6 +64,12 @@ export const createVitNode = ({
writeFileSync(tailwindConfigPath, newTailwindConfig);
}

// Copy pnpm template
if (packageManager === 'pnpm') {
cpSync(join(templatePath, 'pnpm'), root, { recursive: true });
}

// Copy eslint template
if (eslint) {
cpSync(join(templatePath, 'eslint'), root, { recursive: true });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- 'apps/*'
6 changes: 3 additions & 3 deletions packages/eslint-config-typescript-vitnode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
"prettierrc"
],
"peerDependencies": {
"eslint": "^8",
"eslint": "^8.57.0",
"typescript": "^5.5.3"
},
"devDependencies": {
"eslint": "8.57.0",
"eslint": "^8.57.0",
"typescript": "^5.5.3"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint-config-next": "15.0.0-canary.64",
"eslint-config-next": "15.0.0-rc.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
"lodash": "^4.17.21",
"lowlight": "^3.1.0",
"lucide-react": "^0.408.0",
"next": "15.0.0-canary.64",
"next-intl": "^3.16.0",
"next": "15.0.0-rc.0",
"next-intl": "^3.17.1",
"next-themes": "^0.3.0",
"nextjs-toploader": "^1.6.12",
"nprogress": "^0.2.0",
Expand Down
Loading

0 comments on commit 678de05

Please sign in to comment.