@lemon-clown/ts-dev-util
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

usage

yarn add --dev @lemon-clown/ts-dev-util
// or
npm install --save-dev @lemon-clown/ts-dev-util

example

build single entry project

// filepath: ./build.ts
import fs from 'fs-extra'
import path from 'path'
import { nodePackageScript } from '@lemon-clown/ts-dev-util'
import manifest from '../package.json'


const appDirectory = fs.realpathSync(process.cwd())
export const resolvePath = (...relativePath: string[]) => {
  return path.normalize(path.resolve(appDirectory, ...relativePath))
}


// paths Option.
// see [Paths](https://github.com/lemon-clown/node-ts-dev-util/blob/master/src/script/node-package/paths.ts) to get more information.
const paths: nodePackageScript.Paths = {
  name: manifest.name,
  // source file config
  source: {
    root: appDirectory,
    src: resolvePath('src'),
    main: resolvePath('src', 'index.ts'),
    tslint: resolvePath('tslint.json'),       // optional
    manifest: resolvePath('package.json'),
    tsconfig: resolvePath('tsconfig.json'),
    lockFile: resolvePath('yarn.lock'),
    nodeModules: [ resolvePath('node_modules') ],
  },
  // output config
  target: {
    root: resolvePath('lib'),
    typesRoot: resolvePath('types'),
    typesMain: resolvePath('types', 'index.d.ts'),
  },
  externals: nodePackageScript.calcExternals(manifest.dependencies),
  modulePrefix: 'ts-demo/lib',
  // to resolve path-alias which defined in tsconfig (compilerOptions.paths)
  alias: {
    '@': appDirectory,
  }
}

// run build script
// see [BuildOption](https://github.com/lemon-clown/node-ts-dev-util/blob/master/src/script/node-module/build.ts) to get more information
nodePackageScript.build({
  paths,
  fullMessage: true,
  // handle typescript paths here
  resolveModuleImport: params => {
    const { importedModuleId } = params
    if (/^\./.test(importedModuleId)) return null
    if (/^@\//.test(importedModuleId)) {
      return `lib/${ importedModuleId.substring(2) }`
    }
    return importedModuleId
  }
})

Readme

Keywords

none

Package Sidebar

Install

npm i @lemon-clown/ts-dev-util

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

175 kB

Total Files

6

Last publish

Collaborators

  • lemonclown
  • lemon-clown-owner