UNPKG

minix-template

Version:

minix template

117 lines (111 loc) 3.68 kB
/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const { spawn } = require('child_process'); const fs = require('fs'); const path = require('path'); const FILE_EXT_NAME = []; const red = '\u001b[31m'; const reset = '\u001b[39m'; let input = ''; let output = ''; let manifestFilePath = ''; function copyFile(input, output) { try { if (fs.existsSync(input)) { const parent = path.join(output, '..'); if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { mkDir(parent); } const readStream = fs.createReadStream(input); const writeStream = fs.createWriteStream(output); readStream.pipe(writeStream); readStream.on('close', function () { writeStream.end(); }); } } catch (e) { console.error(red, `Failed to build file ${input}.`, reset); throw e.message; } } function mkDir(path_) { const parent = path.join(path_, '..'); if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) { mkDir(parent); } fs.mkdirSync(path_); } function circularFile(inputPath, outputPath, ext) { const realPath = path.join(inputPath, ext); if (!fs.existsSync(realPath) || realPath === output) { return; } fs.readdirSync(realPath).forEach(function (file_) { const file = path.join(realPath, file_); const fileStat = fs.statSync(file); if (fileStat.isFile()) { const baseName = path.basename(file); const extName = path.extname(file); if (FILE_EXT_NAME.indexOf(extName) < 0 && baseName !== '.DS_Store') { const outputFile = path.join(outputPath, ext, path.basename(file_)); if (outputFile === path.join(output, 'manifest.json')) { return; } if (fs.existsSync(outputFile)) { const outputFileStat = fs.statSync(outputFile); if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) { copyFile(file, outputFile); } } else { copyFile(file, outputFile); } } } else if (fileStat.isDirectory()) { circularFile(inputPath, outputPath, path.join(ext, file_)); } }); } function copyManifest() { copyFile(manifestFilePath, path.join(output, 'manifest.json')); } class RunPlugin { constructor(input_, output_, manifestFilePath_) { console.log(input, output); input = input_; output = output_; manifestFilePath = manifestFilePath_; } apply(compiler) { var execObj = null; compiler.hooks.done.tap('RunPlugin', () => { if (execObj != null) { setTimeout(function () { console.log('kill pid:', execObj.pid); execObj.kill() }, 300) } circularFile(input, output, ''); copyManifest(); if (fs.existsSync(path.join(output, 'app.js'))) { fs.utimesSync(path.join(output, 'app.js'), new Date(), new Date()); } setTimeout(function () { // 配置本地电脑模拟器存放的路径 execObj = spawn('D:/Mydata/liangzh36/Desktop/架构研究/common/ace_test_windows_phone.exe'); }, 300) }); } } module.exports = RunPlugin;