Skip to content

Commit

Permalink
feat: publish subpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Mar 22, 2023
1 parent 47e357a commit d33cb3c
Show file tree
Hide file tree
Showing 5 changed files with 539 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
# === `master` branch ===
- name: Publish to NPM
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/feat/new-editor'
run: npm publish
run: npm publish ./dist
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

Expand Down
50 changes: 50 additions & 0 deletions bin/post-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'path'
import fsExtra from 'fs-extra'

const { resolve, join, basename } = path
const { readFile, writeFile, copy } = fsExtra
const packagePath = process.cwd()
const distPath = join(packagePath, './dist')

const writeJson = (targetPath: string, obj: any) =>
writeFile(targetPath, JSON.stringify(obj, null, 2), 'utf8')

async function createPackageFile() {
const packageData = await readFile(
resolve(packagePath, './package.json'),
'utf8'
)
const { scripts, devDependencies, ...packageOthers } = JSON.parse(packageData)
const newPackageData = {
...packageOthers,
private: false,
typings: './index.d.ts',
main: './cjs/index.js',
module: './index.js',
}

const targetPath = resolve(distPath, './package.json')

await writeJson(targetPath, newPackageData)
console.log(`Created package.json in ${targetPath}`)
}

async function includeFileInBuild(file: string) {
const sourcePath = resolve(packagePath, file)
const targetPath = resolve(distPath, basename(file))
await copy(sourcePath, targetPath)
console.log(`Copied ${sourcePath} to ${targetPath}`)
}

async function run() {
try {
await createPackageFile()
await includeFileInBuild('./README.md')
// await includeFileInBuild('../../LICENSE');
} catch (err) {
console.error(err)
process.exit(1)
}
}

run()
Loading

0 comments on commit d33cb3c

Please sign in to comment.