create-paiza-ts 1.0.0
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/main.js +49 -0
- package/package.json +22 -0
package/bin/main.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import spawn from 'cross-spawn'
|
|
5
|
+
|
|
6
|
+
const templateDir = path.resolve(import.meta.dirname, '../template')
|
|
7
|
+
const targetDir = process.cwd()
|
|
8
|
+
|
|
9
|
+
const files = fs.readdirSync(targetDir)
|
|
10
|
+
if (files.length > 0) {
|
|
11
|
+
console.error('空のディレクトリで実行してください。処理を停止します。')
|
|
12
|
+
console.error("既に作成したプロジェクトの場合は、代わりに npm start を実行してください。")
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
copyDirectory(templateDir, targetDir)
|
|
17
|
+
|
|
18
|
+
console.log('> npm i')
|
|
19
|
+
runNpmCommand('i')
|
|
20
|
+
|
|
21
|
+
console.log('> npm start')
|
|
22
|
+
runNpmCommand('start')
|
|
23
|
+
|
|
24
|
+
function copyDirectory(sourceDir, targetDir) {
|
|
25
|
+
fs.mkdirSync(targetDir, { recursive: true })
|
|
26
|
+
const entries = fs.readdirSync(sourceDir, { withFileTypes: true })
|
|
27
|
+
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const sourcePath = path.join(sourceDir, entry.name)
|
|
30
|
+
const targetPath = path.join(targetDir, entry.name)
|
|
31
|
+
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
copyDirectory(sourcePath, targetPath)
|
|
34
|
+
} else {
|
|
35
|
+
fs.copyFileSync(sourcePath, targetPath)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function runNpmCommand(command) {
|
|
41
|
+
const result = spawn.sync('npm', [command], {
|
|
42
|
+
cwd: targetDir,
|
|
43
|
+
stdio: 'inherit',
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
if (result.status !== 0) {
|
|
47
|
+
process.exit(result.status)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-paiza-ts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"bin": {
|
|
6
|
+
"create-paiza-ts": "./bin/main.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "vrcalphabet",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
17
|
+
"prettier": "^3.8.3"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"cross-spawn": "^7.0.6"
|
|
21
|
+
}
|
|
22
|
+
}
|