Skip to content

Commit

Permalink
feat: symlink dist/package.json -> package.json when running serve (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
lguychard committed Jan 7, 2019
1 parent 6c1af45 commit 0fd5e11
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ async function main(): Promise<void> {
tslint: "tslint -p tsconfig.json './src/**/*.ts'",
typecheck: 'tsc -p tsconfig.json',
build: `parcel build --out-file dist/${name}.js src/${name}.ts`,
serve: `parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
'symlink-package': 'node dev/symlinkPackage.js',
serve: `npm run symlink-package && parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
'watch:typecheck': 'tsc -p tsconfig.json -w',
'watch:build': 'tsc -p tsconfig.dist.json -w',
'sourcegraph:prepublish': 'npm run build',
Expand All @@ -200,6 +201,25 @@ async function main(): Promise<void> {
await writeFile('package.json', JSON.stringify(packageJson, null, 2))
}

console.log('📂 Creating dev directory')
await mkdir('dev')
await writeFile('dev/symlinkPackage.js', [
"const createSymlink = require('create-symlink')",
"const { existsSync } = require('fs')",
"const mkdirp = require('mkdirp-promise')",
"const { resolve } = require('path')",
'',
"mkdirp('dist').then(async () => {",
" if (!existsSync('./dist/package.json')) {",
" await createSymlink(resolve('./package.json'), resolve('./dist/package.json'))",
' }',
' process.exit(0)',
'}).catch(err => {',
' console.error(err)',
' process.exit(1)',
'})',
].join('\n'))

try {
console.log('📂 Creating src directory')
await mkdir('src')
Expand Down Expand Up @@ -243,6 +263,8 @@ async function main(): Promise<void> {
'tslint',
'@sourcegraph/tslint-config',
'@sourcegraph/tsconfig',
'create-symlink',
'mkdirp-promise',
],
{ stdio: 'inherit' }
)
Expand Down

0 comments on commit 0fd5e11

Please sign in to comment.