feat(npm): Build and publish NPM package (#43)

This commit is contained in:
Steven Noorbergen
2024-05-05 16:35:22 +02:00
committed by GitHub
parent cfe3da0aed
commit abc6b132a8
10 changed files with 207 additions and 3 deletions

2
.editorconfig Normal file
View File

@@ -0,0 +1,2 @@
[*]
max_line_length=120

2
.eslintignore Normal file
View File

@@ -0,0 +1,2 @@
dist/
node_modules/

29
.eslintrc.js Normal file
View File

@@ -0,0 +1,29 @@
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
],
plugins: ["@typescript-eslint", "import", "prettier"],
rules: {
"newline-per-chained-call": "off",
},
parserOptions: {
project: "./tsconfig.json",
},
ignorePatterns: [],
overrides: [
{
// The files listed below are part of the build process, so they will be using packages that are listed
// under devDependences and/or peerDependencies, so we need to be lenient with the import/no-extraneous-dependencies
files: [".eslintrc.js", "rollup.config.mjs"],
rules: {
"import/no-extraneous-dependencies": ["error", { peerDependencies: true, devDependencies: true }],
},
},
],
};

View File

@@ -14,11 +14,27 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install NodeJS
uses: actions/setup-node@v4
with:
registry-url: https://npm.pkg.github.com
scope: "@eveshipfit"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set version
run: |
# Remove the "v" from the version.
VERSION=$(echo ${{ github.ref_name }} | cut -b2-)
echo "Version: ${VERSION}"
sed -i 's/"version": "0.0.0-git"/"version": "'${VERSION}'"/' package.json
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y --no-install-recommends rclone protobuf-compiler
pip install -r requirements.txt
npm install
- name: Setup rclone
run: |
@@ -63,9 +79,20 @@ jobs:
run: |
python download_icons.py sde/fsd
- name: Build package
run: |
npm run build
- name: Publish package
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
registry: "https://npm.pkg.github.com"
package: package.json
- name: Publish to R2 bucket
run: |
rclone copy dist eveshipfit:eveshipfit/${{ github.event.release.tag_name }}/ --progress
rclone copy dist eveshipfit:eveshipfit/${{ github.event.release.tag_name }}/ --progress --exclude=*.{js,js.map,d.ts}
env:
RCLONE_CONFIG_EVESHIPFIT_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
RCLONE_CONFIG_EVESHIPFIT_ENDPOINT: ${{ secrets.R2_ENDPOINT }}

32
.github/workflows/testing.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: Testing
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
testing:
name: Testing
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install NodeJS
uses: actions/setup-node@v4
with:
registry-url: https://npm.pkg.github.com
scope: "@eveshipfit"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: npm install
- name: Run linter
run: npm run lint

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
@eveshipfit:registry=https://npm.pkg.github.com

View File

@@ -1,5 +1,42 @@
{
"dependencies": {
"protobufjs-cli": "^1.1.2"
"name": "@eveshipfit/data",
"publishConfig": {
"registry": "https://npm.pkg.github.com/EVEShipFit"
},
"version": "0.0.0-git",
"description": "Converted data from the EVE Online SDE",
"scripts": {
"build": "rollup -c",
"lint": "eslint src --ext .js,.ts --cache && prettier -c src",
"prettier": "prettier -w src"
},
"repository": {
"type": "git",
"url": "git+https://github.com/EVEShipFit/data.git"
},
"author": "Patric Stout <eveshipfit@truebrain.nl>",
"license": "SEE LICENSE IN LICENSE",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"files": [
"dist"
],
"types": "dist/index.d.ts",
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"protobufjs-cli": "^1.1.2",
"rollup": "^4.4.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.0",
"rollup-plugin-node-externals": "^7.0.1",
"typescript": "^5.2.2"
}
}

53
rollup.config.mjs Normal file
View File

@@ -0,0 +1,53 @@
import commonjs from "@rollup/plugin-commonjs";
import dts from "rollup-plugin-dts";
import esbuild from "rollup-plugin-esbuild";
import nodeExternals from "rollup-plugin-node-externals";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import replace from "@rollup/plugin-replace";
import { readFileSync } from "fs";
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
export default [
{
input: "src/index.ts",
output: [
{
file: "dist/cjs/index.js",
format: "cjs",
sourcemap: true,
},
{
file: "dist/esm/index.js",
format: "esm",
sourcemap: true,
},
],
plugins: [
replace({
preventAssignment: true,
values: {
"process.env.VERSION": JSON.stringify(packageJson.version),
"process.env.BUILD_TIME": JSON.stringify(new Date().toISOString()),
},
}),
nodeExternals(),
nodeResolve(),
commonjs(),
esbuild({ tsconfig: "./tsconfig.json" }),
terser(),
],
},
{
input: "src/index.ts",
output: [
{
file: "dist/index.d.ts",
format: "esm",
},
],
plugins: [dts({ tsconfig: "./tsconfig.json" })],
},
];

2
src/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export const ESF_DATA_VERSION = process.env.VERSION as string;
export const ESF_DATA_BUILD_TIME = process.env.BUILD_TIME as string;

19
tsconfig.json Normal file
View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "dist/types",
"emitDeclarationOnly": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "node",
"outDir": "dist",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es2016"
},
"include": ["src/**/*.ts", "src/**/*.d.ts"],
"exclude": ["node_modules"]
}