cli/lib/demo-config.js

96 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-01-05 17:00:49 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2022/10/10 16:49:07
*/
import fs from 'iofs'
export function writePackageJson(file, name) {
fs.echo(
JSON.stringify(
{
name: name || 'gm5-app',
type: 'module',
main: 'app.js',
dependencies: {
2023-11-02 11:16:54 +08:00
'@gm5/core': '^2.0.0'
2023-01-05 17:00:49 +08:00
}
},
null,
2
),
file
)
}
export function writeGitIgnore(file) {
fs.echo(
`
*.sublime-project
*.sublime-workspace
node_modules
package-lock.json
data/logs
public/upload/
._*
.idea
.vscode
.Spotlight-V100
.Trashes
.DS_Store
.AppleDouble
.LSOverride
`,
file
)
}
export function writePrettierrc(file) {
fs.echo(
`
jsxBracketSameLine: true
jsxSingleQuote: true
semi: false
singleQuote: true
2023-11-02 11:16:54 +08:00
printWidth: 80
2023-01-05 17:00:49 +08:00
useTabs: false
tabWidth: 2
trailingComma: none
bracketSpacing: true
arrowParens: avoid
`,
file
)
}
2023-11-02 11:16:54 +08:00
export function writePm2File(
file,
{ env = 'production', name = 'gm5-app', cluster = true }
) {
2023-01-05 17:00:49 +08:00
fs.echo(
`
2023-11-02 11:16:54 +08:00
script: node ./app.js
2023-01-05 17:00:49 +08:00
cwd: ./
watch: true
name: ${name}
ignore_watch: [data, public, package.json, package-lock.json, node_modules, .git, .gitignore, app.yaml]
exec_mode: ${cluster ? 'cluster' : 'fork'}
${cluster ? 'instances: max' : ''}
error_file: ./data/logs/error.log
out_file: ./data/logs/out.log
merge_logs: true
min_uptime: 60s
max_restarts: 1
max_memory_restart: 300M
env:
NODE_ENV: ${env}
`,
file
)
}