diff --git a/packages/cli/.eslintignore b/packages/cli/.eslintignore new file mode 100644 index 00000000..a9ba028c --- /dev/null +++ b/packages/cli/.eslintignore @@ -0,0 +1 @@ +.eslintrc.js diff --git a/packages/cli/.eslintrc.js b/packages/cli/.eslintrc.js new file mode 100644 index 00000000..13f66352 --- /dev/null +++ b/packages/cli/.eslintrc.js @@ -0,0 +1,39 @@ +module.exports = { + root: true, + plugins: ['@typescript-eslint', 'import'], + extends: ['plugin:@typescript-eslint/recommended', 'airbnb', 'airbnb-typescript', 'eslint:recommended', 'plugin:import/typescript', 'prettier'], + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + tsconfigRootDir: __dirname, + }, + rules: { + 'import/prefer-default-export': 0, + 'class-methods-use-this': 0, + 'import/extensions': [ + 'error', + 'ignorePackages', + { + '': 'never', + js: 'never', + jsx: 'never', + ts: 'never', + tsx: 'never', + }, + ], + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: ['build.js', '**/*.test.{ts,tsx}', '**/mocks/**', '**/__mocks__/**', '**/*.setup.{ts,js}', '**/*.config.{ts,js}', '**/tests/**'], + }, + ], + 'arrow-body-style': 0, + 'no-underscore-dangle': 0, + 'no-console': 0, + }, + globals: { + NodeJS: true, + }, +}; diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore new file mode 100644 index 00000000..32d1b901 --- /dev/null +++ b/packages/cli/.gitignore @@ -0,0 +1,4 @@ +dev +dist/ +coverage/ +assets/VERSION diff --git a/packages/cli/.prettierrc.js b/packages/cli/.prettierrc.js new file mode 100644 index 00000000..18502e8f --- /dev/null +++ b/packages/cli/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + singleQuote: true, + semi: true, + trailingComma: 'all', + printWidth: 200, +}; diff --git a/packages/cli/build.js b/packages/cli/build.js new file mode 100644 index 00000000..102a666b --- /dev/null +++ b/packages/cli/build.js @@ -0,0 +1,21 @@ +const { build } = require('esbuild'); + +const commandArgs = process.argv.slice(2); + +async function bundle() { + const start = Date.now(); + const options = { + entryPoints: ['./src/index.ts'], + outfile: './dist/index.js', + platform: 'node', + target: 'node20', + bundle: true, + color: true, + sourcemap: commandArgs.includes('--sourcemap'), + }; + + await build({ ...options, minify: true }); + console.log(`Build time: ${Date.now() - start}ms`); +} + +bundle(); diff --git a/packages/cli/nodemon.json b/packages/cli/nodemon.json new file mode 100644 index 00000000..d6268126 --- /dev/null +++ b/packages/cli/nodemon.json @@ -0,0 +1,5 @@ +{ + "watch": ["src"], + "exec": "NODE_ENV=development npx tsx ./src/index.ts watch", + "ext": "js ts" +} diff --git a/packages/cli/package.json b/packages/cli/package.json new file mode 100644 index 00000000..a5a1b401 --- /dev/null +++ b/packages/cli/package.json @@ -0,0 +1,61 @@ +{ + "name": "@runtipi/cli", + "version": "1.6.0", + "description": "", + "main": "index.js", + "bin": "dist/index.js", + "scripts": { + "test": "dotenv -e .env.test vitest -- --coverage --watch=false", + "test:watch": "dotenv -e .env.test vitest", + "package": "npm run build && pkg package.json && chmod +x dist/bin/cli-x64 && chmod +x dist/bin/cli-arm64", + "package:m1": "npm run build && pkg package.json -t node18-darwin-arm64", + "set-version": "node -e \"require('fs').writeFileSync('assets/VERSION', process.argv[1])\"", + "build": "node build.js", + "build:meta": "esbuild ./src/index.ts --bundle --platform=node --target=node18 --outfile=dist/index.js --metafile=meta.json --analyze", + "dev": "dotenv -e ../../.env nodemon", + "lint": "eslint . --ext .ts" + }, + "pkg": { + "assets": "assets/**/*", + "targets": [ + "node18-linux-x64", + "node18-linux-arm64" + ], + "outputPath": "dist/bin" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@faker-js/faker": "^8.0.2", + "@types/cli-progress": "^3.11.0", + "@types/inquirer": "^9.0.3", + "@types/node": "20.3.2", + "dotenv-cli": "^7.2.1", + "esbuild": "^0.16.17", + "eslint-config-prettier": "^8.8.0", + "memfs": "^4.2.0", + "nodemon": "^2.0.22", + "pkg": "^5.8.1", + "vite": "^4.4.7", + "vite-tsconfig-paths": "^4.2.0", + "vitest": "^0.32.2" + }, + "dependencies": { + "@runtipi/shared": "workspace:^", + "axios": "^1.4.0", + "boxen": "^7.1.1", + "bullmq": "^4.5.0", + "chalk": "^5.3.0", + "cli-progress": "^3.12.0", + "cli-spinners": "^2.9.0", + "commander": "^11.0.0", + "dotenv": "^16.3.1", + "inquirer": "^9.2.8", + "log-update": "^5.0.1", + "semver": "^7.5.3", + "systeminformation": "^5.18.7", + "web-push": "^3.6.3", + "zod": "^3.21.4" + } +} diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json new file mode 100644 index 00000000..96bf6ea5 --- /dev/null +++ b/packages/cli/tsconfig.json @@ -0,0 +1,52 @@ +{ + "compilerOptions": { + "target": "es2017", + "baseUrl": ".", + "outDir": "./dist", + "paths": { + "@/utils/*": [ + "./src/utils/*" + ], + "@/executors": [ + "./src/executors" + ], + "@/tests/*": [ + "./tests/*" + ], + }, + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "CommonJS", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "strictNullChecks": true, + "allowSyntheticDefaultImports": true, + "noUncheckedIndexedAccess": true, + "types": [ + "node" + ], + "experimentalDecorators": true + }, + "include": [ + "**/*.ts", + "**/*.tsx", + "**/*.mjs", + "**/*.js", + "**/*.jsx" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/packages/cli/vitest.config.ts b/packages/cli/vitest.config.ts new file mode 100644 index 00000000..e623d863 --- /dev/null +++ b/packages/cli/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; +import tsconfigPaths from 'vite-tsconfig-paths'; + +export default defineConfig({ + plugins: [tsconfigPaths()], + test: { + setupFiles: ['./tests/vite.setup.ts'], + coverage: { all: true, reporter: ['lcov', 'text-summary'] }, + }, +}); diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 00000000..a6fd963c --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +prefer-workspace-packages: true +packages: + - 'packages/**' diff --git a/tsconfig.json b/tsconfig.json index f67613df..f7c28c19 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -38,7 +38,7 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", - "incremental": true, + "incremental": false, "strictNullChecks": true, "allowSyntheticDefaultImports": true, "noUncheckedIndexedAccess": true, @@ -54,9 +54,11 @@ "**/*.tsx", "**/*.mjs", "**/*.js", - "**/*.jsx" + "**/*.jsx", ], "exclude": [ - "node_modules" + "node_modules", + "packages", + "repos", ] }