UNPKG

11.5 kBJavaScriptView Raw
1parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"e+FD":[function(require,module,exports) {
2const e=require("get-stream"),r=require("chalk"),s=require("path"),o=process.cwd(),t=require("moment"),n=require("pretty-ms"),c=require("cross-spawn");module.exports=(async({script:e,task:o,type:n=e.type})=>(console.log(`${r.green.bgHex("#181c24").bold(t().format("HH:MM:SS")+" executing ")}${r.bgHex("#181c24").bold.hex("#8c91a7")(o.name+":")} :`),new Promise((r,o)=>{c(n,[...e.rest],{stdio:"inherit",env:Object.assign({},process.env,{FORCE_COLOR:!0,PATH:`${s.resolve("node_modules/.bin")}:${process.env.PATH}`})}).on("close",e=>{0===e?r():o("ERROR --")})})));
3},{}],"J6HI":[function(require,module,exports) {
4const e=require("fs-extra"),r=require("chalk"),t=require("boxen"),a=1/6,n=1/3,o=2/3,c={emptyDir:async r=>{try{await e.emptyDir(r)}catch(t){console.error(t)}}},i=1533,s={mode:1533};c.ensureDir=(async(r,t=s)=>{try{await e.ensureDir(r,t)}catch(a){console.error(a)}}),c.ensureFile=(async r=>{try{await e.ensureFile(r)}catch(t){console.error(t)}}),c.pathExists=(async r=>{return await e.pathExists(r)}),c.readJson=(async r=>{try{return await e.readJson(r)}catch(t){return console.error(t),{}}}),c.readFile=(async r=>{try{return await e.readFileSync(r,"utf8")}catch(t){return console.error(t),{}}}),c.removeFile=(async r=>{try{return await e.remove(r)}catch(t){return console.error(`File ${r} NOT REMOVED! ${t}`),!1}}),c.writeFile=(async(r,t="")=>{try{return await e.outputFile(r,t)}catch(a){console.error(a)}}),c.writeJson=(async(r,t={})=>{try{await e.writeJson(r,t)}catch(a){console.error(a)}}),c.chainAsync=(e=>{let r=0;const t=e[e.length-1],a=()=>{const n=e[r++];n===t?n():n(a)};a()}),c.appendToFile=(async(r,t="")=>{try{await e.appendFileSync(r,t)}catch(a){console.error(a)}}),c.boxInform=(async(e,a="")=>{console.log(t(r.hex("#717877")(e)+r.bold.underline.hex("#438b34")(a)+r.hex("#717877")(" "),{padding:0,margin:{left:2,top:0,bottom:0,right:0},borderStyle:{topLeft:r.hex("#5a596d")("╔"),topRight:r.hex("#5a596d")("╗"),bottomLeft:r.hex("#5a596d")("╚"),bottomRight:r.hex("#5a596d")("╝"),horizontal:r.hex("#5a596d")("═"),vertical:r.hex("#5a596d")("║")},align:"center"}))});const l=(e,r,t)=>(t<0&&(t+=1),t>1&&(t-=1),t<1/6?e+6*(r-e)*t:t<.5?r:t<2/3?e+(r-e)*(2/3-t)*6:e),h=(e,r,t)=>{if(0===r)return new Array(3).fill(t);const a=t<.5?t*r+t:t+r-t*r,n=2*t-a;return[l(n,a,e+1/3),l(n,a,e),l(n,a,e-1/3)]};c.rainbowGradient=((e,r=1,t=.5)=>{const a=[];for(let n=0;n<e;n++)a.push(h(n/e,r,t).map(e=>Math.round(255*e)));return a}),module.exports=c;
5},{}],"gevp":[function(require,module,exports) {
6const e=require("chalk"),r=require("inquirer"),{appendToFile:s,writeFile:n,boxInform:a,readJson:i,readFile:c}=require("./helpers.js"),o=require("path"),t=process.cwd(),p=o.join(t,"package.json"),l={scripts:[]};let h="# First category of scripts\n\n Welcome to your new amazing .fscripts.md file. It replaces the headaches of npm scripts! But so much more.\n\n";l.init=(async()=>{try{l.packageJson=await i(p),Object.keys(l.packageJson.scripts).forEach(e=>{h+=`\n## ${e}\n\nTBD\n\n\`\`\`bash\n${l.packageJson.scripts[e]}\n\`\`\`\n\n`}),await n("./sample.fscripts.md",h)}catch(e){console.error(e)}}),module.exports=l.init;
7},{"./helpers.js":"J6HI"}],"E6PL":[function(require,module,exports) {
8"use strict";const e=require("fs"),t=require("joycon"),s=require("path"),r=require("chalk"),i=new t({stopDir:s.dirname(process.cwd())}),a=require("marked");let p=function(e){let t=a.lexer(e);t=t.filter(e=>"space"!==e.type);let s=[],r={};t.forEach((e,i)=>{if(r.title||1!==e.depth)if(r.title&&1===e.depth){s.push(r),(r={}).title=e.text;let a=t[i+1];r.description=a&&"paragraph"===a.type?a.text:"",r.subitems=[]}else void 0===r.subitems&&(r.subitems=[]),r.subitems.push(e);else{r.title=e.text;let s=t[i+1];r.description=s&&"paragraph"===s.type?s.text:"",r.subitems=[]}}),s.push(r),r={};let i=!1,p={};return s.forEach(e=>{e.tasks={},e.subitems.forEach(t=>{r.title||2!==t.depth?r.title&&2===t.depth?(i=t.text,e.tasks[i]={},p[i]={}):("paragraph"===t.type&&void 0!==e.tasks[i]&&(e.tasks[i].description=t.text),"code"===t.type&&(e.tasks[i].code={type:t.lang,code:t.text},p[i]={script:t.text,type:t.lang})):(i=t.text,e.tasks[i]={})}),delete e.subitems}),{categories:s,allTasks:p}};const l=async()=>{const{path:e,data:t}=i.loadSync(["fscripts.md"]);if(e){console.warn(`${r.bold.green("Located fscripts.md file!")}`);let e=t.replace(/(<!-- toc -->(\s|\S)*?<!-- tocstop -->)/g,"").trim();return p(e)}return console.warn(`${r.bold.red("You're missing the fscripts.md file!")}`),null};module.exports=l;
9},{}],"7oAW":[function(require,module,exports) {
10const e=require("chalk"),t=require("fs"),s=require("path"),i=require("micromatch"),n=require("require-from-string"),a=require("./runCLICommand"),r=require("inquirer"),o=require("moment"),c=()=>(new Date).toTimeString().slice(0,8),l=s.join(process.cwd(),"./.secret.json"),m=" ~ ",u=process.cwd(),p=s.join(u,"./"),f=s.join(u,"./package.json");class h{constructor(e={}){return this.loadAsync(e)}async runTasks(e,t){if(e&&0!==e.length)if(t)await Promise.all(e.map(e=>this.runTask(e)));else for(const s of e)await this.runTask(s)}async runFile(e){await this.runTask("beforeAll",!1),await this.runTask(e),await this.runTask("afterAll",!1)}async runTask(e,t=!0){const s=e&&this.maidfile&&this.maidfile.tasks.find(t=>t.name===e);if(!s){if(!t)return;console.log(`No task called "${e}" was found. Stop.`)}await this.runTaskHooks(s,"before");const i=Date.now();console.log("Starting",'"'+s.name+'..."');for(const n of s.scripts)await this.runScript(n,s);await this.runTaskHooks(s,"after"),console.log("Finished",'"'+s.name+` after ${Date.now()-i} ms`)}runScript(e,t){return new Promise((s,i)=>{const r=e=>{console.log(`Task '${t.name}' failed.\n${e.stack}`)};if(d(e,["sh","bash"]))return a({script:e,task:t,resolve:s,reject:i});if(d(e,["py","python"]))return a({type:"python",script:e,task:t,resolve:s,reject:i});if(d(e,["js","javascript"])){let t;try{t=n(e.src,this.maidfile.filepath)}catch(o){return r(o)}return s("function"==typeof(t=t.default||t)?Promise.resolve(t()).catch(r):t)}return s()})}async runTaskHooks(e,t){const s="before"===t?"pre":"post",i=this.maidfile.tasks.filter(({name:t})=>t===`${s}${e.name}`);await this.runTasks(i.map(e=>e.name));for(const n of e[t]){const{taskNames:e,inParallel:t}=n;await this.runTasks(e,t)}}getHelp(t){const n=(t=[].concat(t)).length>0?this.maidfile.tasks.filter(e=>i.some(e.name,t)):this.maidfile.tasks;0===n.length&&console.log(`No tasks for pattern "${t.join(" ")}" was found. Stop.`),logger.log(`\n ${e.magenta.bold(`Task${n.length>1?"s":""} in ${s.relative(process.cwd(),this.maidfile.filepath)}:`)}\n\n`+n.map(t=>` ${e.bold(t.name)}\n${e.dim(t.description?t.description.split("\n").map(e=>` ${e.trim()}`).join("\n"):" No description")}`).join("\n\n")+"\n")}runList(e){}getList(){this.maidfile.tasks}}function d(e,t){return t.some(t=>t===e.type)}const k=async(e,t)=>new Promise(s=>{let i=[...t,"-------------",...e.categories.map(e=>e.title+" ~ "+e.description)];r.prompt([{type:"list",name:"category",message:"What category do you want to run?",choices:i}]).then(({category:t})=>{let n=i.indexOf("-------------"),a=i.indexOf(t);if(n===a)console.log("Can't select divider");else if(a<n){let e=t.split(" ~ ")[0].trim();s(e)}else{let i=t.split(" ~ ")[0],n=e.categories.findIndex(e=>e.title===i);n=e.categories[n];let a=Object.keys(n.tasks).map(e=>{let t=n.tasks[e];return`${e} ${t.description?" ~ "+t.description.replace(/\n/g," ").trim():""}`});r.prompt([{type:"list",name:"taskToRun",message:"Which task do you want to run",choices:a}]).then(({taskToRun:e})=>{e=e.split(" ~ ")[0].trim(),s(e)})}})});module.exports=k;
11},{"./runCLICommand":"e+FD"}],"Focm":[function(require,module,exports) {
12const t=require("chalk"),e=require("moment"),a=require("./lib/runCLICommand.js"),s=require("./lib/generateFScripts.js"),r=require("./lib/parseScriptsMd.js"),n=require("./lib/taskList"),i=require("path"),l=process.cwd(),c=i.join(l,"./"),o=" ~ ",p=require("conf"),u=new p,m=async()=>{return await r()},w=async()=>{const t=await m(),s=u.get("recentTasks",{});let r=Object.keys(s).map(t=>{return{name:t,lastExecuted:s[t].lastExecuted}}).sort((t,e)=>t.lastExecuted>e.lastExecuted?1:e.lastExecuted>t.lastExecuted?-1:0).reverse().slice(0,3).map(t=>t.name+" ~ "+e(t.lastExecuted).calendar()),i=await n(t,r);void 0===s[i]?s[i]={lastExecuted:Date.now()}:s[i].lastExecuted=Date.now(),u.set("recentTasks",s);let l=t.allTasks[i].script.split(" "),c=l.shift();await a({task:{name:i},script:{type:c,rest:l}})},d=require("yargs").usage("Usage: $0 <command> [options]").scriptName("yarn fsr").example(`${t.rgb(39,173,96)("$0")}`,`${t.rgb(159,161,181)("will open a task selection selector")}`).command("start","Start the scripts!",t=>{},async function(){await w()}).example(`${t.rgb(39,173,96)("$0 start")}`,`${t.rgb(159,161,181)("will open a task selection selector")}`).command("run","Run a specific task",()=>{},async function(t){t._[1]}).example(`${t.rgb(39,173,96)("$0 run start:web")}`,`${t.rgb(159,161,181)("will run task 'start:web'")}`).command("run-s","Series as a sequence",()=>{},async function(t){let e=t._.slice();e.shift();const s=await r();for(let r in e){let t=e[r],n=s.allTasks[t].script.split(" "),i=n.shift();await a({task:{name:t},script:{type:i,rest:n}})}}).example(`${t.rgb(39,173,96)("$0 run-s start:web start:desktop")}`,`${t.rgb(159,161,181)("will run task 'start:web' and afterwards 'start:desktop'")}`).command("clear","Clear history",()=>{},async function(t){let e=t._.slice();e.shift();const s=await r();for(let r in e){let t=e[r],n=s.allTasks[t].script.split(" "),i=n.shift();await a({task:{name:t},script:{type:i,rest:n}})}}).command("generate","Clear history",()=>{},async function(t){await s()}).command("run-p","Run tasks in parallel",()=>{},async function(t){let e=t._.slice();e.shift();const s=await r();for(let r in e){let t=e[r];console.warn("-- Console WHICH",t,s.allTasks[t]);let n=s.allTasks[t].script.split(" "),i=n.shift();a({task:{name:t},script:{type:i,rest:n}})}}).example(`${t.rgb(39,173,96)("$0 run-p start:web start:desktop")}`,`${t.rgb(159,161,181)("will run task 'start:web' and at the same time 'start:desktop'")}`).argv;0===d._.length&&async function(){await w()}();
13},{"./lib/runCLICommand.js":"e+FD","./lib/generateFScripts.js":"gevp","./lib/parseScriptsMd.js":"E6PL","./lib/taskList":"7oAW"}]},{},["Focm"], null)
14//# sourceMappingURL=/index.js.map
\No newline at end of file