-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs')
const path = require('path')
const { rmSync, cpSync } = require('./utils')
const { pioPath,textures } = require('./config')
const modelTemplate = require('./source/model.json')
const modelsPath = path.resolve(pioPath, 'models')
const sourcePath = path.resolve(__dirname,'source')
rmSync(pioPath)
fs.mkdirSync(pioPath)
rmSync(modelsPath)
fs.mkdirSync(modelsPath)
const createPromise = texture => new Promise(resolve => {
const basePath = path.resolve(modelsPath,`pio-${texture}`)
fs.mkdirSync(basePath)
fs.mkdirSync(path.resolve(basePath,'textures'))
const cpList = ['motions',`textures/${texture}.png`,'model.moc']
cpList.forEach(cpPath => {
cpSync(path.resolve(sourcePath,cpPath),path.resolve(basePath,cpPath))
})
modelTemplate.textures = [`textures/${texture}.png`]
fs.writeFile(path.resolve(basePath, `model.json`), JSON.stringify(modelTemplate), (err) => {
if (err) throw err;
resolve(texture)
})
})
Promise.all(textures.map(createPromise)).then(textures => {
const modelListPath = path.resolve(pioPath,'models.js')
rmSync(modelListPath)
fs.writeFile(modelListPath, `var pio_models = ${JSON.stringify(textures)};`,err => {
if(err) throw err;
console.log('输出成功')
})
})