Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit ebc10f9

Browse files
committed
👕 refactor: generator
1 parent 4b64d81 commit ebc10f9

File tree

2 files changed

+70
-55
lines changed

2 files changed

+70
-55
lines changed

generator/index.js

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,10 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
4-
function checkInstalled (target) {
5-
let ret = true
6-
try {
7-
const resolveModule = require(path.resolve(target))
8-
if (!resolveModule) {
9-
ret = false
10-
}
11-
} catch (e) {
12-
ret = false
13-
}
14-
return ret
15-
}
16-
17-
function exists (path) {
18-
let ret = true
19-
try {
20-
fs.accessSync(path, fs.constants.F_OK)
21-
} catch (e) {
22-
ret = false
23-
}
24-
return ret
25-
}
26-
27-
function mkdir (path) {
28-
let ret = true
29-
try {
30-
fs.mkdirSync(path)
31-
} catch (e) {
32-
ret = false
33-
}
34-
return ret
35-
}
36-
37-
function writeFile (path, content) {
38-
let ret = true
39-
try {
40-
fs.writeFileSync(path, content, { encoding: 'utf8' })
41-
} catch (e) {
42-
ret = false
43-
}
44-
return ret
45-
}
46-
47-
function readFile (path) {
48-
let ret = ''
49-
try {
50-
ret = fs.readFileSync(path, { encoding: 'utf8' })
51-
} catch (e) {
52-
ret = ''
53-
}
54-
return ret
55-
}
1+
const {
2+
checkInstalled,
3+
exists,
4+
mkdir,
5+
writeFile,
6+
readFile
7+
} = require('../utils')
568

579
module.exports = (api, options, rootOptions) => {
5810
const { locale, fallbackLocale, enableInSFC } = options

utils.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
function checkInstalled (target) {
5+
let ret = true
6+
try {
7+
const resolveModule = require(path.resolve(target))
8+
if (!resolveModule) {
9+
ret = false
10+
}
11+
} catch (e) {
12+
ret = false
13+
}
14+
return ret
15+
}
16+
17+
function exists (path) {
18+
let ret = true
19+
try {
20+
fs.accessSync(path, fs.constants.F_OK)
21+
} catch (e) {
22+
ret = false
23+
}
24+
return ret
25+
}
26+
27+
function mkdir (path) {
28+
let ret = true
29+
try {
30+
fs.mkdirSync(path)
31+
} catch (e) {
32+
ret = false
33+
}
34+
return ret
35+
}
36+
37+
function writeFile (path, content) {
38+
let ret = true
39+
try {
40+
fs.writeFileSync(path, content, { encoding: 'utf8' })
41+
} catch (e) {
42+
ret = false
43+
}
44+
return ret
45+
}
46+
47+
function readFile (path) {
48+
let ret = ''
49+
try {
50+
ret = fs.readFileSync(path, { encoding: 'utf8' })
51+
} catch (e) {
52+
ret = ''
53+
}
54+
return ret
55+
}
56+
57+
module.exports = {
58+
checkInstalled,
59+
exists,
60+
mkdir,
61+
writeFile,
62+
readFile
63+
}

0 commit comments

Comments
 (0)