UNPKG

@mornya/vessel

Version:

Creates/publishes a Node.js module with no build configuration.

1 lines 3.94 kB
var o=this&&this.__assign||function(){return(o=Object.assign||function(e){for(var t,a=1,o=arguments.length;a<o;a++)for(var i in t=arguments[a])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},i=(Object.defineProperty(exports,"__esModule",{value:!0}),e(require("path"))),r=require("@mornya/cli-libs"),n=e(require("deepmerge")),s=require("../cli"),l=require("../paths");function InitScript(e,t){this.authorName="mornya",this.authorEmail="mornya78@gmail.com",this.option=e}InitScript.prototype.run=function(){this.resolveAuthorProgress(),InitScript.copyOwnTemplateProgress(),this.mergePackageJsonProgress(),InitScript.processTemplateFilesProgress(),InitScript.installNodeModulesProgress()},InitScript.prototype.resolveAuthorProgress=function(){r.Files.isExist(".git")?(this.authorName=r.Command.get("git",["config","--get","user.name"])||r.Command.get("git",["config","--get","--global","user.name"])||this.authorName,this.authorEmail=r.Command.get("git",["config","--get","user.email"])||r.Command.get("git",["config","--get","--global","user.email"])||this.authorEmail):(r.Command.run("git",["init"]),this.authorName=r.Command.get("git",["config","--get","--global","user.name"])||this.authorName,this.authorEmail=r.Command.get("git",["config","--get","--global","user.email"])||this.authorEmail),r.Log.progress("Author information from Git:",r.chalk.magenta("".concat(this.authorName," <").concat(this.authorEmail,">")))},InitScript.copyOwnTemplateProgress=function(){r.Log.progress("Copying own template files..");try{r.Files.copy(l.paths.ownTemplate,l.paths.appPath),r.Files.rimraf("".concat(l.paths.appPath,"/packageJson.js")),r.Files.rimraf("".concat(l.paths.appPath,"/README.md"))}catch(e){console.error(e)}},InitScript.prototype.mergePackageJsonProgress=function(){var e=o({},s.CLI.appPackageJson),t=require(i.default.resolve(l.paths.ownTemplate,"packageJson")),e=(Object.keys(e).length?(r.Log.progress("Merging ".concat(r.chalk.magenta("package.json")," data with own properties.")),e.keywords=r.Utils.removeArrayDups(e.keywords,t.keywords),e.files=r.Utils.removeArrayDups(e.files,t.files),e.browserslist=r.Utils.removeArrayDups(e.browserslist,t.browserslist),e["lint-staged"]&&delete t["lint-staged"],a=(0,n.default)(t,e)):(r.Log.progress("Create a new ".concat(r.chalk.magenta("package.json")," data with own properties.")),(a=t).author="".concat(this.authorName," <").concat(this.authorEmail,">")),this.option.name&&(a.name=this.option.name),this.option.desc&&(a.description=this.option.desc),r.Files.writePrettyJSON(l.paths.appPackageJson,a),"".concat(l.paths.appPath,"/README.md")),a=r.Files.isExist(e)?r.Files.read(e):(r.Log.progress("Generate ".concat(r.chalk.magenta("README.md")," template file..")),r.Files.read("".concat(l.paths.ownTemplate,"/README.md")).replace(/{{PROJECT_NAME}}/g,null!=(t=a.name)?t:"").replace(/{{PROJECT_DESC}}/g,null!=(t=a.description)?t:""));r.Files.write(e,a)},InitScript.processTemplateFilesProgress=function(){["/.eslintignore.template","/.gitignore.template","/.prettierignore.template","/.prettierrc.template"].forEach(function(e){return r.Files.move("".concat(l.paths.appPath).concat(e),"".concat(l.paths.appPath).concat(e.replace(".template","")))})},InitScript.installNodeModulesProgress=function(){r.Log.progress("Installing dependencies.."),r.Command.run("npm",["install","--include=dev","--loglevel=warn","--no-audit","--no-fund"])?(r.Command.run("npm",["run","setup"]),r.Log.success("Initialization completed."),r.Log.info(['Now you can run a command "'.concat(r.chalk.magenta("npm run build"),'" for production build.'),'Also "'.concat(r.chalk.magenta("npm publish"),'" command will publish your project.')]),r.Log.linefeed(),r.Log.out(r.chalk.magenta("🍻 HAPPY HACK!")),r.Log.linefeed()):r.Log.failure("Failed to install dependencies!")},exports.default=InitScript;