Skip to content

Commit 4ed068a

Browse files
committed
fix: build dir to .gridea
Change-Id: I0a39b89afafb443d5ae6a19435bce0c07a3237b7
1 parent 4a81644 commit 4ed068a

5 files changed

Lines changed: 16 additions & 67 deletions

File tree

src/server/app.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ export default class App {
3131

3232
db: IApplicationDb
3333

34+
buildDir: string
35+
3436
constructor(setting: IApplicationSetting) {
3537
this.mainWindow = setting.mainWindow
3638
this.app = setting.app
3739
this.baseDir = setting.baseDir
3840
this.appDir = path.join(this.app.getPath('documents'), 'gridea')
3941
this.previewServer = setting.previewServer
42+
this.buildDir = path.join(this.app.getPath('home'), '.gridea', 'output')
4043

4144
this.db = {
4245
posts: [],
@@ -202,6 +205,11 @@ export default class App {
202205
fse.writeFileSync(appConfigPath, jsonString)
203206
}
204207

208+
const buildDir = path.join(appConfigFolder, 'output')
209+
if (!fse.pathExistsSync(buildDir)) {
210+
fse.mkdirSync(buildDir)
211+
}
212+
205213
const appConfig = fse.readJsonSync(appConfigPath)
206214
this.appDir = appConfig.sourceFolder
207215

src/server/deploy.ts

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import GitProxy from './plugins/deploys/gitproxy'
77
const git = require('isomorphic-git')
88

99
export default class Deploy extends Model {
10-
outputDir: string = `${this.appDir}/output`
10+
outputDir: string = this.buildDir
1111

1212
remoteUrl = ''
1313

@@ -91,6 +91,7 @@ export default class Deploy extends Model {
9191
}
9292

9393
async publish() {
94+
await this.remoteDetect()
9495
this.db.themeConfig.domain = this.db.setting.domain
9596
let result = {
9697
success: true,
@@ -112,61 +113,6 @@ export default class Deploy extends Model {
112113
return result
113114
}
114115

115-
async firstPush() {
116-
const { setting } = this.db
117-
const localBranchs = {}
118-
console.log('first push')
119-
120-
try {
121-
await git.init({ fs, dir: this.outputDir })
122-
await git.setConfig({
123-
fs,
124-
dir: this.outputDir,
125-
path: 'user.name',
126-
value: setting.username,
127-
})
128-
await git.setConfig({
129-
fs,
130-
dir: this.outputDir,
131-
path: 'user.email',
132-
value: setting.email,
133-
})
134-
await git.add({ fs, dir: this.outputDir, filepath: '.' })
135-
await git.commit({
136-
fs,
137-
dir: this.outputDir,
138-
message: `update from gridea: ${moment().format('YYYY-MM-DD HH:mm:ss')}`,
139-
})
140-
await git.addRemote({
141-
fs, dir: this.outputDir, remote: 'origin', url: this.remoteUrl, force: true,
142-
})
143-
144-
await this.checkCurrentBranch()
145-
const pushRes = await git.push({
146-
fs,
147-
http: this.http,
148-
dir: this.outputDir,
149-
remote: 'origin',
150-
ref: setting.branch,
151-
force: true,
152-
})
153-
return {
154-
success: true,
155-
data: pushRes,
156-
message: '',
157-
localBranchs,
158-
}
159-
} catch (e) {
160-
console.error(e)
161-
return {
162-
success: false,
163-
data: localBranchs,
164-
message: e.message,
165-
localBranchs,
166-
}
167-
}
168-
}
169-
170116
async commonPush() {
171117
console.log('common push')
172118
const { setting } = this.db

src/server/interfaces/application.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export interface IApplication {
3030
app: any
3131
baseDir: string
3232
appDir: string
33+
buildDir: string
3334
db: IApplicationDb
3435
}

src/server/model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { IApplicationDb, IApplication } from './interfaces/application'
77
export default class Model {
88
appDir: string
99

10+
buildDir: string
11+
1012
$setting: any
1113

1214
$posts: any
@@ -19,6 +21,7 @@ export default class Model {
1921

2022
constructor(appInstance: IApplication) {
2123
this.appDir = appInstance.appDir
24+
this.buildDir = appInstance.buildDir
2225
this.db = appInstance.db
2326
this.mainWindow = appInstance.mainWindow
2427

src/server/renderer.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Bluebird.promisifyAll(fs)
2323
const helper = new ContentHelper()
2424

2525
export default class Renderer extends Model {
26-
outputDir: string = `${this.appDir}/output`
26+
outputDir: string = this.buildDir
2727

2828
themePath: string = ''
2929

@@ -622,17 +622,8 @@ export default class Renderer extends Model {
622622
}
623623

624624
async clearOutputFolder() {
625-
const { outputDir } = this
626-
const files = fse.readdirSync(outputDir, { withFileTypes: true })
627-
const needClearPath = files
628-
.map(item => item.name)
629-
.filter(junk.not)
630-
.filter((name: string) => name !== '.git')
631-
632625
try {
633-
needClearPath.forEach(async (name: string) => {
634-
fse.removeSync(urlJoin(outputDir, name))
635-
})
626+
fse.emptyDirSync(this.outputDir)
636627
} catch (e) {
637628
console.log('Delete file error', e)
638629
}

0 commit comments

Comments
 (0)