diff --git a/.npmrc b/.npmrc index d9b4b32..d8b0b35 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ @abearxiong:registry=https://npm.pkg.github.com +//registry.npmjs.org/:_authToken=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 \ No newline at end of file diff --git a/bin/envision.js b/bin/envision.js index c4c1458..42c8664 100755 --- a/bin/envision.js +++ b/bin/envision.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -import '../dist/app.js'; \ No newline at end of file +import '../dist/index.js'; \ No newline at end of file diff --git a/package.json b/package.json index 0da431f..9e0cde6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/envision-cli", - "version": "0.0.3", + "version": "0.0.4", "description": "envision command tools", "main": "dist/index.js", "type": "module", @@ -50,6 +50,7 @@ }, "dependencies": { "@kevisual/router": "^0.0.2", + "pg-hstore": "^2.3.4", "sequelize": "^6.37.4", "sqlite3": "^5.1.7" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 88b9f06..107626c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,9 +14,12 @@ importers: '@kevisual/router': specifier: ^0.0.2 version: 0.0.2 + pg-hstore: + specifier: ^2.3.4 + version: 2.3.4 sequelize: specifier: ^6.37.4 - version: 6.37.4(sqlite3@5.1.7) + version: 6.37.4(pg-hstore@2.3.4)(sqlite3@5.1.7) sqlite3: specifier: ^5.1.7 version: 5.1.7 @@ -811,6 +814,10 @@ packages: pg-connection-string@2.7.0: resolution: {integrity: sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==} + pg-hstore@2.3.4: + resolution: {integrity: sha512-N3SGs/Rf+xA1M2/n0JBiXFDVMzdekwLZLAO0g7mpDY9ouX+fDI7jS6kTq3JujmYbtNSJ53TJ0q4G98KVZSM4EA==} + engines: {node: '>= 0.8.x'} + picomatch@4.0.2: resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} engines: {node: '>=12'} @@ -1030,6 +1037,9 @@ packages: engines: {node: '>=14.17'} hasBin: true + underscore@1.13.7: + resolution: {integrity: sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==} + undici-types@6.19.8: resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} @@ -1906,6 +1916,10 @@ snapshots: pg-connection-string@2.7.0: {} + pg-hstore@2.3.4: + dependencies: + underscore: 1.13.7 + picomatch@4.0.2: {} prebuild-install@7.1.2: @@ -2007,7 +2021,7 @@ snapshots: sequelize-pool@7.1.0: {} - sequelize@6.37.4(sqlite3@5.1.7): + sequelize@6.37.4(pg-hstore@2.3.4)(sqlite3@5.1.7): dependencies: '@types/debug': 4.1.12 '@types/validator': 13.12.2 @@ -2026,6 +2040,7 @@ snapshots: validator: 13.12.0 wkx: 0.5.0 optionalDependencies: + pg-hstore: 2.3.4 sqlite3: 5.1.7 transitivePeerDependencies: - supports-color @@ -2158,6 +2173,8 @@ snapshots: typescript@5.6.3: {} + underscore@1.13.7: {} + undici-types@6.19.8: {} unique-filename@1.1.1: diff --git a/rollup.config.js b/rollup.config.js index d07e5cb..8cad602 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -10,12 +10,15 @@ import json from '@rollup/plugin-json'; export default { input: 'src/index.ts', // TypeScript 入口文件 output: { - file: 'dist/app.js', // 输出文件 + // file: 'dist/app.js', // 输出文件 + dir: 'dist', format: 'es', // 输出格式设置为 ES 模块 }, plugins: [ resolve(), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块 - commonjs(), + commonjs({ + // dynamicRequireTargets: ['node_modules/sqlite3/lib/*.js'], + }), json(), typescript({ allowImportingTsExtensions: true, @@ -24,4 +27,5 @@ export default { declaration: false, }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件 ], + external: ['sqlite3', 'sequelize'], // 将 sqlite3 作为外部依赖 }; diff --git a/src/command/config.ts b/src/command/config.ts new file mode 100644 index 0000000..6045415 --- /dev/null +++ b/src/command/config.ts @@ -0,0 +1,24 @@ +import { program as app, Command } from '@/program.ts'; +import { getConfig, writeConfig } from '@/module/index.ts'; + +const command = new Command('config') + .description('') + .option('-d, --dev ', 'Specify dev') + .option('-l --list', 'list config') + .action(async (options) => { + const { dev, list } = options || {}; + if (dev === 'true' || dev === 'false') { + const config = getConfig(); + if (dev === 'true') { + writeConfig({ ...config, dev: true }); + } else { + writeConfig({ ...config, dev: false }); + } + } + if (list) { + const config = getConfig(); + console.log('config', config); + } + }); + +app.addCommand(command); diff --git a/src/command/deploy.ts b/src/command/deploy.ts index f95d287..a73106d 100644 --- a/src/command/deploy.ts +++ b/src/command/deploy.ts @@ -3,7 +3,7 @@ import { glob } from 'glob'; import path from 'path'; import fs from 'fs'; import FormData from 'form-data'; -import { baseURL } from '@/module/query.ts'; +import { baseURL, getBaseURL } from '@/module/query.ts'; import { getConfig } from '@/module/index.ts'; import inquirer from 'inquirer'; @@ -76,12 +76,14 @@ const uploadFiles = async (files: string[], directory: string, { key, version }: const filePath = path.join(directory, file); form.append('file', fs.createReadStream(filePath), { filename: file, + filepath: file, }); } form.append('appKey', key); form.append('version', version); return new Promise((resolve) => { - const url = new URL(baseURL); + const _baseURL = getBaseURL(); + const url = new URL(_baseURL); console.log('upload url', url.hostname, url.protocol, url.port); form.submit( { diff --git a/src/index.ts b/src/index.ts index 0b32d22..1319d95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,5 +5,6 @@ import './command/ls-token.ts'; import './command/me.ts'; import './command/deploy.ts'; import './command/serve.ts'; +import './command/config.ts'; program.parse(process.argv); diff --git a/src/module/query.ts b/src/module/query.ts index 8dd6244..81e9ff0 100644 --- a/src/module/query.ts +++ b/src/module/query.ts @@ -2,7 +2,12 @@ import { Query } from '@kevisual/query'; import { getConfig } from './get-config.ts'; const config = getConfig(); export const baseURL = config?.baseURL || 'https://envision.xiongxiao.me'; - +export const getBaseURL = () => { + if (config?.dev) { + return 'http://localhost:4002'; + } + return baseURL; +}; export const query = new Query({ url: `${baseURL}/api/router`, }); diff --git a/src/module/sequelize.ts b/src/module/sequelize.ts index c25341f..833c40c 100644 --- a/src/module/sequelize.ts +++ b/src/module/sequelize.ts @@ -8,6 +8,9 @@ export const sequelize = new Sequelize({ // logging: false, }); -sequelize.authenticate({ logging: false }).then(() => { - console.log('Connection sqlite has been established successfully.'); -}); +sequelize + .authenticate({ logging: false }) + .then(() => {}) + .catch((err) => { + console.error('Unable to connect to the database:', err); + });