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