@lemon-clown/ts-dev-util
typescript develop utils
Last updated 4 months ago by lemonclown .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @lemon-clown/ts-dev-util 
SYNC missed versions from official npm registry.

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
  }
})

Current Tags

  • 0.0.2                                ...           latest (4 months ago)

1 Versions

  • 0.0.2                                ...           4 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |