Skip to content

Commit

Permalink
v2 updates & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyrenth committed Sep 3, 2024
1 parent 34ac727 commit bd343c2
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 29 deletions.
Binary file added Badges/ESBuild.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Badges/ESLint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Badges/Husky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Badges/Prettier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Badges/Typescript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 36 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
# ts-app-template
Base template for a typescript app.
<div align="center">
<p align="center">
<img width="750" src="Banner.png"/>
</p>
<p>
<a href="https://esbuild.github.io/">
<img height="48" src="Badges/ESBuild.png" />
</a>
<a href="https://www.typescriptlang.org/">
<img height="48" src="Badges/Typescript.png" />
</a>
<a href="https://prettier.io/">
<img height="48" src="Badges/Prettier.png" />
</a>
<a href="https://eslint.org/">
<img height="48" src="Badges/ESLint.png" />
</a>
<a href="https://typicode.github.io/husky/">
<img height="48" src="Badges/Husky.png" />
</a>
</p>
</div>

# Setup
After cloning, init your project by running
```bash
npm init -y
```

and install the required eslint plugins by running
```bash
npm i
```

# Files and scripts
You can find the `index.ts` file in the `src` directory and the build file at `scripts/build.js`.

You can build the project by running
```bash
npm run build
```

and start it by running
```bash
npm run start
```

1. After cloning the repository, make sure you have [pnpm](https://pnpm.io/) installed. If you don't, you can install it by running `npm install -g pnpm`.

2. After that, you can proceed to set up the project by running `pnpm run setup`. This will install all the necessary dependencies and purge the README, LICENSE, and Banner files which are no longer needed.

3. If you're using Visual Studio Code, you can also install the recommended extensions by clicking on the "Install Recommended Extensions" button that appears when you open the project.

4. You're all set! You can now start developing your project.

# Development

If you want to make a production build, you can run `pnpm run prod`. This will create a `dist` folder with the production build of your project.

If you want to make a development build, you can run `pnpm run dev`. This will create a `dist` folder with the development build of your project and will automatically rebuild the project whenever you make changes to the source files.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"lint": "tsc",
"build": "esbuild src/index.ts --outfile=dist/index.js --format=esm --bundle --platform=node --sourcemap",
"start": "node dist/index.js",
"prod": "node scripts/run.js lint build start",
"dev:lint": "tsc --watch --preserveWatchOutput",
"dev:start": "node --watch dist/index.js",
"dev:build": "esbuild src/index.ts --outfile=dist/index.js --format=esm --bundle --platform=node --sourcemap --watch",
"dev": "node scripts/run.js dev:lint dev:start dev:build",
"cleanup": "node scripts/cleanup.js dist",
"prepare": "husky"
"prepare": "husky",
"setup": "node scripts/setup.js"
},
"devDependencies": {
"@types/node": "^20.10.6",
Expand Down
2 changes: 1 addition & 1 deletion scripts/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fileURLToPath } from 'node:url';

import * as fs from 'fs';
import fs from 'fs';
import path from 'path';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
Expand Down
5 changes: 3 additions & 2 deletions scripts/run.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { exec } = require('child_process');
import { exec } from 'child_process';

const scripts = process.argv.slice(2);

const runScript = (scriptName) => {
return new Promise((resolve) => {
const proc = exec(`pnpm run ${scriptName}`, (error) => {
if (error) {
console.error(`An error occurred while running script "${scriptName}".`);
console.error(`An error occurred while running script "${scriptName}". Exiting...`);
process.exit(1);
} else {
resolve();
}
Expand Down
23 changes: 23 additions & 0 deletions scripts/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from 'fs';
import { execSync } from 'child_process';

const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));

console.log('[Setup]', 'Cleaning up...');

fs.unlinkSync('./README.md');
fs.unlinkSync('./LICENSE');

fs.unlinkSync('./Banner.png');
fs.rmdirSync('./Badges', { recursive: true });

delete packageJson.scripts.setup;
fs.writeFileSync('../package.json', JSON.stringify(packageJson, null, 4));

fs.unlinkSync(__filename);

console.log('[Setup]', 'Install dependencies...');

execSync('pnpm install');

console.log('[Setup]', 'Setup complete.');
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
console.log('Hello, world!');
console.log(`Typescript starter template, ready to go! - NodeJS v${process.version} TypeScript v${process.versions.typescript} on ${process.platform} platform.`);
console.log(`Typescript starter template, ready to go! - NodeJS ${process.version} on ${process.platform} platform.`);

0 comments on commit bd343c2

Please sign in to comment.