alemonjs 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build.js +100 -0
- package/bin/dev.js +25 -0
- package/bin/main.js +7 -1
- package/bin/start.js +25 -0
- package/package.json +6 -3
package/bin/build.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync, mkdirSync } from 'fs'
|
|
4
|
+
import { execSync, exec, spawn } from 'child_process'
|
|
5
|
+
import { compilationTools } from 'alemon-rollup'
|
|
6
|
+
import { join } from 'path'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 执行指令
|
|
10
|
+
* @param {*} cess
|
|
11
|
+
* @param {*} cmd
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
async function command(cess, cmd) {
|
|
15
|
+
// 错误参数
|
|
16
|
+
if (!cmd) process.exit()
|
|
17
|
+
// 锁定位置
|
|
18
|
+
const dirPath = `./`
|
|
19
|
+
// 没有存在
|
|
20
|
+
mkdirSync(dirPath, { recursive: true })
|
|
21
|
+
console.info('\n')
|
|
22
|
+
try {
|
|
23
|
+
// 切换目录
|
|
24
|
+
process.chdir(dirPath)
|
|
25
|
+
console.info(`[command] ${cmd}`)
|
|
26
|
+
if (cess == 'execSync') {
|
|
27
|
+
execSync(cmd, { stdio: 'inherit' })
|
|
28
|
+
} else if (cess == 'exec') {
|
|
29
|
+
exec(cmd)
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.info(`${error}`)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 执行脚本
|
|
39
|
+
* @param {*} name
|
|
40
|
+
* @param {*} file
|
|
41
|
+
* @param {*} ars
|
|
42
|
+
*/
|
|
43
|
+
function nodeScripts(name = 'node', file = '', ars = []) {
|
|
44
|
+
const command = spawn(`${name} ${file} ${ars.join(' ')}`, { shell: true })
|
|
45
|
+
command.stdout.on('data', data => {
|
|
46
|
+
process.stdout.write(data.toString())
|
|
47
|
+
})
|
|
48
|
+
command.stderr.on('data', data => {
|
|
49
|
+
process.stderr.write(data.toString())
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
;(async function run() {
|
|
54
|
+
/**
|
|
55
|
+
* 得到配置
|
|
56
|
+
*/
|
|
57
|
+
const ars = process.argv.slice(2)
|
|
58
|
+
const msg = ars.join(' ')
|
|
59
|
+
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.build.js']
|
|
60
|
+
/**
|
|
61
|
+
* 判断是文件是否存在
|
|
62
|
+
*/
|
|
63
|
+
let Options = {}
|
|
64
|
+
|
|
65
|
+
if (existsSync(join(process.cwd(), files[0]))) {
|
|
66
|
+
console.log('[CONFIG]', files[0])
|
|
67
|
+
Options = await import(`../${files[0]}`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 开始打包
|
|
72
|
+
*/
|
|
73
|
+
await compilationTools({
|
|
74
|
+
aInput: Options?.input ?? 'apps/**/*.ts',
|
|
75
|
+
aOutput: Options?.output ?? 'app.alemon.js'
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 附加指令
|
|
80
|
+
*/
|
|
81
|
+
if (Options?.command) {
|
|
82
|
+
for await (const item of Options.command) {
|
|
83
|
+
if (item?.cmd) {
|
|
84
|
+
await command(item?.cess ?? 'execSync', item?.cmd)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* **********
|
|
91
|
+
* 附加脚本
|
|
92
|
+
* **********
|
|
93
|
+
*/
|
|
94
|
+
if (Options?.scripts) {
|
|
95
|
+
for await (const item of Options.scripts) {
|
|
96
|
+
const name = item?.name ?? 'node'
|
|
97
|
+
nodeScripts(name, item?.file, item?.ars ?? [])
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})()
|
package/bin/dev.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from 'child_process'
|
|
4
|
+
import { existsSync } from 'fs'
|
|
5
|
+
import { join } from 'path'
|
|
6
|
+
const ars = process.argv.slice(2).push('dev')
|
|
7
|
+
const msg = ars.join(' ')
|
|
8
|
+
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
9
|
+
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
10
|
+
for (const item of files) {
|
|
11
|
+
if (!existsSync(join(process.cwd(), item))) {
|
|
12
|
+
console.log('[NO FILE]', item)
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
// nodemon alemon.config.ts dev
|
|
16
|
+
const cmd = `nodemon ${item} ${argsWithoutFiles}`
|
|
17
|
+
console.log('[alemonjs]', cmd)
|
|
18
|
+
const childProcess = spawn(cmd, { shell: true })
|
|
19
|
+
childProcess.stdout.on('data', data => {
|
|
20
|
+
process.stdout.write(data.toString())
|
|
21
|
+
})
|
|
22
|
+
childProcess.stderr.on('data', data => {
|
|
23
|
+
process.stderr.write(data.toString())
|
|
24
|
+
})
|
|
25
|
+
}
|
package/bin/main.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawn } from 'child_process'
|
|
4
|
+
import { existsSync } from 'fs'
|
|
5
|
+
import { join } from 'path'
|
|
4
6
|
const ars = process.argv.slice(2)
|
|
5
7
|
const msg = ars.join(' ')
|
|
6
8
|
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
7
9
|
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
8
10
|
for (const item of files) {
|
|
11
|
+
if (!existsSync(join(process.cwd(), item))) {
|
|
12
|
+
console.log('[NO FILE]', item)
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
9
15
|
const isTypeScript = item.endsWith('.ts')
|
|
10
16
|
const command = isTypeScript ? 'npx ts-node' : 'node'
|
|
11
17
|
const cmd = `${command} ${item} ${argsWithoutFiles}`
|
package/bin/start.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from 'child_process'
|
|
4
|
+
import { existsSync } from 'fs'
|
|
5
|
+
import { join } from 'path'
|
|
6
|
+
const ars = process.argv.slice(2)
|
|
7
|
+
const msg = ars.join(' ')
|
|
8
|
+
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['pm2.config.cjs']
|
|
9
|
+
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
10
|
+
for (const item of files) {
|
|
11
|
+
if (!existsSync(join(process.cwd(), item))) {
|
|
12
|
+
console.log('[NO FILE]', item)
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
// pm2 startOrRestart pm2.config.cjs
|
|
16
|
+
const cmd = `pm2 startOrRestart ${item} ${argsWithoutFiles}`
|
|
17
|
+
console.log('[alemonjs]', cmd)
|
|
18
|
+
const childProcess = spawn(cmd, { shell: true })
|
|
19
|
+
childProcess.stdout.on('data', data => {
|
|
20
|
+
process.stdout.write(data.toString())
|
|
21
|
+
})
|
|
22
|
+
childProcess.stderr.on('data', data => {
|
|
23
|
+
process.stderr.write(data.toString())
|
|
24
|
+
})
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "阿柠檬框架",
|
|
5
5
|
"author": "ningmengchongshui",
|
|
6
6
|
"license": "GPL-2.0",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@discordjs/builders": "^1.6.3",
|
|
17
17
|
"@discordjs/core": "^0.6.0",
|
|
18
18
|
"@discordjs/rest": "^1.7.1",
|
|
19
|
-
"alemon-rollup": "^1.0.
|
|
19
|
+
"alemon-rollup": "^1.0.3",
|
|
20
20
|
"alemonjs": "^1.0.13",
|
|
21
21
|
"axios": "^1.4.0",
|
|
22
22
|
"discord.js": "^14.11.0",
|
|
@@ -61,7 +61,10 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"bin": {
|
|
64
|
-
"alemonjs": "bin/main.js"
|
|
64
|
+
"alemonjs": "bin/main.js",
|
|
65
|
+
"alemonjs-start": "bin/start.js",
|
|
66
|
+
"alemonjs-build": "bin/build.js",
|
|
67
|
+
"alemonjs-dev": "bin/dev.js"
|
|
65
68
|
},
|
|
66
69
|
"publishConfig": {
|
|
67
70
|
"registry": "https://registry.npmjs.org"
|