From 0b26c00c2ba4372705fcbefdb194c870ca230a39 Mon Sep 17 00:00:00 2001 From: Armin Jazi Date: Tue, 11 Jun 2024 15:53:14 +0200 Subject: [PATCH] add build and publish scripts --- .../workflows/npm-publish-github-packages.yml | 44 +++++++++++++++++++ .gitlab-ci.yml | 41 ----------------- package.json | 16 ++++++- src/core/index.ts | 5 +++ tsconfig.lib.json | 25 +++++++++++ vite.config.ts | 10 ++++- 6 files changed, 97 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/npm-publish-github-packages.yml delete mode 100644 .gitlab-ci.yml create mode 100644 tsconfig.lib.json diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..d26fde3 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,44 @@ +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + - run: npm ci + - run: npm run test:unit + - run: npm run build + - run: npm run build:types + - uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: dist + + publish-gpr: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + registry-url: https://npm.pkg.github.com/ + scope: '@openreplyde' + - run: npm ci + - uses: actions/download-artifact@v3 + with: + name: build-artifacts + path: dist + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 72f41c3..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,41 +0,0 @@ -stages: - - test - - publish - -test-job: - image: node:16.14.2 - stage: test - cache: - key: npm - policy: pull-push - paths: - - .npm/ - script: - - npm ci - - npm run lint - - npm run test:unit - - npm run build - artifacts: - paths: - - node_modules/ - - dist/ - expire_in: 1 days - tags: - - infra-cicd - -publish-job: - image: node:16.14.2 - stage: publish - only: - - /^release\/*/ - cache: - key: npm - policy: pull-push - paths: - - .npm/ - script: - - echo "//registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}">.npmrc - - npm publish - tags: - - infra-cicd - diff --git a/package.json b/package.json index 9b53a07..7aaa12d 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,23 @@ { "name": "@openreply/query-cache", - "private": true, - "version": "0.0.0", + "version": "1.0.0-alpha.1", "type": "module", + "files": [ + "dist" + ], + "main": "./dist/index.umd.js", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.umd.cjs" + } + }, "scripts": { "dev:app": "vite --host", "build": "tsc && vite build", + "build:types": "tsc --emitDeclarationOnly --declaration --declarationMap --project ./tsconfig.lib.json", "preview": "vite preview", "lint": "eslint --ext .js,.ts", "test:unit": "vitest", diff --git a/src/core/index.ts b/src/core/index.ts index 009beb5..c1bbc8d 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,4 +1,7 @@ import GlobalSyncEvent, { GlobalSyncEventType } from "~/core/global-sync-event"; +import useQuery from "~/core/use-query"; +import { DefaultCache } from "~/core/default-cache"; +import { DefaultCacheSync } from "~/core/default-cache-sync"; declare global { interface WindowEventMap { @@ -6,3 +9,5 @@ declare global { } } +export { GlobalSyncEvent, GlobalSyncEventType, useQuery, DefaultCache, DefaultCacheSync }; + diff --git a/tsconfig.lib.json b/tsconfig.lib.json new file mode 100644 index 0000000..800baae --- /dev/null +++ b/tsconfig.lib.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "allowJs": true, + "target": "ESNext", + "useDefineForClassFields": true, + "module": "ESNext", + "moduleResolution": "Node", + "noImplicitAny": true, + "declaration": true, + "strict": true, + "jsx": "preserve", + "sourceMap": true, + "resolveJsonModule": true, + "isolatedModules": true, + "esModuleInterop": true, + "lib": ["ESNext", "DOM"], + "skipLibCheck": true, + "outDir": "./dist", + "paths": { + "~/*": ["./src/*"] + } + }, + "include": ["./src/core/**/*"], + "exclude": ["./src/app*", "./src/test-server", "./src/testing", "./src/**/*.spec.ts"] +} diff --git a/vite.config.ts b/vite.config.ts index 0c0ee9c..f768fab 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,8 @@ import { defineConfig } from "vitest/config"; import { fileURLToPath, URL } from "url"; +import { resolve } from "path"; export default defineConfig({ - resolve: { alias: { "~": fileURLToPath(new URL("./src", import.meta.url)), @@ -11,4 +11,12 @@ export default defineConfig({ test: { environment: "happy-dom", }, + build: { + lib: { + entry: resolve(__dirname, "src/core/index.ts"), + name: "CacheQuery", + fileName: "index", + }, + outDir: "dist", + } });