Skip to content

Commit

Permalink
fix: 修改错误拼写 & 调整模块esm & 添加.npmignore 项
Browse files Browse the repository at this point in the history
  • Loading branch information
gxr404 committed Aug 16, 2023
1 parent 92dde98 commit 910cb0a
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
env: {
node: true,
},
Expand Down
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ src
node_modules
test
temp
.vscode
.vscode
.np-config.js
.eslintrc.js
.eslintignore
.editorconfig
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
semi: false,
endOfLine: 'lf',
singleQuote: true,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
"build:bundle": "rollup -c rollup.config.ts --configPlugin typescript",
"build:types": "tsc --emitDeclarationOnly --outDir types -p tsconfig.base.json",
"clean": "rm -rf dist types",
"release": "np"
"release": "run-s clean build np"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gxr404/yuque-dl.git"
},
"keywords": [],
"author": "",
"keywords": ["yuque", "nodejs", "download","yuque-dl"],
"author": "gxr404",
"license": "ISC",
"bugs": {
"url": "https://github.com/gxr404/yuque-dl/issues"
},
"homepage": "https://github.com/gxr404/yuque-dl#readme",
"devDependencies": {
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@types/node": "^20.5.0",
"@types/progress": "^2.0.5",
Expand Down
61 changes: 54 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'rollup'
import typescript from '@rollup/plugin-typescript'
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'

export default defineConfig({
input: {
Expand All @@ -19,7 +19,7 @@ export default defineConfig({
],
plugins: [
typescript(),
json()
terser()
]
})

Expand Down
38 changes: 19 additions & 19 deletions src/Process.ts → src/ProgressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import progress from 'progress'
import logger from './log'
import type { KnowledgeBase } from './types/KnowledgeBaseResponse'

export interface IProcessItem {
export interface IProgressItem {
path: string,
toc: KnowledgeBase.Toc,
pathIdList: string[],
pathTitleList: string[]
}
export type IProcess = IProcessItem[]
export type IProgress = IProgressItem[]

export default class Progress {
export default class ProgressBar {
bookPath: string = ''
processFilePath: string = ''
processInfo: IProcess = []
progressFilePath: string = ''
progressInfo: IProgress = []
curr: number = 0
total: number = 0
isDownloadInterrupted: boolean = false
Expand All @@ -24,13 +24,13 @@ export default class Progress {

constructor (bookPath: string, total: number) {
this.bookPath = bookPath
this.processFilePath = `${bookPath}/process.json`
this.progressFilePath = `${bookPath}/progress.json`
this.total = total
}

async init() {
this.processInfo = await this.getProgress()
this.curr = this.processInfo.length
this.progressInfo = await this.getProgress()
this.curr = this.progressInfo.length
let completeResolve: Function
this.completePromise = new Promise(resolve => {
completeResolve = resolve
Expand All @@ -51,28 +51,28 @@ export default class Progress {

}

async getProgress(): Promise<IProcess> {
let processInfo = []
async getProgress(): Promise<IProgress> {
let progressInfo = []
try {
const processInfoStr = await fs.readFile(this.processFilePath, {encoding: 'utf8'})
processInfo = JSON.parse(processInfoStr)
const progressInfoStr = await fs.readFile(this.progressFilePath, {encoding: 'utf8'})
progressInfo = JSON.parse(progressInfoStr)
} catch (err) {
if (err && err.code === 'ENOENT') {
await fs.writeFile(
this.processFilePath,
JSON.stringify(processInfo),
this.progressFilePath,
JSON.stringify(progressInfo),
{encoding: 'utf8'}
)
}
}
return processInfo
return progressInfo
}

async updateProgress(progressItem: IProcessItem) {
this.processInfo.push(progressItem)
async updateProgress(progressItem: IProgressItem) {
this.progressInfo.push(progressItem)
await fs.writeFile(
this.processFilePath,
JSON.stringify(this.processInfo),
this.progressFilePath,
JSON.stringify(this.progressInfo),
{encoding: 'utf8'}
)
this.curr = this.curr + 1
Expand Down
9 changes: 0 additions & 9 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,3 @@ try {
logger.error(err.message || 'unknown exception')
process.exit(1)
}

// try {
// cli.parse(process.argv, { run: false })
// await cli.runMatchedCommand()
// } catch (error) {
// logger.error(error.message || 'unknown exception')
// process.exit(1)

// }
Loading

0 comments on commit 910cb0a

Please sign in to comment.