diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-07-03 13:27:44 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-07-26 12:09:17 -0600 |
commit | 5a91ec2da6a63bd31b1f26efaad01b7dc71cd20b (patch) | |
tree | 898d03717ce3bc6be0270c6741ef07472a32cc49 /packages | |
parent | 72a0da7bbed253d86b24a49e1a1e8635b205de68 (diff) | |
download | wallet-core-5a91ec2da6a63bd31b1f26efaad01b7dc71cd20b.tar.xz |
Move anastasis CLI into separate package
Diffstat (limited to 'packages')
-rw-r--r-- | packages/anastasis-cli/Makefile | 41 | ||||
-rw-r--r-- | packages/anastasis-cli/README.md | 4 | ||||
-rwxr-xr-x | packages/anastasis-cli/bin/anastasis-cli.mjs | 20 | ||||
-rwxr-xr-x | packages/anastasis-cli/build-node.mjs | 70 | ||||
-rw-r--r-- | packages/anastasis-cli/package.json | 44 | ||||
-rw-r--r-- | packages/anastasis-cli/src/import-meta-url.js | 2 | ||||
-rw-r--r-- | packages/anastasis-cli/src/index.ts (renamed from packages/anastasis-core/src/cli.ts) | 2 | ||||
-rw-r--r-- | packages/anastasis-cli/tsconfig.json | 33 | ||||
-rw-r--r-- | packages/anastasis-core/src/cli-entry.ts | 7 | ||||
-rw-r--r-- | packages/anastasis-core/src/index.node.ts | 2 | ||||
-rw-r--r-- | packages/taler-util/package.json | 2 |
11 files changed, 216 insertions, 11 deletions
diff --git a/packages/anastasis-cli/Makefile b/packages/anastasis-cli/Makefile new file mode 100644 index 000000000..292f7000f --- /dev/null +++ b/packages/anastasis-cli/Makefile @@ -0,0 +1,41 @@ +# This Makefile has been placed in the public domain. + +ifeq ($(TOPLEVEL), yes) + $(info top-level build) + -include ../../.config.mk +else + $(info package-level build) + -include ../../.config.mk + -include .config.mk +endif + +$(info prefix is $(prefix)) + +all: + @echo use 'make install' to build and install anastasis-cli + +ifndef prefix +.PHONY: warn-noprefix install +warn-noprefix: + @echo "no prefix configured, did you run ./configure?" +install: warn-noprefix +else +install_target = $(prefix)/lib/anastasis-cli +.PHONY: install install-nodeps deps +install-nodeps: + ./build-node.mjs + install -d $(prefix)/bin + install -d $(install_target)/bin + install -d $(install_target)/node_modules/anastasis-cli + install -d $(install_target)/node_modules/anastasis-cli/bin + install -d $(install_target)/node_modules/anastasis-cli/dist + install ./dist/anastasis-cli-bundled.cjs $(install_target)/node_modules/anastasis-cli/dist/ + install ./dist/anastasis-cli-bundled.cjs.map $(install_target)/node_modules/anastasis-cli/dist/ + install ./bin/anastasis-cli.mjs $(install_target)/node_modules/anastasis-cli/bin/ + ln -sf $(install_target)/node_modules/anastasis-cli/bin/anastasis-cli.mjs $(prefix)/bin/anastasis-cli +deps: + pnpm install --frozen-lockfile --filter @gnu-taler/anastasis-cli... +install: + $(MAKE) deps + $(MAKE) install-nodeps +endif diff --git a/packages/anastasis-cli/README.md b/packages/anastasis-cli/README.md new file mode 100644 index 000000000..a48fd3c51 --- /dev/null +++ b/packages/anastasis-cli/README.md @@ -0,0 +1,4 @@ +# anastasis-cli + +This package provides `anastasis-cli`, the command-line interface for the +Anastasis backup system. diff --git a/packages/anastasis-cli/bin/anastasis-cli.mjs b/packages/anastasis-cli/bin/anastasis-cli.mjs new file mode 100755 index 000000000..7506e4ba7 --- /dev/null +++ b/packages/anastasis-cli/bin/anastasis-cli.mjs @@ -0,0 +1,20 @@ +#!/usr/bin/env node +/* + This file is part of GNU Taler + (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { reducerCliMain } from '../dist/anastasis-cli-bundled.cjs'; + +reducerCliMain(); diff --git a/packages/anastasis-cli/build-node.mjs b/packages/anastasis-cli/build-node.mjs new file mode 100755 index 000000000..04b1c5256 --- /dev/null +++ b/packages/anastasis-cli/build-node.mjs @@ -0,0 +1,70 @@ +#!/usr/bin/env node +/* + This file is part of GNU Taler + (C) 2022 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import esbuild from "esbuild"; +import path from "path"; +import fs from "fs"; + +const BASE = process.cwd(); + +let GIT_ROOT = BASE; +while (!fs.existsSync(path.join(GIT_ROOT, ".git")) && GIT_ROOT !== "/") { + GIT_ROOT = path.join(GIT_ROOT, "../"); +} +if (GIT_ROOT === "/") { + console.log("not found"); + process.exit(1); +} +const GIT_HASH = GIT_ROOT === "/" ? undefined : git_hash(); + +let _package = JSON.parse(fs.readFileSync(path.join(BASE, "package.json"))); + +function git_hash() { + const rev = fs + .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) + .toString() + .trim() + .split(/.*[: ]/) + .slice(-1)[0]; + if (rev.indexOf("/") === -1) { + return rev; + } else { + return fs.readFileSync(path.join(GIT_ROOT, ".git", rev)).toString().trim(); + } +} + +export const buildConfig = { + entryPoints: ["src/index.ts"], + outfile: "dist/anastasis-cli-bundled.cjs", + bundle: true, + minify: false, + target: ["es2020"], + format: "cjs", + platform: "node", + sourcemap: true, + inject: ["src/import-meta-url.js"], + define: { + __VERSION__: `"${_package.version}"`, + __GIT_HASH__: `"${GIT_HASH}"`, + ["import.meta.url"]: "import_meta_url", + }, +}; + +esbuild.build(buildConfig).catch((e) => { + console.log(e); + process.exit(1); +}); diff --git a/packages/anastasis-cli/package.json b/packages/anastasis-cli/package.json new file mode 100644 index 000000000..1821cd696 --- /dev/null +++ b/packages/anastasis-cli/package.json @@ -0,0 +1,44 @@ +{ + "name": "@gnu-taler/anastasis-cli", + "version": "0.0.1", + "description": "", + "engines": { + "node": ">=0.18.0" + }, + "repository": { + "type": "git", + "url": "git://git.taler.net/wallet-core.git" + }, + "author": "Florian Dold", + "license": "GPL-3.0", + "bin": { + "anastasis-cli": "./bin/anastasis-cli.mjs" + }, + "type": "module", + "scripts": { + "compile": "tsc --build && ./build-node.mjs", + "test": "tsc", + "clean": "rimraf lib dist tsconfig.tsbuildinfo", + "pretty": "prettier --write src" + }, + "files": [ + "AUTHORS", + "README", + "COPYING", + "bin/", + "dist/node", + "src/" + ], + "devDependencies": { + "@types/node": "^18.11.17", + "prettier": "^2.8.8", + "rimraf": "^3.0.2", + "typedoc": "^0.24.8", + "typescript": "^5.1.3" + }, + "dependencies": { + "@gnu-taler/taler-util": "workspace:*", + "@gnu-taler/anastasis-core": "workspace:*", + "tslib": "^2.5.3" + } +} diff --git a/packages/anastasis-cli/src/import-meta-url.js b/packages/anastasis-cli/src/import-meta-url.js new file mode 100644 index 000000000..c0e657160 --- /dev/null +++ b/packages/anastasis-cli/src/import-meta-url.js @@ -0,0 +1,2 @@ +// Helper to make 'import.meta.url' available in esbuild-bundled code as well. +export const import_meta_url = require("url").pathToFileURL(__filename); diff --git a/packages/anastasis-core/src/cli.ts b/packages/anastasis-cli/src/index.ts index df53d6bd0..560574276 100644 --- a/packages/anastasis-core/src/cli.ts +++ b/packages/anastasis-cli/src/index.ts @@ -3,7 +3,7 @@ import { getBackupStartState, getRecoveryStartState, reduceAction, -} from "./index.js"; +} from "@gnu-taler/anastasis-core"; import fs from "fs"; export const reducerCli = clk diff --git a/packages/anastasis-cli/tsconfig.json b/packages/anastasis-cli/tsconfig.json new file mode 100644 index 000000000..83da34277 --- /dev/null +++ b/packages/anastasis-cli/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "composite": true, + "target": "ES2018", + "module": "ESNext", + "moduleResolution": "Node16", + "sourceMap": true, + "lib": ["es6"], + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "strict": true, + "strictPropertyInitialization": false, + "outDir": "lib", + "noImplicitAny": true, + "noImplicitThis": true, + "incremental": true, + "esModuleInterop": true, + "importHelpers": true, + "rootDir": "src", + "baseUrl": "./src", + "typeRoots": ["./node_modules/@types"] + }, + "include": ["src/**/*"], + "references": [ + { + "path": "../anastasis-core/" + }, + { + "path": "../taler-util/" + } + ] +} diff --git a/packages/anastasis-core/src/cli-entry.ts b/packages/anastasis-core/src/cli-entry.ts deleted file mode 100644 index 8eea42a18..000000000 --- a/packages/anastasis-core/src/cli-entry.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { reducerCliMain } from "./cli.js"; - -async function r() { - reducerCliMain(); -} - -r(); diff --git a/packages/anastasis-core/src/index.node.ts b/packages/anastasis-core/src/index.node.ts deleted file mode 100644 index d08906a22..000000000 --- a/packages/anastasis-core/src/index.node.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./index.js"; -export { reducerCliMain } from "./cli.js"; diff --git a/packages/taler-util/package.json b/packages/taler-util/package.json index b0bfbbaef..73eed814c 100644 --- a/packages/taler-util/package.json +++ b/packages/taler-util/package.json @@ -52,7 +52,7 @@ }, "#argon2-impl": { "node": "./lib/argon2-impl.node.js", - "default": "/lib/argon2-impl.missing.js" + "default": "./lib/argon2-impl.missing.js" } }, "scripts": { |