|
| 1 | +const { exec } = require('child_process'); |
| 2 | +const fs_extra = require('fs-extra'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +var path = require('path') |
| 6 | +const chalk = require('chalk'); |
| 7 | +const log = console.log; |
| 8 | + |
| 9 | + |
| 10 | +module.exports = function (option,package_name){ |
| 11 | + |
| 12 | + process.chdir(path.resolve(__dirname,'../../../../')) |
| 13 | + |
| 14 | +let execCommand = function(command,console_content) { |
| 15 | + let promise = new Promise(function(resolve, reject){ |
| 16 | + |
| 17 | + exec(command, (error, stdout, stderr) => { |
| 18 | + |
| 19 | + if (error) { |
| 20 | + log(chalk.red('exec error:',error)); |
| 21 | + reject(new Error(error)); |
| 22 | + |
| 23 | + return; |
| 24 | + } |
| 25 | + if(stdout!==''){ |
| 26 | + log(chalk.green('stdout:',stdout)); |
| 27 | + } |
| 28 | + if(stderr!==''){ |
| 29 | + log(chalk.red('stderr:',stderr)); |
| 30 | + } |
| 31 | + resolve(); |
| 32 | + |
| 33 | + }); |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + }); |
| 38 | + return promise; |
| 39 | + |
| 40 | + }; |
| 41 | + |
| 42 | + |
| 43 | + let removeDir = function(dir) { |
| 44 | + let promise = new Promise(function(resolve, reject){ |
| 45 | +process.chdir(path.resolve(__dirname,'../../../../')) |
| 46 | + fs_extra.remove(dir,(err) =>{ |
| 47 | + if (err){ |
| 48 | + reject(err); |
| 49 | + throw err; |
| 50 | + } |
| 51 | + log(chalk.green('成功移除 ',dir)); |
| 52 | + resolve(); |
| 53 | + |
| 54 | + }); |
| 55 | + |
| 56 | + }); |
| 57 | + return promise; |
| 58 | + |
| 59 | + }; |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + let changeTabelRouter = function() { |
| 65 | + let promise = new Promise(function(resolve, reject){ |
| 66 | + |
| 67 | + process.chdir(path.resolve(__dirname,'../../../../src/router')) |
| 68 | + |
| 69 | + fs.readFile('index.js', 'utf8', (err, data) => { |
| 70 | + if (err){ |
| 71 | + reject(err); |
| 72 | + throw err; |
| 73 | + } |
| 74 | + const str=`path: '/table'`; |
| 75 | + let index=data.indexOf(str); |
| 76 | + let begin_index=data.lastIndexOf('{',index); |
| 77 | + let end_index=data.indexOf('}',index)+2; |
| 78 | + |
| 79 | + let begin_str=data.substring(0,begin_index); |
| 80 | + |
| 81 | + let end_str=data.substring(end_index+1); |
| 82 | + |
| 83 | + let final_str=begin_str+end_str; |
| 84 | + |
| 85 | + fs.writeFile('index.js', final_str, (err) => { |
| 86 | + if (err){ |
| 87 | + reject(err); |
| 88 | + throw err; |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | + log(chalk.green('移除 Table 路由成功!')); |
| 93 | + resolve(); |
| 94 | + |
| 95 | + }); |
| 96 | + |
| 97 | + }); |
| 98 | + |
| 99 | + }); |
| 100 | + return promise; |
| 101 | + |
| 102 | + }; |
| 103 | + |
| 104 | + let changeTabelDetailRouter = function() { |
| 105 | + let promise = new Promise(function(resolve, reject){ |
| 106 | + |
| 107 | + process.chdir(path.resolve(__dirname,'../../../../src/router')) |
| 108 | + |
| 109 | + fs.readFile('index.js', 'utf8', (err, data) => { |
| 110 | + if (err){ |
| 111 | + reject(err); |
| 112 | + throw err; |
| 113 | + } |
| 114 | + const str=`path: '/tabledetail/:id'`; |
| 115 | + let index=data.indexOf(str); |
| 116 | + let begin_index=data.lastIndexOf('{',index); |
| 117 | + let end_index=data.indexOf('}',index)+2; |
| 118 | + |
| 119 | + let begin_str=data.substring(0,begin_index); |
| 120 | + |
| 121 | + let end_str=data.substring(end_index+1); |
| 122 | + |
| 123 | + let final_str=begin_str+end_str; |
| 124 | + |
| 125 | + fs.writeFile('index.js', final_str, (err) => { |
| 126 | + if (err){ |
| 127 | + reject(err); |
| 128 | + throw err; |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | + log(chalk.green('移除 TableDetail 路由成功!')); |
| 133 | + resolve(); |
| 134 | + |
| 135 | + }); |
| 136 | + |
| 137 | + }); |
| 138 | + |
| 139 | + }); |
| 140 | + return promise; |
| 141 | + |
| 142 | + }; |
| 143 | + |
| 144 | +removeDir('./static/bower_components') |
| 145 | + |
| 146 | +.then( |
| 147 | + () => removeDir('./src/views/Table.vue'), |
| 148 | + err => log(chalk.red("删除 Table 文件 失败 ", err)) |
| 149 | +) |
| 150 | + |
| 151 | + |
| 152 | +.then( |
| 153 | + () => removeDir('./src/views/TableDetail.vue'), |
| 154 | + err => log(chalk.red("删除 TableDetail.vue 文件 失败 ", err)) |
| 155 | +) |
| 156 | + |
| 157 | +.then( |
| 158 | + () => removeDir('./src/views/table-expand.vue'), |
| 159 | + err => log(chalk.red("删除 table-expand.vue 文件 失败 ", err)) |
| 160 | +) |
| 161 | + |
| 162 | +.then( |
| 163 | + () => changeTabelRouter(), |
| 164 | + err => log(chalk.red("移除 Table 路由失败 ", err)) |
| 165 | +) |
| 166 | +.then( |
| 167 | + () => changeTabelDetailRouter(), |
| 168 | + err => log(chalk.red("移除 TableDetail 路由失败 ", err)) |
| 169 | +) |
| 170 | + |
| 171 | +.then( |
| 172 | + () => log(chalk.green('移除 Qiniu 插件成功')) |
| 173 | +) |
| 174 | + |
| 175 | +} |
0 commit comments