pkg-typescript
v0.7.0
Published
[](https://badge.fury.io/js/pkg-typescript) [](https://opensource.org/licenses/ISC) [
yarn add -D pkg-typescript
# Using npm
npm install --save-dev pkg-typescript📖 Quick Start
- Create a
package.tsfile in your project root:
import { PackageConfig } from 'pkg-typescript'
const config: PackageConfig = {
name: 'my-awesome-package',
version: '1.0.0',
scripts: {
dev: 'vite dev',
build: 'vite build',
pre: {
build: 'echo "Starting build..."',
},
post: {
build: 'echo "Build complete!"',
},
},
dependencies: {
react: [18, 0, 0],
lodash: ['github', 'lodash/lodash'],
},
devDependencies: {
typescript: [5, 0, 0],
vite: [4, 0, 0],
},
}
export default config- Generate your
package.json:
npx pkg-ts build🛠️ CLI Commands
pkg-ts build
Generate package.json from your TypeScript configuration:
# Build single package
pkg-ts build
# Build specific package file
pkg-ts build --config my-package.ts
# Build all packages in directory
pkg-ts build --allpkg-ts sync
Sync version between package.json and your TypeScript config:
# Sync version from package.json to package.ts
pkg-ts sync
# Sync specific config file
pkg-ts sync --config my-package.tspkg-ts add-plugin
Add a plugin to your package configuration:
pkg-ts add-plugin my-pluginpkg-ts update
Update package configurations:
pkg-ts update📋 Configuration
PackageConfig Interface
The PackageConfig interface provides full type safety for your package configuration:
export type PackageConfig<T = any> = {
name: string
version: string
license?: string
type?: 'plugin'
plugins?: string[]
private?: boolean
scripts: {
dev?: string
build?: string
start?: string
pre?: PreScripts
post?: PostScripts
[key: string]: string | undefined | PreScripts | PostScripts
}
dependencies?: Record<string, Dependency>
devDependencies?: Record<string, Dependency>
config?: T
}Dependency Types
Define dependencies using semantic versioning arrays or GitHub sources:
// Semantic version [major, minor, patch]
dependencies: {
'react': [18, 2, 0],
'lodash': [4, 17, 21]
}
// GitHub source
dependencies: {
'my-package': ['github', 'username/repo']
}
// Latest version
dependencies: {
'some-package': 1
}Pre/Post Scripts
Define scripts that run before or after main scripts:
scripts: {
build: 'webpack build',
pre: {
build: 'rm -rf dist',
version: 'npm run test'
},
post: {
build: 'npm run deploy',
version: 'git push --tags'
}
}🧩 Plugin System
Create reusable plugins to extend functionality:
// my-plugin.ts
import { PluginFunction } from 'pkg-typescript'
interface MyPluginConfig {
feature: boolean
}
const myPlugin: PluginFunction<MyPluginConfig> = (config) => {
return {
scripts: {
'my-command': 'echo "Plugin command"',
},
dependencies: {
'plugin-dep': [1, 0, 0],
},
}
}
export default myPluginUse plugins in your package configuration:
import myPlugin from './my-plugin'
const config: PackageConfig = {
name: 'my-package',
version: '1.0.0',
plugins: ['my-plugin'],
// ... rest of config
}🔌 Available Plugins
Extend pkg-ts functionality with these official plugins:
🚀 Next.js Plugin
Pre-configured setup for Next.js applications with optimized scripts and dependencies.
💅 Prettier Plugin
Automatic code formatting configuration with Prettier integration.
🗄️ Prisma Plugin
Database toolkit integration with Prisma ORM setup and scripts.
🗄️ Mantine Plugin
Mantine UI library integration with Mantine UI setup and scripts.
⚙️ Scripts Plugin
Scripts integration with scripts setup and scripts.
Using Plugins
Install and use plugins in your package configuration:
npx pkg-ts add-plugin prisma
npx pkg-ts add-plugin prettierimport { PackageConfig } from 'pkg-typescript'
import nextjsPlugin from 'pkg-ts-plugin-nextjs'
const config: PackageConfig = {
name: 'my-nextjs-app',
version: '1.0.0',
plugins: ['pkg-ts-plugin-nextjs'],
// Plugin configuration will be automatically applied
}
export default config🎯 Use Cases
- Monorepos: Manage multiple packages with shared configuration
- Type Safety: Catch configuration errors at compile time
- Plugin Development: Create reusable package configurations
- CI/CD: Automate package.json generation in build pipelines
- Team Collaboration: Share typed package configurations
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m '✨ add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the ISC License - see the LICENSE file for details.
🔗 Links
Made with ❤️ and TypeScript
