Skip to content

Commit

Permalink
chore: release to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
asdofindia committed Oct 23, 2023
1 parent 7a049e1 commit 676b88a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
- name: Build
run: |
node scripts/build.js
node scripts/build.js ${{ github.run_id }}
- uses: ncipollo/release-action@v1
with:
artifacts: "build/raw/*"
tag: v1.0.${{ github.run_id }}
- name: npm publish
working-directory: build/npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

34 changes: 32 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const fs = require('fs');
const path = require('path');

const version = process.argv[2];

const mkdir = (f) => fs.mkdirSync(f, { recursive: true })

const scriptDir = __dirname;
const mapsFolder = path.join(scriptDir, '..', "maps");
const buildFolder = path.join(scriptDir, '..', "build");
Expand All @@ -21,5 +25,31 @@ files.forEach((file) => {
atlas[fontName] = fontMap;
});
const jsBuildPath = path.join(buildRawFolder, 'unicode-conversion-maps.mjs');
fs.mkdirSync(buildRawFolder, { recursive: true })
fs.writeFileSync(jsBuildPath, `export default ${JSON.stringify(atlas, null, 0)};`)
mkdir(buildRawFolder);
fs.writeFileSync(jsBuildPath, `export default ${JSON.stringify(atlas, null, 0)};`)

const npmFolder = path.join(buildFolder, "npm");
mkdir(npmFolder);

const npmReadme = path.join(npmFolder, 'README.md')
fs.writeFileSync(npmReadme, `# Unicode Conversion Maps
Install with \`npm install @indicjs/unicode-conversion-maps\`
Then use it like this:
\`\`\`javascript
import maps from '@indicjs/unicode-conversion-maps'
console.log(maps["revathi"]["A"]) // prints അ
\`\`\`
`)

const npmPackageJson = path.join(npmFolder, 'package.json');
fs.writeFileSync(npmPackageJson, `{
"name": "@indicjs/unicode-conversion-maps",
"version": "1.0.${version}",
"homepage": "https://github.com/libindic/unicode-conversion-maps",
"main": "unicode-conversion-maps.mjs",
"type": "module"
}`)

fs.copyFileSync(jsBuildPath, path.join(npmFolder, "unicode-conversion-maps.mjs"))

0 comments on commit 676b88a

Please sign in to comment.