Skip to content

Commit dd4e7ee

Browse files
feat: Enhance build and publish scripts, add prompts for command selection
1 parent 9bf627b commit dd4e7ee

10 files changed

Lines changed: 136 additions & 33 deletions

File tree

package.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,13 @@
99
"dist"
1010
],
1111
"scripts": {
12-
"clean": "rimraf dist",
13-
"build": "tsc && pnpm exec tsc-alias",
14-
"rebuild": "pnpm run clean && pnpm run build",
12+
"format": "prettier --write 'src/**/*.{ts,tsx,js,json,md}'",
1513
"lint": "eslint src/**/*.{ts,tsx}",
1614
"lint:fix": "eslint src/**/*.{ts,tsx} --fix",
17-
"test": "jest",
18-
"test:watch": "jest --watch",
19-
"test:coverage": "jest --coverage",
20-
"start:dev": "ts-node -r tsconfig-paths/register src/FastKit.ts",
21-
"start:test": "ts-node --transpile-only src/test.ts",
22-
"format": "prettier --write 'src/**/*.{ts,tsx,js,json,md}'",
23-
"prepublishOnly": "pnpm run format && pnpm run lint && pnpm run build",
24-
"publish:npm": "npm publish --access public",
25-
"publish:pnpm": "pnpm publish --access public --no-git-checks",
26-
"version:patch": "npm version patch",
27-
"version:minor": "npm version minor",
28-
"version:major": "npm version major"
15+
"link": "npm link @nexgenstudiodev/fastkit",
16+
"build": "tsc && pnpm exec tsc-alias",
17+
"link:manage": "ts-node src/script/manage-link.ts",
18+
"manage": "ts-node src/script/index.ts"
2919
},
3020
"keywords": [
3121
"api",
@@ -78,8 +68,10 @@
7868
"jest": "^30.0.3",
7969
"lint-staged": "^16.1.2",
8070
"prettier": "^3.6.2",
71+
"prompts": "^2.4.2",
8172
"rimraf": "^6.0.1",
8273
"ts-jest": "^29.4.0",
74+
"ts-node": "^10.9.2",
8375
"ts-node-dev": "^2.0.0",
8476
"tsc-alias": "^1.8.16",
8577
"tsconfig-paths": "^4.2.0",

pnpm-lock.yaml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/FastKit-Config/__test__/config.test.dist.js

Whitespace-only changes.

src/config/FastKit-Config/config.validation.ts

Whitespace-only changes.

src/script/build.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { execSync } from 'child_process';
2+
3+
4+
export function build() {
5+
console.log('Running clean...');
6+
execSync('rimraf dist', { stdio: 'inherit' });
7+
8+
console.log('Compiling TypeScript...');
9+
execSync('tsc', { stdio: 'inherit' });
10+
11+
console.log('Fixing path aliases...');
12+
execSync('pnpm exec tsc-alias', { stdio: 'inherit' });
13+
14+
console.log('Build complete!');
15+
}

src/script/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import prompts from 'prompts';
2+
import { build } from './build';
3+
import { startProd } from './production';
4+
import { publish } from './publish';
5+
6+
async function main() {
7+
const response = await prompts({
8+
type: 'select',
9+
name: 'command',
10+
message: 'Which script do you want to run?',
11+
choices: [
12+
{ title: 'Build', value: 'build' },
13+
{ title: 'Start Production', value: 'prod' },
14+
{ title: 'Publish', value: 'publish' },
15+
{ title: 'Exit', value: 'exit' },
16+
],
17+
});
18+
19+
switch (response.command) {
20+
case 'build':
21+
build();
22+
break;
23+
case 'prod':
24+
startProd();
25+
break;
26+
case 'publish':
27+
publish();
28+
break;
29+
default:
30+
console.log('Exiting...');
31+
process.exit(0);
32+
}
33+
}
34+
35+
main();

src/script/production.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { execSync } from 'child_process';
2+
3+
export function startProd() {
4+
console.log('Running pre-production tasks: format, lint, build');
5+
execSync('pnpm run format && pnpm run lint --fix && pnpm run build', { stdio: 'inherit' });
6+
7+
console.log('Starting production server...');
8+
execSync('node dist/index.js', { stdio: 'inherit' });
9+
}

src/script/publish.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { execSync } from 'child_process';
2+
3+
/**
4+
* Bump version, run format/lint/build, then publish
5+
* @param bumpType one of 'patch' | 'minor' | 'major' (default: patch)
6+
* @param tag optional npm tag (e.g., 'beta')
7+
*/
8+
function publishWithVersionBump(bumpType = 'patch', tag?: string) {
9+
console.log(`Bumping version (${bumpType})...`);
10+
execSync(`npm version ${bumpType}`, { stdio: 'inherit' });
11+
12+
console.log('Running prepublish tasks: format, lint, build');
13+
execSync('pnpm run format && pnpm run lint && pnpm run build', { stdio: 'inherit' });
14+
15+
const publishCmd = tag
16+
? `npm publish --access public --tag ${tag}`
17+
: 'npm publish --access public';
18+
19+
console.log(`Publishing${tag ? ` with tag "${tag}"` : ''} to npm...`);
20+
execSync(publishCmd, { stdio: 'inherit' });
21+
}
22+
23+
export function publish() {
24+
publishWithVersionBump('patch');
25+
}
26+
27+
export function publishBeta() {
28+
publishWithVersionBump('patch', 'beta');
29+
}

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import {} from '@nexgenstudiodev/fastkit'

tsconfig.json

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
{
22
"compilerOptions": {
3-
"target": "es2016",
4-
"module": "commonjs",
5-
"rootDir": "./src",
6-
"outDir": "./dist",
7-
"esModuleInterop": true,
8-
"forceConsistentCasingInFileNames": true,
9-
"strict": true,
10-
"skipLibCheck": true
3+
"target": "ES2019",
4+
"module": "CommonJS", // Compile to CommonJS
5+
"declaration": true, // Emit .d.ts files for types
6+
"esModuleInterop": true, // Allow default import from CJS
7+
"outDir": "dist",
8+
"rootDir": "src",
119
},
12-
"paths": {
13-
"@fastkit/constant": ["src/constant/FastKit.constant.ts"],
14-
"@fastkit/setup": ["src/FastKit.ts"],
15-
16-
},
17-
"include": [
18-
"src/**/*"
19-
],
10+
"include": ["src/**/*"],
2011
"exclude": [
2112
"node_modules",
2213
"dist",
14+
"test.js",
15+
"test.ts",
16+
"src/script/*.ts",
2317
"src/**/*.test.ts",
24-
"src/**/*.spec.ts"
18+
"src/**/*.spec.ts",
19+
"src/**/__test__/**"
2520
]
26-
}
21+
22+
}

0 commit comments

Comments
 (0)