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

View File

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

View File

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

View File

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