@stories-js/cli
Version:
Stories CLI to manage list of stories in UI
4 lines (3 loc) • 4.75 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fs"),require("chokidar"),require("yargs"),require("yargs/helpers"),require("path"),require("fast-glob")):"function"==typeof define&&define.amd?define(["exports","fs","chokidar","yargs","yargs/helpers","path","fast-glob"],t):t((e||self).cli={},e.fs,e.chokidar,e.yargs,e.helpers,e.path,e.fastGlob)}(this,function(e,t,r,o,n,i,a){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u,p=s(r),c=s(o),l=s(a),f=process.cwd(),d="./stories-list.js",h=["**/*.stories.tsx","**/*.stories.ts","**/*.stories.jsx","**/*.stories.js"],m=c.default(n.hideBin(process.argv)).command("scan <patterns...>","Search and save list of stories in file",function(e){return e.option("output",{describe:"The relative path to file to save output.",default:d,type:"string"}).option("from",{describe:"The path to search from & generate imports",default:f,type:"string"}).option("dryRun",{describe:"Set this to avoid writing any files.",default:!1,type:"boolean"}).option("quiet",{describe:"Hide all logs",default:!1,type:"boolean"}).option("_",{describe:"Search patterns",default:h,type:"string"})}).example("$0 **/*.stories.tsx","Search by pattern").example("$0 --from ./src","Search in folder and all subfolders").example("$0 --output ./stories-list.js","Save output stories list in file").example("$0 --dryRun","Run but do not save output").example("$0 --quiet","Suppress logs messages").version("version","0.2.0").argv,v={dryRun:m.dryRun||!1,quiet:m.quiet||!1,from:m.from||f,output:m.output||d,search:(u=m._,u.length>0?u:h)};function g(){return g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},g.apply(this,arguments)}var y=function(){return y=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},y.apply(this,arguments)};function b(e){return e.toLowerCase()}var P=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],j=/[^A-Z0-9]+/gi;function x(e,t,r){return t instanceof RegExp?e.replace(t,r):t.reduce(function(e,t){return e.replace(t,r)},e)}function R(e,t){var r=e.charAt(0),o=e.substr(1).toLowerCase();return t>0&&r>="0"&&r<="9"?"_"+r+o:""+r.toUpperCase()+o}function S(e,t){return 0===t?e.toLowerCase():R(e,t)}function w(e){var t=new Set,r=e.map(function(e,r){var o=i.parse(e),n=function(e,t){return void 0===t&&(t={}),function(e,t){return void 0===t&&(t={}),function(e,t){void 0===t&&(t={});for(var r=t.splitRegexp,o=t.stripRegexp,n=void 0===o?j:o,i=t.transform,a=void 0===i?b:i,s=t.delimiter,u=void 0===s?" ":s,p=x(x(e,void 0===r?P:r,"$1\0$2"),n,"\0"),c=0,l=p.length;"\0"===p.charAt(c);)c++;for(;"\0"===p.charAt(l-1);)l--;return p.slice(c,l).split("\0").map(a).join(u)}(e,y({delimiter:"",transform:R},t))}(e,y({transform:S},t))}(o.name);t.has(n)?t.add(n+"_"+r):t.add(n);var a=i.format(g({},o,{base:void 0,ext:void 0}));return a.startsWith(".")||(a="."+i.sep+a),{name:n,originalPath:e,importPath:a}});return r}function q(e){return e.split(i.sep).join(i.posix.sep)}var A=function(e){try{return $(e),Promise.resolve(function(e){var t=e.rootPath,r=e.patterns,o=e.outputPath,n=e.ignorePaths;try{var a=i.resolve(t);return Promise.resolve(l.default(r,{absolute:!0,caseSensitiveMatch:!1,ignore:n,cwd:a})).then(function(e){var r=e.map(q),n=i.resolve(t,o),s=i.dirname(n),u=r.map(function(e){return i.relative(s,e)});return{paths:r,searchFrom:a,outputFilePath:n,importPaths:u}})}catch(e){return Promise.reject(e)}}({rootPath:v.from,patterns:v.search,outputPath:v.output,ignorePaths:O})).then(function(e){var r=e.outputFilePath,o=e.importPaths;$("Saving to: "+r);var n,i=["/* NOTE: This is an autogenerated file; please do not edit. */\n",(n=w(o)).map(function(e){return"import * as "+e.name+" from '"+e.importPath+"'"}).join(";\n"),"","const modules = [",n.map(function(e){return" "+e.name+","}).join("\n"),"];\n","export default modules;"].join("\n");v.dryRun||(t.writeFileSync(r,i,"utf8"),$("Saved.")),$(""),(v.quiet||v.dryRun)&&console.log(i)})}catch(e){return Promise.reject(e)}},O=["**/node_modules/**"],$=v.dryRun?function(){}:console.log;e.scan=function(){$("\nLooking stories in "+v.from),$("Search patterns are "+v.search+"\n"),v.dryRun&&$("Dry run."),p.default.watch(v.search,{cwd:v.from,usePolling:!0,interval:2e3,binaryInterval:2e3}).on("error",function(e){return $("Watcher error: "+e)}).on("add",function(e){return Promise.resolve(A("Added "+e))}).on("change",function(e){return Promise.resolve(A("Change "+e))}).on("unlink",function(e){return Promise.resolve(A("Removed "+e))})}});
//# sourceMappingURL=cli.umd.js.map