feat: create new cli package

This commit is contained in:
Nicolas Meienberger 2023-08-15 22:48:15 +02:00 committed by Nicolas Meienberger
parent 4faaec3129
commit 8fc132f3d0
11 changed files with 207 additions and 3 deletions

View File

@ -0,0 +1 @@
.eslintrc.js

39
packages/cli/.eslintrc.js Normal file
View File

@ -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,
},
};

4
packages/cli/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
dev
dist/
coverage/
assets/VERSION

View File

@ -0,0 +1,6 @@
module.exports = {
singleQuote: true,
semi: true,
trailingComma: 'all',
printWidth: 200,
};

21
packages/cli/build.js Normal file
View File

@ -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();

View File

@ -0,0 +1,5 @@
{
"watch": ["src"],
"exec": "NODE_ENV=development npx tsx ./src/index.ts watch",
"ext": "js ts"
}

61
packages/cli/package.json Normal file
View File

@ -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"
}
}

View File

@ -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"
]
}

View File

@ -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'] },
},
});

3
pnpm-workspace.yaml Normal file
View File

@ -0,0 +1,3 @@
prefer-workspace-packages: true
packages:
- 'packages/**'

View File

@ -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",
]
}