-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateFiles.js
More file actions
53 lines (46 loc) · 3.04 KB
/
createFiles.js
File metadata and controls
53 lines (46 loc) · 3.04 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
const {join: pJoin} = require('path')
const fs = require('fs-extra')
const { generateProjectPackageJson } = require('./generateProjectPackageJson.js')
const templateFolderPath = pJoin(__dirname, 'templates')
function createFiles(cwd, {node, nodeandweb, webpack}, appName) {
const compiler = webpack ? 'webpack' : 'rollup'
const webTemplateFolderSrcPath = pJoin(templateFolderPath, 'web')
const serverTemplateFolderSrcPath = pJoin(templateFolderPath, 'server')
const nodeAndWebTemplateFolderSrcPath = pJoin(templateFolderPath, 'nodeandweb')
const serverIndexJsWritePath = pJoin(cwd, 'src', (nodeandweb ? 'server': ''), 'index.lsc')
const frontendIndexJsWritePath = pJoin(cwd, 'src', (nodeandweb ? 'frontend': ''), 'index.lsc')
const projectPackageJson = generateProjectPackageJson(node, nodeandweb, webpack, appName)
fs.writeJSONSync(pJoin(cwd, 'package.json'), projectPackageJson, {spaces: 2})
fs.outputFileSync(pJoin(cwd, '.gitattributes'), '*.lsc linguist-language=javascript')
fs.outputFileSync(pJoin(cwd, '.gitignore'), '')
fs.outputFileSync(pJoin(cwd, '.eslintignore'), '')
fs.copySync(pJoin(templateFolderPath, '.vscode', 'settings.json'), pJoin(cwd, '.vscode', 'settings.json'))
fs.copySync(pJoin(templateFolderPath, 'eslint-config.js'), pJoin(cwd, '.eslintrc.js'))
if(node){
fs.copySync(pJoin(serverTemplateFolderSrcPath, compiler, 'index.lsc'), serverIndexJsWritePath)
fs.copySync(pJoin(serverTemplateFolderSrcPath, compiler, `${ compiler }.config.server.js`), pJoin(cwd, `${ compiler }.config.server.js`))
}
else if(nodeandweb){
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, compiler, 'index-server.lsc'), serverIndexJsWritePath)
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, compiler, `${ compiler }.config.server.js`), pJoin(cwd, `${ compiler }.config.server.js`))
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, 'index.html'), pJoin(cwd, 'dist', 'index.html'))
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, compiler, 'index-web.lsc'), frontendIndexJsWritePath)
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, compiler, `${ compiler }.config.web.js`), pJoin(cwd, `${ compiler }.config.web.js`))
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, 'styles', 'style.scss'), pJoin(cwd, 'src', 'frontend', 'styles', 'style.scss'))
if(webpack){
fs.copySync(pJoin(nodeAndWebTemplateFolderSrcPath, compiler, 'postcss.config.js'), pJoin(cwd, 'postcss.config.js'))
}
}
else{ //web
fs.copySync(pJoin(webTemplateFolderSrcPath, 'index.html'), pJoin(cwd, 'dist', 'index.html'))
fs.copySync(pJoin(webTemplateFolderSrcPath, compiler, 'index.lsc'), frontendIndexJsWritePath)
fs.copySync(pJoin(webTemplateFolderSrcPath, compiler, `${ compiler }.config.web.js`), pJoin(cwd, `${ compiler }.config.web.js`))
fs.copySync(pJoin(webTemplateFolderSrcPath, 'styles', 'style.scss'), pJoin(cwd, 'src', 'styles', 'style.scss'))
if(webpack){
fs.copySync(pJoin(webTemplateFolderSrcPath, compiler, 'postcss.config.js'), pJoin(cwd, 'postcss.config.js'))
}
}
}
module.exports = {
createFiles
}