UNPKG

matron

Version:

> A Domain Specific Language à-la Dockerfile with a CLI to scaffold your projects.

1 lines 44.3 kB
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///external \"path\"","webpack:///external \"fs\"","webpack:///external \"xstate\"","webpack:///external \"chalk\"","webpack:///external \"@reduxjs/toolkit\"","webpack:///external \"fs-extra\"","webpack:///external \"yargs\"","webpack:///external \"morphism\"","webpack:///external \"uuid/v4\"","webpack:///external \"js-yaml\"","webpack:///external \"ajv\"","webpack:///external \"cross-spawn\"","webpack:///external \"deepmerge\"","webpack:///external \"dotenv-flow\"","webpack:///./src/core/parser/parser.ts","webpack:///./src/core/parser/parser.types.ts","webpack:///./src/core/stateMachine.ts","webpack:///./src/cli/utilities/log.ts","webpack:///./src/cli/utilities/errors.ts","webpack:///./src/core/runner.ts","webpack:///./src/cli/commands/create/create.ts","webpack:///./src/cli/commands/create/index.ts","webpack:///./src/cli/index.ts"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","require","toCommand","morphism","createSchema","cmd","step","keys","args","argsStr","values","split","parser","content","doc","yaml","safeLoad","error","loadMatronDocument","validate","Ajv","compile","jsonSchema","LinterError","errors","lint","entries","jobs","map","job","steps","Error","constructor","super","JSON","stringify","evaluate","command","commandString","join","evaluatedCommandString","regex","parameters","matches","exec","index","lastIndex","groups","param","push","getCommandParameters","reduce","acc","process","env","undefined","replace","CommandType","log","actions","ActionType","createAction","SET_WORKDIR","startParse","START_PARSE","executeJob","START_EXECUTE","EXECUTE_COMMAND","EXECUTE_JOB","getStateMachineInterpreter","options","defaultOptions","executionPath","assign","matronMachine","createMachine","id","strict","initial","context","config","matronFile","path","text","byId","allIds","commands","states","idle","on","target","event","payload","matronFilePath","parse","entry","loadingMatronFile","invoke","src","loadFile","Promise","resolve","readFileSync","onDone","data","extractJobs","commandItemsByJobId","jobItems","jobId","uuidv4","rawCommand","evaluatedCommand","executed","commandItem","reject","jobItem","allCommandsItems","commandItems","execute","commandId","forEach","RUN","spawnCommand","slice","toSpawnCommand","spawn","sync","stdio","cwd","WORKDIR","MERGE_JSON","sourcePath","dirname","destinationPath","jsonSource","fs","jsonDest","mergedJson","merge","writeFileSync","COPY","fse","copySync","final","interpret","start","Color","fmtError","message","finalMessage","cur","idx","chalk","hex","Red","bold","GenericError","this","MatronFileMissingError","ArgsConflictError","RequiredArgsError","NotAFolderError","arg","FolderNotExistsError","NotAFileError","FileNotExistsError","run","matronFileRelativePath","dotEnvFolderRelativePath","templateFolderRelativePath","matronFileAbsolutePath","validateRequiredArgs","templateFolderAbsolutePath","getAbsolutePath","existsSync","setupEnvironmentVariables","matronService","subscribe","state","remainingJobs","filter","length","send","relativePath","dotEnvFolderAbsolutePath","result","dotenv","CommandOptions","checkRequiredArgs","MatronFile","Template","checkEnvFolder","EnvFolder","absolutePath","lstatSync","isDirectory","checkMatronFile","isFile","checkProjectPath","projectRelativePath","ProjectPath","describe","builder","yargs","usage","green","alias","type","check","version","handler","help","wrap","terminalWidth","showHelpOnFail","demandCommand","recommendCommands","argv"],"mappings":";6DACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QA0Df,OArDAF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBk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oBsB,yBCnBtBC,QDoBsBC,GACfA,EACJC,MACE,cAEHpD,IAAMqD,MAAM,kDACZrD,IAAMqD,MAAM,gFAGXvI,QAAQ,CACP,CAACqH,EAAea,aAAc,CAC5BM,MAAO,IACPL,SAAU,yCACVM,KAAM,UAER,CAACpB,EAAeG,UAAW,CACzBgB,MAAO,IACPL,SAAU,gDACVM,KAAM,UAER,CAACpB,EAAeE,YAAa,CAC3BiB,MAAO,IACPL,SAAU,oBACVM,KAAM,UAER,CAACpB,EAAeK,WAAY,CAC1BS,SAAU,qBACVM,KAAM,YAGTC,MAAMpB,GACNoB,MAAMjB,IACNiB,MAAMZ,IACNY,MAAMV,IACNW,SAAQ,GCrDXC,QDuDsB1M,IACtB,MAAM+J,EAAyB/J,EAAKmL,EAAeE,YAC7CrB,EAA2BhK,EAAKmL,EAAeK,WAC/CvB,EAA6BjK,EAAKmL,EAAeG,UACjDS,EAAsB/L,EAAKmL,EAAea,aAE5CD,IACFlJ,QAAQC,IAAR,aAAgCiJ,GAElCjC,EAAI,CAAEE,2BAA0BC,6BAA4BF,6BEnExDqC,GAAS,cAEXpD,IAAMqD,MAAM,kDACZrD,IAAMqD,MAAM,+EAGhBF,IACGC,MAAMA,IACNO,OACAC,KAAKT,IAAMU,iBACXC,gBAAe,GACfjL,QAAQ9C,IACRgO,gBACAC,oBACA3I,SAAS4I","file":"matron.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 15);\n","module.exports = require(\"path\");","module.exports = require(\"fs\");","module.exports = require(\"xstate\");","module.exports = require(\"chalk\");","module.exports = require(\"@reduxjs/toolkit\");","module.exports = require(\"fs-extra\");","module.exports = require(\"yargs\");","module.exports = require(\"morphism\");","module.exports = require(\"uuid/v4\");","module.exports = require(\"js-yaml\");","module.exports = require(\"ajv\");","module.exports = require(\"cross-spawn\");","module.exports = require(\"deepmerge\");","module.exports = require(\"dotenv-flow\");","import yaml from 'js-yaml';\nimport { readFileSync } from 'fs';\nimport { morphism, createSchema } from 'morphism';\nimport Ajv, { ValidationError } from 'ajv';\nimport fse from 'fs-extra';\nimport path from 'path';\nimport jsonSchema from './schema.json';\nimport { Command, CommandType, Job, MatronDocumentJobStep, MatronDocument } from './parser.types';\n\nexport function loadFile(path: string) {\n return Promise.resolve(readFileSync(path, 'utf8'));\n}\nconst toCommand = morphism(\n createSchema<Command, MatronDocumentJobStep>({\n cmd: step => {\n return Object.keys(step)[0] as CommandType;\n },\n args: step => {\n const argsStr = Object.values(step)[0];\n if (argsStr) {\n const args = argsStr.split(' ');\n return args;\n } else {\n return [];\n }\n }\n })\n);\n\nexport function loadMatronDocument(content: string): MatronDocument {\n try {\n return yaml.safeLoad(content);\n } catch (error) {\n throw error;\n }\n}\nexport function parser(content: string): Job[] {\n const doc = loadMatronDocument(content);\n lint(doc);\n return Object.entries(doc.jobs).map(([key, job]) => {\n return {\n key,\n name: job.name,\n steps: toCommand(job.steps)\n };\n });\n}\n\nexport function lint(doc: MatronDocument) {\n const ajv = new Ajv();\n const validate = ajv.compile(jsonSchema);\n const isValid = validate(doc);\n if (!isValid) {\n throw new LinterError(validate.errors!);\n }\n}\n\nclass LinterError extends Error {\n constructor(errors: Ajv.ErrorObject[]) {\n const message = `\nUnable to validate the Matron file.\n Errors: ${JSON.stringify(errors, null, 2)}\n `;\n super(message);\n }\n}\n\nfunction getCommandParameters(commandString: string) {\n const regex = /\\${(?<param>\\w+)}/gm;\n const parameters: string[] = [];\n let matches;\n while ((matches = regex.exec(commandString)) !== null) {\n if (matches.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n if (matches.groups && matches.groups.param) parameters.push(matches.groups.param);\n }\n\n return parameters;\n}\n\nexport function evaluate(command: Command): Command {\n const commandString = command.args.join(' ');\n const params = getCommandParameters(commandString);\n const evaluatedCommandString = params.reduce((acc, param) => {\n const value = process.env[param];\n if (value === undefined) throw new Error(`Parameter ${param} is not defined.`);\n return acc.replace(`\\${${param}}`, value);\n }, commandString);\n return {\n cmd: command.cmd,\n args: evaluatedCommandString.split(' ')\n };\n}\n\ninterface SpawnCommand {\n cmd: string;\n args: string[];\n}\n\nexport function toSpawnCommand(command: Command): SpawnCommand {\n return {\n cmd: command.args[0],\n args: command.args.slice(1)\n };\n}\n","export interface Job {\n key: string;\n name?: string;\n steps: Command[];\n}\n\nexport interface Command {\n cmd: keyof typeof CommandType;\n args: string[];\n}\n\nexport enum CommandType {\n COPY = 'COPY',\n RUN = 'RUN',\n WORKDIR = 'WORKDIR',\n MERGE_JSON = 'MERGE_JSON'\n}\n\nexport type MatronDocumentJobStep = { [key in CommandType]?: string };\nexport interface MatronDocumentJob {\n name?: string;\n steps: MatronDocumentJobStep[];\n}\nexport type MatronDocumentJobs = { [key: string]: MatronDocumentJob };\nexport interface MatronDocument {\n jobs: MatronDocumentJobs;\n}\n","import { interpret, createMachine, assign, actions } from 'xstate';\nimport { createAction } from '@reduxjs/toolkit';\nimport { parser, loadFile, evaluate, toSpawnCommand } from './parser/parser';\nimport spawn from 'cross-spawn';\nimport uuidv4 from 'uuid/v4';\nimport merge from 'deepmerge';\nimport path from 'path';\nimport fs from 'fs';\nimport fse from 'fs-extra';\nimport { Command, CommandType } from './parser/parser.types';\n\nconst { log } = actions;\n\nenum ActionType {\n SET_WORKDIR = 'SET_WORKDIR',\n START_PARSE = 'START_PARSE',\n START_EXECUTE = 'START_EXECUTE',\n EXECUTE_COMMAND = 'EXECUTE_COMMAND',\n EXECUTE_JOB = 'EXECUTE_JOB',\n EXECUTE_COMMANDS = 'EXECUTE_COMMANDS'\n // LOG= 'LOG'\n}\n\nexport const setWorkdir = createAction<{ path: string }, ActionType.SET_WORKDIR>(ActionType.SET_WORKDIR);\nexport const startParse = createAction<{ matronFilePath: string }, ActionType.START_PARSE>(ActionType.START_PARSE);\nexport const startExecute = createAction<{ commands: Command[] }, ActionType.START_EXECUTE>(ActionType.START_EXECUTE);\nexport const executeCommand = createAction<{ commandItem: CommandItem }, ActionType.EXECUTE_COMMAND>(ActionType.EXECUTE_COMMAND);\nexport const executeJob = createAction<{ jobItem: JobItem }, ActionType.EXECUTE_JOB>(ActionType.EXECUTE_JOB);\n// export const log = createAction<{ message: string }, ActionType.LOG>(ActionType.LOG);\n\n// export const executeCommands = createAction<undefined, ActionType.EXECUTE_COMMANDS>(ActionType.EXECUTE_COMMANDS);\n\ntype MatronActions =\n | ReturnType<typeof setWorkdir>\n | ReturnType<typeof startParse>\n | ReturnType<typeof startExecute>\n | ReturnType<typeof executeCommand>\n // | ReturnType<typeof executeCommands>\n | ReturnType<typeof executeJob>;\n\ninterface MatronOptions {\n executionPath?: string;\n}\n\ninterface CommandItem {\n id: string;\n executed: boolean;\n rawCommand: Command;\n evaluatedCommand: Command;\n}\n\nexport interface NormalizedState<T> {\n byId: Record<string, T>;\n allIds: string[];\n}\n\ninterface JobItem {\n id: string;\n key: string;\n name?: string;\n commands: string[];\n executed: boolean;\n}\n\ninterface MatronContext {\n config: {\n executionPath: string;\n matronFile: {\n path: string;\n text: string;\n };\n };\n jobs: NormalizedState<JobItem>;\n commands: NormalizedState<CommandItem>;\n}\n\nexport function getStateMachineInterpreter(options: MatronOptions) {\n const defaultOptions = {\n executionPath: './'\n };\n Object.assign(defaultOptions, options);\n const matronMachine = createMachine<MatronContext, MatronActions>({\n id: 'matron',\n strict: true,\n initial: 'idle',\n context: {\n config: {\n ...defaultOptions,\n matronFile: { path: '', text: '' }\n },\n jobs: { byId: {}, allIds: [] },\n commands: { byId: {}, allIds: [] }\n },\n\n states: {\n idle: {\n on: {\n START_PARSE: {\n target: 'parse',\n actions: assign({\n config: (context, event) => {\n return {\n ...context.config,\n matronFile: {\n ...context.config.matronFile,\n path: event.payload.matronFilePath\n }\n };\n }\n })\n }\n }\n },\n parse: {\n initial: 'loadingMatronFile',\n entry: log(() => 'Parsing Matron file'),\n states: {\n loadingMatronFile: {\n invoke: {\n id: 'loadingMatronFile',\n src: context => loadFile(context.config.matronFile.path),\n onDone: {\n target: 'extractJobs',\n actions: assign({\n config: (context, event) => {\n return {\n ...context.config,\n matronFile: {\n ...context.config.matronFile,\n text: event.data\n }\n };\n }\n })\n }\n }\n },\n extractJobs: {\n invoke: {\n id: 'extractJobs',\n src: context => {\n const matronFileText = context.config.matronFile.text;\n\n const jobs = parser(matronFileText);\n const commandItemsByJobId: Record<string, CommandItem[]> = {};\n try {\n const jobItems = jobs.map<JobItem>(job => {\n const jobId = uuidv4();\n commandItemsByJobId[jobId] = job.steps.map(step => {\n return { id: uuidv4(), rawCommand: step, evaluatedCommand: evaluate(step), executed: false };\n });\n return {\n id: jobId,\n key: job.key,\n name: job.name,\n commands: commandItemsByJobId[jobId].map(commandItem => commandItem.id),\n executed: false\n };\n });\n return Promise.resolve({ jobItems, commandItemsByJobId });\n } catch (error) {\n return Promise.reject(error);\n }\n },\n onDone: {\n target: '#matron.execute',\n actions: assign({\n jobs: (context, event) => {\n const { jobItems }: { jobItems: JobItem[]; commandItemsByJobId: Record<string, CommandItem[]> } = event.data;\n return {\n byId: {\n ...context.jobs.byId,\n ...jobItems.reduce<MatronContext['jobs']['byId']>((acc, jobItem) => {\n acc[jobItem.id] = jobItem;\n return acc;\n }, {})\n },\n allIds: [...context.jobs.allIds, ...jobItems.map(jobItem => jobItem.id)]\n };\n },\n commands: (context, event) => {\n const { commandItemsByJobId }: { jobItems: JobItem[]; commandItemsByJobId: Record<string, CommandItem[]> } = event.data;\n const allCommandsItems = Object.values(commandItemsByJobId).reduce<CommandItem[]>((acc, commandItems) => {\n acc.push(...commandItems);\n return acc;\n }, []);\n return {\n byId: {\n ...context.commands.byId,\n ...allCommandsItems.reduce<MatronContext['commands']['byId']>((acc, commandItem) => {\n acc[commandItem.id] = commandItem;\n return acc;\n }, {})\n },\n allIds: [...context.commands.allIds, ...allCommandsItems.map(commandItem => commandItem.id)]\n };\n }\n })\n }\n }\n }\n }\n },\n execute: {\n entry: [log(() => 'Executing Jobs')],\n on: {\n EXECUTE_JOB: {\n actions: [\n log((context, event) => {\n const {\n payload: { jobItem }\n } = event;\n const message = jobItem.name ? jobItem.name : `Running Job ${jobItem.key}`;\n return message;\n }),\n (context, event) => {\n const {\n payload: { jobItem }\n } = event;\n\n const commandItems = jobItem.commands.map(commandId => context.commands.byId[commandId]);\n commandItems.forEach(commandItem => {\n switch (commandItem.evaluatedCommand.cmd) {\n case CommandType.RUN:\n {\n const spawnCommand = toSpawnCommand(commandItem.evaluatedCommand);\n spawn.sync(spawnCommand.cmd, spawnCommand.args, {\n stdio: 'inherit',\n cwd: context.config.executionPath\n });\n }\n break;\n case CommandType.WORKDIR:\n {\n context.config.executionPath = commandItem.evaluatedCommand.args[0];\n }\n break;\n case CommandType.MERGE_JSON:\n {\n const sourcePath = path.join(path.dirname(context.config.matronFile.path), commandItem.evaluatedCommand.args[0]);\n\n const destinationPath = path.join(\n process.cwd(),\n context.config.executionPath,\n commandItem.evaluatedCommand.args[1]\n );\n const jsonSource = JSON.parse(fs.readFileSync(sourcePath, 'utf8'));\n const jsonDest = JSON.parse(fs.readFileSync(destinationPath, 'utf8'));\n const mergedJson = merge(jsonSource, jsonDest);\n fs.writeFileSync(destinationPath, JSON.stringify(mergedJson, null, 2));\n }\n break;\n case CommandType.COPY:\n {\n const sourcePath = path.join(path.dirname(context.config.matronFile.path), commandItem.evaluatedCommand.args[0]);\n const destinationPath = path.join(\n process.cwd(),\n context.config.executionPath,\n commandItem.evaluatedCommand.args[1]\n );\n fse.copySync(sourcePath, destinationPath);\n }\n break;\n default:\n break;\n }\n });\n },\n assign({\n jobs: (context, event) => {\n const {\n payload: { jobItem }\n } = event;\n return {\n byId: {\n ...context.jobs.byId,\n [jobItem.id]: {\n ...context.jobs.byId[jobItem.id],\n executed: true\n }\n },\n allIds: context.jobs.allIds\n };\n },\n commands: (context, event) => {\n const {\n payload: { jobItem }\n } = event;\n const commandItems = jobItem.commands.map(commandId => context.commands.byId[commandId]);\n return {\n byId: {\n ...context.commands.byId,\n ...commandItems.reduce<Record<string, CommandItem>>((acc, commandItem) => {\n acc[commandItem.id] = {\n ...commandItem,\n executed: true\n };\n return acc;\n }, {})\n },\n allIds: context.commands.allIds\n };\n }\n })\n ]\n }\n }\n },\n final: {}\n },\n on: {\n SET_WORKDIR: {\n actions: assign({\n config: (context, event) => {\n return {\n ...context.config,\n executionPath: event.payload.path\n };\n }\n })\n }\n }\n });\n\n const matronService = interpret(matronMachine);\n return matronService.start();\n}\n","import chalk from 'chalk';\n\nenum Color {\n Blue = '#4285f4',\n Green = '#34a853',\n Yellow = '#fbbc05',\n Red = '#ea4335'\n}\n\nexport function fmtError(message: TemplateStringsArray, ...values: any) {\n const finalMessage = message.reduce((acc, cur, idx) => {\n acc += cur;\n acc += values[idx] !== undefined ? values[idx] : '';\n return acc;\n }, '');\n return chalk.hex(Color.Red).bold(finalMessage);\n}\n","import { fmtError } from './log';\n\nexport class GenericError extends Error {\n constructor(message: string) {\n super(fmtError`${message}`);\n this.name = 'GenericError';\n }\n}\n\nexport class MatronFileMissingError extends Error {\n constructor(path: string) {\n super(fmtError`Unable to locate a 'matron.yml' file at ${path}`);\n this.name = 'MatronFileMissingError';\n }\n}\n\nexport class ArgsConflictError extends Error {\n constructor(...args: string[]) {\n super(fmtError`Arguments ${args.join(', ')} can't be use jointly. You might choose between one of them.`);\n this.name = 'ArgsConflictError';\n }\n}\n\nexport class RequiredArgsError extends Error {\n constructor(...args: string[]) {\n const argsList = args.reduce((acc, cur) => {\n acc += `\\n - ${cur}`;\n return acc;\n }, '');\n const message = `\nOne argument below is required: ${argsList}\n`;\n super(fmtError`${message}`);\n this.name = 'RequiredArgsError';\n }\n}\n\nexport class NotAFolderError extends Error {\n constructor(path: string, arg: string) {\n super(fmtError`Path ${path} provided to '${arg}' is not a folder.`);\n this.name = 'NotAFolderError';\n }\n}\n\nexport class FolderNotExistsError extends Error {\n constructor(path: string, arg: string) {\n super(fmtError`Folder ${path} provided to '${arg}' does not exists.`);\n this.name = 'FolderNotExistsError';\n }\n}\n\nexport class NotAFileError extends Error {\n constructor(path: string, arg: string) {\n super(fmtError`Path ${path} provided to '${arg}' is not a file.`);\n this.name = 'NotAFileError';\n }\n}\n\nexport class FileNotExistsError extends Error {\n constructor(path: string, arg: string) {\n super(fmtError`File ${path} provided to '${arg}' does not exists.`);\n this.name = 'FileNotExistsError';\n }\n}\n","import { getStateMachineInterpreter, startParse, executeJob } from './stateMachine';\nimport dotenv from 'dotenv-flow';\nimport path from 'path';\nimport { ArgsConflictError, RequiredArgsError, MatronFileMissingError, GenericError } from '../cli/utilities/errors';\nimport fse from 'fs-extra';\n\ninterface RunnerOptions {\n matronFileRelativePath?: string;\n dotEnvFolderRelativePath?: string;\n templateFolderRelativePath?: string;\n}\nexport function run(options: RunnerOptions) {\n const { matronFileRelativePath, dotEnvFolderRelativePath, templateFolderRelativePath } = options;\n let matronFileAbsolutePath: string | undefined;\n\n if (validateRequiredArgs({ matronFileRelativePath, templateFolderRelativePath })) {\n if (templateFolderRelativePath) {\n const templateFolderAbsolutePath = getAbsolutePath(templateFolderRelativePath);\n\n if (!fse.existsSync(path.join(templateFolderAbsolutePath, './matron.yml'))) {\n throw new MatronFileMissingError(templateFolderAbsolutePath);\n } else {\n matronFileAbsolutePath = path.join(templateFolderAbsolutePath, './matron.yml');\n }\n setupEnvironmentVariables(templateFolderAbsolutePath);\n }\n\n if (matronFileRelativePath) {\n matronFileAbsolutePath = getAbsolutePath(matronFileRelativePath);\n\n if (dotEnvFolderRelativePath) {\n const dotEnvFolderAbsolutePath = getAbsolutePath(dotEnvFolderRelativePath);\n setupEnvironmentVariables(dotEnvFolderAbsolutePath);\n }\n }\n\n if (matronFileAbsolutePath) {\n const matronService = getStateMachineInterpreter({});\n matronService.subscribe(state => {\n if (state.value === 'execute') {\n const jobs = state.context.jobs;\n const remainingJobs = Object.values(jobs.byId).filter(job => !job.executed);\n if (remainingJobs.length > 0) {\n matronService.send(executeJob({ jobItem: remainingJobs[0] }));\n }\n }\n });\n matronService.send(startParse({ matronFilePath: matronFileAbsolutePath }));\n } else {\n throw new GenericError(`\nUnable to find a matron.yml file with the following parameters:\n - matronFileRelativePath: ${matronFileRelativePath}\n - dotEnvFolderRelativePath: ${dotEnvFolderRelativePath}\n - templateFolderRelativePath: ${templateFolderRelativePath}\n `);\n }\n }\n}\n\ninterface RequiredArgs {\n matronFileRelativePath?: string;\n templateFolderRelativePath?: string;\n}\nfunction validateRequiredArgs(args: RequiredArgs) {\n const { matronFileRelativePath, templateFolderRelativePath } = args;\n if (matronFileRelativePath && templateFolderRelativePath) {\n throw new ArgsConflictError('matronFileRelativePath', 'templateFolderRelativePath');\n } else if (!matronFileRelativePath && !templateFolderRelativePath) {\n throw new RequiredArgsError('matronFileRelativePath', 'templateFolderRelativePath');\n } else {\n return true;\n }\n}\n\nfunction getAbsolutePath(relativePath: string) {\n return path.join(process.cwd(), relativePath);\n}\n\nfunction setupEnvironmentVariables(dotEnvFolderAbsolutePath: string) {\n const result = dotenv.config({\n path: dotEnvFolderAbsolutePath\n });\n if (result.error) {\n throw result.error;\n }\n}\n","import { Argv } from 'yargs';\nimport { run } from '../../../core/runner';\nimport { existsSync, lstatSync } from 'fs';\nimport path from 'path';\nimport chalk from 'chalk';\nimport {\n NotAFolderError,\n FolderNotExistsError,\n NotAFileError,\n FileNotExistsError,\n ArgsConflictError,\n RequiredArgsError,\n GenericError\n} from '../../utilities/errors';\n\nconst PROJECT_PATH_VAR = 'PROJECT_PATH';\n\nexport enum CommandOptions {\n ProjectPath = 'project',\n Template = 'template',\n MatronFile = 'matron-file',\n EnvFolder = 'env-folder'\n}\nexport const command = 'create';\nexport const describe = 'Scaffold a new project';\nexport const builder = (yargs: Argv) => {\n return yargs\n .usage(\n `\nUsage\n ${chalk.green('matron')} create --matron-file=./matron.yml\n ${chalk.green('matron')} create --matron-file=./matron.yml --env-folder ./dotenv/folder\n `\n )\n .options({\n [CommandOptions.ProjectPath]: {\n alias: 'p',\n describe: 'Name or Path of the project to create.',\n type: 'string'\n },\n [CommandOptions.Template]: {\n alias: 't',\n describe: 'Folder containing at least a matron.yml file.',\n type: 'string'\n },\n [CommandOptions.MatronFile]: {\n alias: 'f',\n describe: 'Matron file path.',\n type: 'string'\n },\n [CommandOptions.EnvFolder]: {\n describe: '.env files folder.',\n type: 'string'\n }\n })\n .check(checkRequiredArgs)\n .check(checkEnvFolder)\n .check(checkMatronFile)\n .check(checkProjectPath)\n .version(false);\n};\nexport const handler = (args: Arguments) => {\n const matronFileRelativePath = args[CommandOptions.MatronFile];\n const dotEnvFolderRelativePath = args[CommandOptions.EnvFolder];\n const templateFolderRelativePath = args[CommandOptions.Template];\n const projectRelativePath = args[CommandOptions.ProjectPath];\n\n if (projectRelativePath) {\n process.env[PROJECT_PATH_VAR] = projectRelativePath;\n }\n run({ dotEnvFolderRelativePath, templateFolderRelativePath, matronFileRelativePath });\n};\n\nexport type CommandBuilder = typeof builder;\nexport type Arguments = ReturnType<CommandBuilder>['argv'];\n\nfunction checkRequiredArgs(args: any) {\n const matronFileRelativePath = args[CommandOptions.MatronFile] as string;\n const templateFolderRelativePath = args[CommandOptions.Template] as string;\n if (matronFileRelativePath && templateFolderRelativePath) {\n throw new ArgsConflictError(CommandOptions.MatronFile, CommandOptions.Template);\n } else if (!matronFileRelativePath && !templateFolderRelativePath) {\n throw new RequiredArgsError(CommandOptions.MatronFile, CommandOptions.Template);\n } else {\n return true;\n }\n}\nfunction checkEnvFolder(args: any) {\n const dotEnvFolderRelativePath = args[CommandOptions.EnvFolder] as string;\n if (dotEnvFolderRelativePath) {\n const absolutePath = path.join(process.cwd(), dotEnvFolderRelativePath);\n if (existsSync(absolutePath)) {\n if (lstatSync(absolutePath).isDirectory()) {\n return true;\n } else {\n throw new NotAFolderError(absolutePath, `--${CommandOptions.EnvFolder}`);\n }\n } else {\n throw new FolderNotExistsError(absolutePath, `--${CommandOptions.EnvFolder}`);\n }\n }\n return true;\n}\n\nfunction checkMatronFile(args: any) {\n const matronFileRelativePath = args[CommandOptions.MatronFile] as string;\n if (matronFileRelativePath) {\n const absolutePath = path.join(process.cwd(), matronFileRelativePath);\n if (existsSync(absolutePath)) {\n if (lstatSync(absolutePath).isFile()) {\n return true;\n } else {\n throw new NotAFileError(absolutePath, `--${CommandOptions.MatronFile}`);\n }\n } else {\n throw new FileNotExistsError(absolutePath, `--${CommandOptions.MatronFile}`);\n }\n }\n return true;\n}\n\nfunction checkProjectPath(args: any) {\n const projectRelativePath = args[CommandOptions.ProjectPath] as string;\n if (projectRelativePath && process.env[PROJECT_PATH_VAR]) {\n throw new GenericError(`${PROJECT_PATH_VAR} environment variable can't be used jointly with --${CommandOptions.ProjectPath}.`);\n } else {\n if (projectRelativePath) {\n const absolutePath = path.join(process.cwd(), projectRelativePath);\n if (existsSync(absolutePath)) {\n if (lstatSync(absolutePath).isDirectory()) {\n return true;\n } else {\n throw new NotAFolderError(absolutePath, `--${CommandOptions.ProjectPath}`);\n }\n }\n }\n }\n return true;\n}\n","import { command, describe, builder, handler } from './create';\n\nexport const create = {\n command,\n describe,\n builder,\n handler\n};\n","import yargs, { CommandModule } from 'yargs';\nimport chalk from 'chalk';\nimport { create } from './commands';\nconst usage = `\nUsage\n ${chalk.green('matron')} create --matron-file=./matron.yml\n ${chalk.green('matron')} create --matron-file=./matron.yml --env-folder ./dotenv/folder\n `;\n\nyargs\n .usage(usage)\n .help()\n .wrap(yargs.terminalWidth())\n .showHelpOnFail(true)\n .command(create)\n .demandCommand()\n .recommendCommands()\n .strict().argv;\n"],"sourceRoot":""}