migrate config file to json; read them via fs.

This commit is contained in:
bossgeekgo
2024-02-11 23:43:10 +08:00
parent 4e2904721d
commit f9761a47bb
11 changed files with 154 additions and 126 deletions
@@ -1,16 +1,35 @@
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
import { cookies as bossCookies } from '../../config/boss.mjs'
import targetCompanyList from '../../config/target-company-list.mjs'
import {
sleep,
sleepWithRandomDelay
} from '@bossgeekgo/utils/sleep.mjs'
import fs from 'node:fs'
import { get__dirname } from '@bossgeekgo/utils/legacy-path.mjs';
import path from 'node:path';
puppeteer.use(StealthPlugin())
const { cookies: bossCookies } = JSON.parse(
fs.readFileSync(
path.join(
get__dirname(),
'../../config/boss.json'
)
)
)
const targetCompanyList = JSON.parse(
fs.readFileSync(
path.join(
get__dirname(),
'../../config/target-company-list.json'
)
)
)
if (!bossCookies?.length) {
console.error('There is no cookies. you can save a copy with EditThisCookie extension.')
process.exit(1)
@@ -1,10 +1,21 @@
import DingtalkPlugin from '@bossgeekgo/dingtalk-plugin/index.mjs'
import { dingTalkAccessToken } from "../../config/dingtalk.mjs"
import { mainLoop } from '@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs'
import {
SyncHook,
AsyncSeriesHook
} from 'tapable'
import fs from 'node:fs'
import path from 'node:path'
import { get__dirname } from '@bossgeekgo/utils/legacy-path.mjs';
const { groupRobotAccessToken: dingTalkAccessToken } = JSON.parse(
fs.readFileSync(
path.join(
get__dirname(),
'../../config/dingtalk.json'
)
)
)
const initPlugins = (hooks) => {
new DingtalkPlugin(dingTalkAccessToken).apply(hooks)
@@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"@bossgeekgo/dingtalk-plugin": "workspace:*",
"@bossgeekgo/geek-auto-start-chat-with-boss": "workspace:*"
"@bossgeekgo/geek-auto-start-chat-with-boss": "workspace:*",
"@bossgeekgo/utils": "workspace:*"
}
}
+3
View File
@@ -0,0 +1,3 @@
import * as url from 'url';
export const get__filename = () => url.fileURLToPath(import.meta.url);
export const get__dirname = () => url.fileURLToPath(new URL('.', import.meta.url));