diff --git a/Makefile b/Makefile index 85c332194..f493c24e9 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ dist: $(git-archive-all) \ --include ./configure \ --include ./packages/taler-wallet-cli/configure \ + --include ./packages/anastasis-cli/configure \ --include ./packages/demobank-ui/configure \ --include ./packages/taler-harness/configure \ --include ./packages/merchant-backoffice-ui/configure \ @@ -121,15 +122,17 @@ install: pnpm install --frozen-lockfile pnpm run compile make -C packages/taler-wallet-cli TOPLEVEL=yes install-nodeps + make -C packages/anastasis-cli TOPLEVEL=yes install-nodeps make -C packages/taler-harness TOPLEVEL=yes install-nodeps make -C packages/demobank-ui TOPLEVEL=yes install-nodeps make -C packages/merchant-backoffice-ui TOPLEVEL=yes install-nodeps make -C packages/aml-backoffice-ui TOPLEVEL=yes install-nodeps .PHONY: install-tools -# Install taler-wallet-cli and taler-harness +# Install taler-wallet-cli, anastasis-cli and taler-harness install-tools: - pnpm install --frozen-lockfile --filter @gnu-taler/taler-wallet-cli... --filter @gnu-taler/taler-harness... - pnpm run --filter @gnu-taler/taler-wallet-cli... --filter @gnu-taler/taler-harness... compile + pnpm install --frozen-lockfile --filter @gnu-taler/taler-wallet-cli... --filder @gnu-taler/anastasis-cli... --filter @gnu-taler/taler-harness... + pnpm run --filter @gnu-taler/taler-wallet-cli... --filter @gnu-taler/anastasis-cli... --filter @gnu-taler/taler-harness... compile make -C packages/taler-wallet-cli TOPLEVEL=yes install-nodeps + make -C packages/anastasis-cli TOPLEVEL=yes install-nodeps make -C packages/taler-harness TOPLEVEL=yes install-nodeps diff --git a/bootstrap b/bootstrap index d5e3838d6..4b03f0921 100755 --- a/bootstrap +++ b/bootstrap @@ -27,6 +27,7 @@ copy_configure() { our_configure=build-system/taler-build-scripts/configure copy_configure "$our_configure" ./configure copy_configure "$our_configure" ./packages/taler-wallet-cli/configure +copy_configure "$our_configure" ./packages/anastasis-cli/configure copy_configure "$our_configure" ./packages/demobank-ui/configure copy_configure "$our_configure" ./packages/merchant-backoffice-ui/configure copy_configure "$our_configure" ./packages/taler-harness/configure 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 + */ + +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 + */ + +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 similarity index 97% rename from packages/anastasis-core/src/cli.ts rename to 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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 45b11cf08..d9d1a2fa3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -112,6 +112,34 @@ importers: specifier: 5.1.3 version: 5.1.3 + packages/anastasis-cli: + dependencies: + '@gnu-taler/anastasis-core': + specifier: workspace:* + version: link:../anastasis-core + '@gnu-taler/taler-util': + specifier: workspace:* + version: link:../taler-util + tslib: + specifier: ^2.5.3 + version: 2.5.3 + devDependencies: + '@types/node': + specifier: ^18.11.17 + version: 18.11.17 + prettier: + specifier: ^2.8.8 + version: 2.8.8 + rimraf: + specifier: ^3.0.2 + version: 3.0.2 + typedoc: + specifier: ^0.24.8 + version: 0.24.8(typescript@5.1.3) + typescript: + specifier: ^5.1.3 + version: 5.1.3 + packages/anastasis-core: dependencies: '@gnu-taler/taler-util': @@ -6295,7 +6323,7 @@ packages: engines: {node: '>=14.15.0'} dependencies: js-yaml: 3.14.1 - tslib: 2.4.1 + tslib: 2.5.3 dev: true /@zkochan/js-yaml@0.0.6: @@ -12308,6 +12336,7 @@ packages: /marked@4.3.0: resolution: {integrity: sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==} engines: {node: '>= 12'} + hasBin: true dev: true /matcher@5.0.0: @@ -15089,6 +15118,7 @@ packages: /rimraf@2.7.1: resolution: {integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==} + hasBin: true dependencies: glob: 7.2.3 dev: true @@ -16447,10 +16477,6 @@ packages: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} dev: true - /tslib@2.4.1: - resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==} - dev: true - /tslib@2.5.3: resolution: {integrity: sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==} @@ -16552,6 +16578,7 @@ packages: /typescript@4.6.4: resolution: {integrity: sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==} engines: {node: '>=4.2.0'} + hasBin: true dev: true /typescript@5.1.3: diff --git a/tsconfig.build.json b/tsconfig.build.json index 3a8d2433c..cc6a9ab1e 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -21,6 +21,9 @@ }, { "path": "packages/taler-wallet-webextension//" + }, + { + "path": "packages/anastasis-core/" } ], "files": []