Skip to content

Instantly share code, notes, and snippets.

@TimRChen
Last active March 12, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimRChen/ec87616f1a985acfea43ac3b2f2a27f8 to your computer and use it in GitHub Desktop.
Save TimRChen/ec87616f1a985acfea43ac3b2f2a27f8 to your computer and use it in GitHub Desktop.
fast coding script use js
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();
@TimRChen
Copy link
Author

快速达到一个demo list 项目的快速启动。在package.json中配置script启动为node run.js即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment