-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.js
More file actions
94 lines (80 loc) · 2.07 KB
/
release.js
File metadata and controls
94 lines (80 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require('fs');
const { execSync } = require('child_process')
let count = 1
/**
* ディレクトリ存在確認
* @param {String} path
* @returns ディレクトリの存在
*/
function isExistDir(path){
const stat = fs.statSync(`src/${path}`)
if(stat.isDirectory()) return true
console.error('指定したディレクトリが存在しません')
return false
}
/**
* コマンドを実行する
* @param {String} command 文字列コマンド
*/
function runCommand(command, isShowCommand = true){
console.log(`${count}:\t${command}`)
execSync(command)
console.log("++++++++++++++++++++++")
count++
}
/**
* バニラ(ビルドツールなど介入なし)のビルド
*/
function buildVanilla(){
const dirpath = process.argv[3];
if(isExistDir(dirpath)){
runCommand(`npx rimraf demo/${dirpath}`)
runCommand(`npx cpx -C src/${dirpath}/**/* demo/${dirpath}`)
}
}
/**
* webpackによるビルド
*/
function buildWebpack(){
const dirpath = process.argv[3];
if(isExistDir(dirpath)){
runCommand(`npx rimraf demo/${dirpath}`)
runCommand(`npm -prefix src/${dirpath} install src/${dirpath}`)
runCommand(`npm -prefix src/${dirpath} run build`)
runCommand(`npx cpx -C src/${dirpath}/dist/**/* demo/${dirpath}`)
}
}
const command_dict = {
mode_vanilla:{
mode: 'vanilla',
description: 'vanilla file(not builder tools)',
exec: buildVanilla
},
mode_webpack:{
mode: 'webpack',
description: 'webpack build. depencies select dir\'s npm.',
exec: buildWebpack
}
}
switch(process.argv.length){
case 3:
if(process.argv[2] === '-h'){
console.log('"$ node release <mode> <path/to/file>"')
console.log('+++++++++++++++++++++++++++++++++++++')
console.log('select <mode> in under list')
for(let key in command_dict)
console.log(`- ${command_dict[key].mode}:\t\t${command_dict[key].description}`)
return
}
break;
case 4:
for(key in command_dict){
if(process.argv[2] === command_dict[key].mode){
command_dict[key].exec()
return
}
}
break;
}
console.error('"$ node release -h" show description')
return -1