Compare commits

..

No commits in common. "master" and "1.0.1" have entirely different histories.

4 changed files with 32 additions and 45 deletions

View File

@ -19,9 +19,7 @@ import {
import { writeMainJs, writeAppJs, writeModelJs } from './lib/demo-js.js'
const CURRENT_DIR = process.cwd()
const root = dirname(
import.meta.url.slice(process.platform === 'win32' ? 10 : 7)
)
const root = dirname(import.meta.url.slice(process.platform === 'win32' ? 10 : 7))
const { version } = JSON.parse(fs.cat(join(root, './package.json')))
const DEFAULT_NAME = 'gm5-app'
@ -43,7 +41,7 @@ function sleep(num = 1) {
function printHelp() {
console.log('Usage: create-five {command} [arguments]')
console.log(' ', 'create-five init', '一个快速创建`@gm5`项目的小工具')
console.log(' ', 'create-five init', '一个快速创建Five.js项目的小工具')
console.log(' ', 'create-five -h[--help]', '打印帮助信息')
console.log()
process.exit()
@ -74,8 +72,7 @@ function printHelp() {
{
name: 'shouldOverwrite',
type: _ => (isEmpty(targetDir) ? null : 'toggle'),
message: _ =>
`目录 ${cyan(targetDir)} 非空, 是否${red('删除')}目录下所有的文件?`,
message: _ => `目录 ${cyan(targetDir)} 非空, 是否${red('删除')}目录下所有的文件?`,
initial: false,
active: '是',
inactive: '否'
@ -85,7 +82,7 @@ function printHelp() {
type: shouldOverwrite => {
if (shouldOverwrite === false) {
console.log(red('✖') + ' 操作取消~~')
process.exit()
process.exit(1)
}
return null
}
@ -94,11 +91,6 @@ function printHelp() {
console.log()
if (res.projectName === undefined) {
console.log('已取消操作~~')
process.exit()
}
if (res.projectName === '.') {
res.projectName = DEFAULT_NAME
}
@ -117,7 +109,6 @@ function printHelp() {
}
console.log(cyan('\n初始化项目...'))
console.log('[c---------]', '10%')
fs.mkdir(join(targetDir, 'apps'))
fs.mkdir(join(targetDir, 'models'))
@ -126,7 +117,7 @@ function printHelp() {
fs.mkdir(join(targetDir, 'public'))
fs.mkdir(join(targetDir, 'views'))
console.log('[ooc-------]', '30%')
console.log('[c---------]', '10%')
writePackageJson(join(targetDir, 'package.json'), res.projectName)
writeGitIgnore(join(targetDir, '.gitignore'))
@ -141,6 +132,8 @@ function printHelp() {
cluster: false
})
console.log('[ooc-------]', '30%')
console.log('[oooooc----]', '60%')
writeMainJs(join(targetDir, 'app.js'))
@ -149,11 +142,9 @@ function printHelp() {
console.log('[oooooooooo]', '100%')
console.log(cyan('初始化完成, 可依次执行以下命令启动项目: '))
console.log(blue('cd ' + res.projectName))
console.log(blue('npm i'))
console.log(blue('pm2 start app.dev.yaml'), gray('# 开发模式'))
console.log(blue('pm2 start app.yaml'), gray('# 生产模式'))
console.log('访问地址: ', cyan('http://127.0.0.1:3000'))
break
}

View File

@ -14,7 +14,7 @@ export function writePackageJson(file, name) {
type: 'module',
main: 'app.js',
dependencies: {
'@gm5/core': '^2.0.0'
'@gm5/core': '^1.1.4'
}
},
null,
@ -27,6 +27,9 @@ export function writePackageJson(file, name) {
export function writeGitIgnore(file) {
fs.echo(
`
*.sublime-project
*.sublime-workspace
node_modules
package-lock.json
data/logs
@ -53,7 +56,7 @@ jsxBracketSameLine: true
jsxSingleQuote: true
semi: false
singleQuote: true
printWidth: 80
printWidth: 100
useTabs: false
tabWidth: 2
trailingComma: none
@ -64,13 +67,10 @@ arrowParens: avoid
)
}
export function writePm2File(
file,
{ env = 'production', name = 'gm5-app', cluster = true }
) {
export function writePm2File(file, { env = 'production', name = 'gm5-app', cluster = true }) {
fs.echo(
`
script: node ./app.js
script: node --experimental-json-modules ./app.js
cwd: ./
watch: true
name: ${name}

View File

@ -9,23 +9,22 @@ import fs from 'iofs'
export function writeMainJs(file) {
fs.echo(
`
import { createApp, mount } from '@gm5/core'
const app = createApp()
// // 也可以在创建应用时, 就传递一些配置进去, 等价于下面的 app.set({...})
// const app = createApp({...})
import Five from '@gm5/core'
const app = new Five()
// app.set({
// // 可开启跨域支持
// cors: { enabled: true }
// // 可开启session支持
// session: { enabled: true, type: 'redis' }
//
// // 可开启模板引擎的支持
// views: { enabled: true, dir: './views' }
// })
// 预加载应用, 这一步是必须的, 且需要在run()方法前调用
app.use(mount('./apps/'))
// 预加载应用, 这一步是必须的, 且需要在listen方法前调用
app.preload('./apps/')
// 中间件示例
// 这里的回调, 如果不用箭头函数的话, this指向app
@ -40,17 +39,14 @@ app.use(mount('./apps/'))
// 安装拓展包, 可以应用中通过 this.context.$$mysql 调用到,
// 在中间件, 或后面的其他拓展包中, 可以直接 this.$$mysql 调用
// app.use({
// app.install({
// name: 'mysql',
// install: function() {
// return new Mysqli(conf)
// }
// })
app.listen(3000, () => {
// 这里可以做一些启动后的操作
// 初始化websocket服务
})
app.listen(3000)
`,
file
@ -87,9 +83,9 @@ import Controller from '@gm5/controller'
// import Model from '../models/index.js'
// 也可以不继承 Controller。 如用到session/jwt/views模块, 可继承Controller, 以获得更简单的调用方式(也可以不继承)。
//
export default class extends Controller {
// 所有的应用, 都要继承Controller
// 以获取跟框架交互的能力
export default class Index extends Controller {
// 这个main方法是可选的, 如果有定义, 会自动先调用
// 可以在这里做任何需要预处理的事, 支持async/await
@ -99,8 +95,8 @@ export default class extends Controller {
// this.model = new Model(this.context.$$mysql)
}
async indexAction() {
this.response.body = 'It works!'
async indexAction(){
this.response.end('It works!')
}
}

View File

@ -2,7 +2,7 @@
"name": "create-five",
"description": "一个快速创建Five.js项目的小工具",
"type": "module",
"version": "1.2.0",
"version": "1.0.1",
"author": "yutent <yutent.io@gmail.com>",
"bin": {
"create-five": "index.js"
@ -14,7 +14,7 @@
},
"repository": {
"type": "git",
"url": "https://git.wkit.fun/gm5/cli.git"
"url": "https://github.com/bytedo/gmf.cli.git"
},
"license": "MIT"
}