Skip to content

Commit

Permalink
Merge pull request #3 from FriendlyCaptcha/ship-dist-folder
Browse files Browse the repository at this point in the history
Publish from dist folder
  • Loading branch information
gzuidhof authored Dec 12, 2023
2 parents 8d215a2 + 10c1db3 commit 6d5739e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- run: npm ci
- run: npm run build:dist
- run: npm test
- run: npm publish --access public
- run: npm run dist
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# changelog

## 0.0.1
**Date**: 2023-TODO
## 0.1.1
**Date**: 2023-12-12

* Library and built script files are no longer in the `dist` folder, so you can remove `/dist` from import/script paths.

## 0.1.0
**Date**: 2023-12-08

Initial release.
1 change: 1 addition & 0 deletions license-checker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"build/",
"node_modules/",
"temp/",
".github/",

"**/*.html",
"**/*.md",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@friendlycaptcha/sdk",
"version": "0.1.0",
"version": "0.1.1",
"description": "In-browser SDK for Friendly Captcha v2 (currently in preview only)",
"main": "dist/sdk.js",
"type": "module",
"private": true,
"scripts": {
"clean": "rm -rf dist build temp",
"build": "./build.sh",
"build:tsc": "tsc",
"build:dist": "npm run build && npm run build:tsc && npm run build:dts && cp -r build/tsc/src/ dist/src && npm run build:apiextractor && npm run build:docs",
Expand All @@ -15,7 +17,9 @@
"test": "ava test/**/*.ts --timeout=1m",
"api-extractor": "api-extractor",
"license-check-and-add": "license-check-and-add",
"fmt": "prettier src/**/*.ts test/**/*.ts package.json babel.config.cjs --write"
"fmt": "prettier src/**/*.ts test/**/*.ts package.json babel.config.cjs --write",
"dist": "npm run clean && npm run build:dist && node prepublish.mjs && cd dist && npm publish",
"prepublishOnly": "echo \"Run npm run dist to build the package and publish it\" && exit 1"
},
"author": "Friendly Captcha GmbH",
"license": "MPL-2.0",
Expand Down
34 changes: 34 additions & 0 deletions prepublish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* Copyright (c) Friendly Captcha GmbH 2023.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import fs from "fs";
import filepath from "path";

// This script is run before publishing to npm, it copies some files into the dist folder and copies a slimmed down version of package.json
// into that folder too, along with some readme files. This is so that we can only publish the contents of the dist folder to npm, that way
// we don't have `/dist/` in any import paths.

(() => {
const source = fs.readFileSync("package.json").toString("utf-8");
const pkg = JSON.parse(source);
delete pkg.scripts;
delete pkg.devDependencies;
delete pkg.files;
delete pkg.ava;
delete pkg.private;
if (pkg.main.startsWith("dist/")) {
pkg.main = pkg.main.slice(5);
}

const outFolder = "dist";

for (const file of ["LICENSE.md", "README.md", "CHANGELOG.md"]) {
fs.copyFileSync(file, filepath.join(outFolder, file));
}

fs.writeFileSync(filepath.join(outFolder, "/package.json"), Buffer.from(JSON.stringify(pkg, null, 2), "utf-8"));
fs.writeFileSync(filepath.join(outFolder, "/version.txt"), Buffer.from(pkg.version, "utf-8")); // Useful for CI/CD tagging of version.
})();

0 comments on commit 6d5739e

Please sign in to comment.