Last active
March 12, 2020 10:44
-
-
Save TimRChen/ec87616f1a985acfea43ac3b2f2a27f8 to your computer and use it in GitHub Desktop.
fast coding script use js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { prompt } = require("inquirer"); | |
const { readdirSync } = require("fs"); | |
const { exec } = require("child_process"); | |
async function run() { | |
const folder = `${__dirname}/public`; | |
const choices = await readdirSync(folder); | |
const promptList = [ | |
{ | |
type: "rawlist", | |
name: "filename", | |
message: "Enter filename", | |
pageSize: 10, | |
highlight: true, | |
searchable: true, | |
choices, | |
source: function(answersSoFar, input) { | |
input = input || ""; | |
return new Promise(function(resolve) { | |
const fuzzyResult = fuzzy.filter(input, filename); | |
const data = fuzzyResult.map(function(element) { | |
return element.original; | |
}); | |
resolve(data); | |
}); | |
} | |
} | |
]; | |
function handleAnswers(answers) { | |
const { filename } = answers; | |
const execCmd = `parcel public/${filename}`; | |
console.log(execCmd); | |
const dev = exec(execCmd); | |
dev.stdout.pipe(process.stdout); | |
dev.stderr.pipe(process.stderr); | |
dev.on("close", code => { | |
console.log(`child process exited with code ${code}`); | |
}); | |
} | |
prompt(promptList).then(handleAnswers); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
快速达到一个demo list 项目的快速启动。在package.json中配置script启动为node run.js即可