contensis-cli 1.0.9-beta.8 → 1.0.10-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -289,7 +289,7 @@ const mapGitHubActionCIWorkflowContent = async (cli, workflowDoc, workflowJS) =>
289
289
  }
290
290
  await addAppImageUri();
291
291
  const newJob = {
292
- name: "Deploy container image to Contensis",
292
+ name: "Push block to Contensis",
293
293
  "runs-on": "ubuntu-latest",
294
294
  needs,
295
295
  steps: [addGitHubActionJobStep]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mappers/DevInit-to-CIWorkflow.ts"],
4
- "sourcesContent": ["import inquirer from 'inquirer';\nimport { JSONPath, JSONPathOptions } from 'jsonpath-plus';\nimport { Document } from 'yaml';\nimport {\n GitHubActionPushBlockJob,\n GitHubActionPushBlockJobStep,\n GitLabPushBlockJobStage,\n} from '~/models/DevService';\nimport { readFile } from '~/providers/file-provider';\nimport ContensisDev from '~/services/ContensisDevService';\nimport { diffFileContent } from '~/util/diff';\nimport { logError } from '~/util/logger';\nimport { normaliseLineEndings } from '~/util/os';\nimport { parseYamlDocument, validateWorkflowYaml } from '~/util/yaml';\n\ntype MappedWorkflowOutput = {\n existingWorkflow: string;\n newWorkflow: string;\n diff: string;\n};\n\nexport const mapCIWorkflowContent = async (\n cli: ContensisDev\n): Promise<MappedWorkflowOutput | undefined> => {\n // get existing workflow file\n const workflowFile = readFile(cli.git.ciFilePath);\n if (!workflowFile) return undefined;\n\n // parse yaml to js\n const workflowDoc = parseYamlDocument(workflowFile);\n const workflowJS = workflowDoc.toJS();\n\n if (cli.git.type === 'github') {\n const newWorkflow = await mapGitHubActionCIWorkflowContent(\n cli,\n workflowDoc,\n workflowJS\n );\n return {\n existingWorkflow: workflowFile,\n newWorkflow,\n diff: diffFileContent(workflowFile, newWorkflow),\n };\n } else if (cli.git.type === 'gitlab') {\n const newWorkflow = await mapGitLabCIWorkflowContent(\n cli,\n workflowDoc,\n workflowJS\n );\n return {\n existingWorkflow: workflowFile,\n newWorkflow,\n diff: diffFileContent(workflowFile, newWorkflow),\n };\n }\n};\n\nconst findExistingJobSteps = (\n path: string,\n json: any,\n resultType: JSONPathOptions['resultType']\n) => {\n const existingJobStep = JSONPath({\n path,\n json,\n resultType: resultType,\n });\n\n return existingJobStep;\n};\n\nconst findPath = (path: string | any[]) =>\n typeof path === 'string' && path.includes('.')\n ? path.split('.').map(p => (Number(p) || Number(p) !== 0 ? p : Number(p)))\n : path;\n\nconst setWorkflowElement = (\n workflowDoc: Document,\n path: string | any[],\n value: any\n) => {\n if (workflowDoc.hasIn(findPath(path))) {\n workflowDoc.setIn(findPath(path), value);\n } else {\n workflowDoc.addIn(findPath(path), value);\n }\n};\n\nconst mapGitLabCIWorkflowContent = async (\n cli: ContensisDev,\n workflowDoc: Document,\n workflowJS: any\n) => {\n const addGitLabJobStage: GitLabPushBlockJobStage = {\n stage: 'push-block',\n variables: {\n block_id: cli.blockId,\n alias: cli.currentEnv,\n project_id: cli.currentProject,\n client_id:\n cli.clientDetailsLocation === 'env'\n ? cli.clientId\n : '$CONTENSIS_CLIENT_ID',\n shared_secret:\n cli.clientDetailsLocation === 'env'\n ? cli.clientSecret\n : '$CONTENSIS_SHARED_SECRET',\n },\n };\n\n const addAppImageUri = async () => {\n // Look in document level \"variables\"\n const appImageUri = await determineAppImageUri(\n cli,\n Object.entries(workflowJS.variables || {}),\n '$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME/app:build-$CI_PIPELINE_IID'\n );\n\n if (appImageUri.addVar)\n setWorkflowElement(\n workflowDoc,\n `variables.${appImageUri.var}`,\n appImageUri.uri\n );\n\n if (appImageUri.var)\n addGitLabJobStage.variables['image_uri'] = `\\$${appImageUri.var}`;\n };\n\n // look for line in job\n // jobname[stage: push-block]\n const existingJobStep = findExistingJobSteps(\n '$..[?(@property === \"stage\" && @.match(/^push-block/i))]^',\n workflowJS,\n 'all'\n );\n\n // update job step\n if (existingJobStep.length) {\n // cli.log.json(existingJobStep);\n\n // The [0] index means we're only looking at updating the first instance in the file\n const step = existingJobStep[0];\n\n // Path looks like this \"$['job_name']\"\n // We want it to look like this \"job_name\"\n const stepPath = step.path\n .replace('$[', '')\n .replaceAll('][', '.')\n .replace(']', '')\n .replaceAll(\"'\", '');\n\n cli.log.info(\n `Found existing Job step:\n ${stepPath}\n stage: ${step.value.stage}\\n`\n );\n\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.alias`,\n cli.currentEnv\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.project_id`,\n cli.currentProject\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.block_id`,\n cli.blockId\n );\n\n // This is likely not needed when updating an existing push-block job step\n // we are assuming this is a forked/copied workflow with an already working image-uri reference\n // await addAppImageUri();\n\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.client_id`,\n cli.clientDetailsLocation === 'env'\n ? cli.clientId\n : '$CONTENSIS_CLIENT_ID'\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.shared_secret`,\n cli.clientDetailsLocation === 'env'\n ? cli.clientSecret\n : '$CONTENSIS_SHARED_SECRET'\n );\n } else {\n // create job with push step\n\n // Does a series of checks and prompts to determine the correct image-uri\n // for the app container build\n await addAppImageUri();\n\n // Add the new \"job\" to the Yaml Document\n workflowDoc.addIn(['stages'], 'push-block');\n workflowDoc.addIn([], {\n key: 'push-to-contensis',\n value: addGitLabJobStage,\n });\n setWorkflowElement(\n workflowDoc,\n `include`,\n 'https://gitlab.zengenti.com/ops/contensis-ci/-/raw/main/push-block.yml'\n );\n }\n\n cli.log.debug(`New file content to write\\n\\n${workflowDoc}`);\n\n const newWorkflow = normaliseLineEndings(\n workflowDoc.toString({ lineWidth: 0 })\n );\n\n return newWorkflow;\n};\n\nconst mapGitHubActionCIWorkflowContent = async (\n cli: ContensisDev,\n workflowDoc: Document,\n workflowJS: any\n) => {\n const addGitHubActionJobStep: GitHubActionPushBlockJobStep = {\n name: 'Push block to Contensis',\n id: 'push-block',\n uses: 'contensis/block-push@v1',\n with: {\n 'block-id': cli.blockId,\n // 'image-uri': '${{ steps.build.outputs.image-uri }}',\n alias: cli.currentEnv,\n 'project-id': cli.currentProject,\n 'client-id':\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_CLIENT_ID }}'\n : '${{ secrets.CONTENSIS_CLIENT_ID }}',\n 'shared-secret':\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_SHARED_SECRET }}'\n : '${{ secrets.CONTENSIS_SHARED_SECRET }}',\n },\n };\n\n const addAppImageUri = async () => {\n // Look in document level \"env\" vars\n const appImageUri = await determineAppImageUri(\n cli,\n Object.entries(workflowJS.env || {}),\n 'ghcr.io/${{ github.repository }}/${{ github.ref_name }}/app'\n );\n\n if (appImageUri.addVar)\n setWorkflowElement(\n workflowDoc,\n `env.${appImageUri.var}`,\n appImageUri.uri\n );\n // workflowDoc.addIn(['env'], { [appImageUri.var]: appImageUri.uri });\n\n if (appImageUri.var)\n addGitHubActionJobStep.with[\n 'image-uri'\n ] = `\\${{ env.${appImageUri.var} }}:build-\\${{ github.run_number }}`;\n };\n\n // look for line in job\n // jobs.x.steps[uses: contensis/block-push]\n const existingJobStep = findExistingJobSteps(\n '$.jobs..steps.*[?(@property === \"uses\" && @.match(/^contensis\\\\/block-push/i))]^',\n workflowJS,\n 'all'\n );\n\n // Update 'env' and store client id and secret\n if (cli.clientDetailsLocation === 'env') {\n setWorkflowElement(workflowDoc, `env.CONTENSIS_CLIENT_ID`, cli.clientId);\n setWorkflowElement(\n workflowDoc,\n `env.CONTENSIS_SHARED_SECRET`,\n cli.clientSecret\n );\n }\n\n if (cli.clientDetailsLocation === 'git') {\n // remove env vars from yml if we choose git\n workflowDoc.deleteIn(findPath(`env.CONTENSIS_CLIENT_ID`));\n workflowDoc.deleteIn(findPath(`env.CONTENSIS_SHARED_SECRET`));\n }\n\n // update job step\n if (existingJobStep.length) {\n //cli.log.json(existingJobStep);\n\n // The [0] index means we're only looking at updating the first instance in the file\n const step = existingJobStep[0];\n\n // Path looks like this \"$['jobs']['build']['steps'][3]\"\n // We want it to look like this \"jobs.build.steps.3\"\n const stepPath = step.path\n .replace('$[', '')\n .replaceAll('][', '.')\n .replace(']', '')\n .replaceAll(\"'\", '');\n\n cli.log.info(\n `Found existing Job step: ${stepPath}\n - name: ${step.value.name}\n id: ${step.value.id}\\n`\n );\n\n setWorkflowElement(workflowDoc, `${stepPath}.with.alias`, cli.currentEnv);\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.with.project-id`,\n cli.currentProject\n );\n setWorkflowElement(workflowDoc, `${stepPath}.with.block-id`, cli.blockId);\n\n // This is likely not needed when updating an existing push-block job step\n // we are assuming this is a forked/copied workflow with an already working image-uri reference\n // await addAppImageUri();\n\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.with.client-id`,\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_CLIENT_ID }}'\n : '${{ secrets.CONTENSIS_CLIENT_ID }}'\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.with.shared-secret`,\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_SHARED_SECRET }}'\n : '${{ secrets.CONTENSIS_SHARED_SECRET }}'\n );\n } else {\n // create job with push step\n\n // is there already a job with a property name containing \"build\"?\n const existingBuildJobStep = findExistingJobSteps(\n '$.jobs[?(@property.match(/build/i))]',\n workflowJS,\n 'all'\n ) as JSONPathOptions[]; // This isn't the correct type for this object\n\n let needs: string | undefined;\n // There are multiple jobs called *build*\n if (existingBuildJobStep.length > 1) {\n // prompt which build job we should depend on before pushing the block\n const choices = existingBuildJobStep.map(s => s.parentProperty);\n choices.push(new inquirer.Separator() as any);\n choices.push('none');\n if (choices.includes('build-app')) needs = 'build-app';\n else {\n ({ needs } = await inquirer.prompt([\n {\n type: 'list',\n prefix: '\u231B',\n message: cli.messages.devinit.ciMultipleBuildJobChoices(),\n name: 'needs',\n choices,\n default: choices.find(\n s => typeof s === 'string' && s.includes('docker')\n ),\n },\n ]));\n }\n\n cli.log.raw('');\n } else if (existingBuildJobStep.length === 1)\n // Exactly one job step found containing a property name of *build*\n // we'll assume that is the one the push-block job depends on\n needs = existingBuildJobStep[0].parentProperty;\n\n if (existingBuildJobStep.length === 0 || needs === 'none') {\n // No existing build step found or chosen, offer all job steps in prompt\n const choices = Object.keys(workflowJS.jobs);\n choices.push(new inquirer.Separator() as any);\n choices.push('none');\n\n ({ needs } = await inquirer.prompt([\n {\n type: 'list',\n prefix: '\u231B',\n message: cli.messages.devinit.ciMultipleJobChoices(),\n name: 'needs',\n choices,\n default: choices.find(\n j => typeof j === 'string' && j.includes('docker')\n ),\n },\n ]));\n if (needs === 'none') needs = undefined;\n cli.log.raw('');\n }\n\n // Does a series of checks and prompts to determine the correct image-uri\n // for the app container build\n await addAppImageUri();\n\n const newJob: GitHubActionPushBlockJob = {\n name: 'Deploy container image to Contensis',\n 'runs-on': 'ubuntu-latest',\n needs,\n steps: [addGitHubActionJobStep],\n };\n\n // Add the new \"job\" to the Yaml Document\n workflowDoc.addIn(['jobs'], {\n key: 'deploy',\n value: newJob,\n });\n }\n\n // Workflow validation provided by @action-validator/core package\n const workflowIsValid = validateWorkflowYaml(workflowDoc.toString());\n\n // We could expand validation to check for having a build step to wait for\n // or if a valid image-uri attribute is set\n if (workflowIsValid === true) {\n cli.log.success(`GitHub workflow YAML is valid`);\n cli.log.debug(`New file content to write\\n\\n${workflowDoc}`);\n } else if (Array.isArray(workflowIsValid)) {\n // Errors\n logError(\n [\n ...workflowIsValid.map(\n res => new Error(`${res.code}: ${res.detail || res.title}`)\n ),\n workflowDoc.toString(),\n ],\n `GitHub workflow YAML did not pass validation check`\n );\n }\n\n // const newWorkflow = normaliseLineEndings(\n // workflowDoc.toString({ lineWidth: 0 })\n // );\n\n const newWorkflow = workflowDoc.toString({ lineWidth: 0 });\n\n return newWorkflow;\n};\n\nconst determineAppImageUri = async (\n cli: ContensisDev,\n vars: [string, string][],\n defaultUri: string\n) => {\n // Determine container image-uri via variables and/or prompts\n\n // Find vars including the word \"image\"\n const imageVars = vars.filter(([varname]) =>\n varname.toLowerCase().includes('image')\n );\n // Find vars named \"image\" that include the word \"app\"\n const appImageVars = imageVars.filter(\n ([varname, value]) =>\n !varname.toLowerCase().includes('builder_') &&\n (varname.toLowerCase().includes('app_') ||\n varname.toLowerCase().includes('build_') ||\n value?.toLowerCase().includes('/app'))\n );\n\n const appImageUriGuess = appImageVars?.[0];\n\n let appImageUri: string | undefined;\n let appImageVar: string | undefined;\n\n if (appImageUriGuess) {\n cli.log.success(\n `Found variable ${cli.log.standardText(\n appImageUriGuess[0]\n )} we'll use for pulling the block image from: ${cli.log.infoText(\n appImageUriGuess[1]\n )}`\n );\n appImageVar = appImageUriGuess[0];\n } else {\n // Could not find a suitable var to use for block image-uri\n // prompt for an app image uri\n const choices = vars.map(v => v[0]);\n const enterOwnMsg = 'enter my own / use default';\n\n choices.push(new inquirer.Separator() as any);\n choices.push(enterOwnMsg);\n choices.push(defaultUri);\n\n ({ appImageVar, appImageUri } = await inquirer.prompt([\n // First question determines if an existing env variable\n // already containes the tagged app image uri\n {\n type: 'list',\n prefix: '\uD83D\uDC33',\n message: cli.messages.devinit.ciMultipleAppImageVarChoices(),\n name: 'appImageVar',\n choices,\n default: choices.find(\n v => typeof v === 'string' && v.toLowerCase().includes('image')\n ),\n },\n // Subsequent prompt allows input of an image-uri if needed\n {\n type: 'input',\n when(answers) {\n return [enterOwnMsg, defaultUri].includes(answers.appImageVar);\n },\n prefix: `\\n \\n\uD83D\uDD17`,\n message: cli.messages.devinit.ciEnterOwnAppImagePrompt(cli.git),\n name: 'appImageUri',\n default: defaultUri,\n },\n ]));\n cli.log.raw('');\n\n // this indicates a uri has been added and we will add a new var\n // to the workflow to encourage users to update the docker tag part\n // of their build workflow to use the same var as the push-block job/step\n if ([enterOwnMsg, defaultUri].includes(appImageVar || ''))\n appImageVar = undefined;\n }\n\n if (appImageVar)\n appImageUri =\n cli.git.type === 'github'\n ? `\\${{ env.${appImageVar} }}`\n : `\\$${appImageVar}`;\n\n // TODO: prompt further for image tag\n\n return {\n addVar: !appImageVar,\n uri: appImageUri,\n var: appImageVar || 'BUILD_IMAGE',\n };\n};\n"],
4
+ "sourcesContent": ["import inquirer from 'inquirer';\nimport { JSONPath, JSONPathOptions } from 'jsonpath-plus';\nimport { Document } from 'yaml';\nimport {\n GitHubActionPushBlockJob,\n GitHubActionPushBlockJobStep,\n GitLabPushBlockJobStage,\n} from '~/models/DevService';\nimport { readFile } from '~/providers/file-provider';\nimport ContensisDev from '~/services/ContensisDevService';\nimport { diffFileContent } from '~/util/diff';\nimport { logError } from '~/util/logger';\nimport { normaliseLineEndings } from '~/util/os';\nimport { parseYamlDocument, validateWorkflowYaml } from '~/util/yaml';\n\ntype MappedWorkflowOutput = {\n existingWorkflow: string;\n newWorkflow: string;\n diff: string;\n};\n\nexport const mapCIWorkflowContent = async (\n cli: ContensisDev\n): Promise<MappedWorkflowOutput | undefined> => {\n // get existing workflow file\n const workflowFile = readFile(cli.git.ciFilePath);\n if (!workflowFile) return undefined;\n\n // parse yaml to js\n const workflowDoc = parseYamlDocument(workflowFile);\n const workflowJS = workflowDoc.toJS();\n\n if (cli.git.type === 'github') {\n const newWorkflow = await mapGitHubActionCIWorkflowContent(\n cli,\n workflowDoc,\n workflowJS\n );\n return {\n existingWorkflow: workflowFile,\n newWorkflow,\n diff: diffFileContent(workflowFile, newWorkflow),\n };\n } else if (cli.git.type === 'gitlab') {\n const newWorkflow = await mapGitLabCIWorkflowContent(\n cli,\n workflowDoc,\n workflowJS\n );\n return {\n existingWorkflow: workflowFile,\n newWorkflow,\n diff: diffFileContent(workflowFile, newWorkflow),\n };\n }\n};\n\nconst findExistingJobSteps = (\n path: string,\n json: any,\n resultType: JSONPathOptions['resultType']\n) => {\n const existingJobStep = JSONPath({\n path,\n json,\n resultType: resultType,\n });\n\n return existingJobStep;\n};\n\nconst findPath = (path: string | any[]) =>\n typeof path === 'string' && path.includes('.')\n ? path.split('.').map(p => (Number(p) || Number(p) !== 0 ? p : Number(p)))\n : path;\n\nconst setWorkflowElement = (\n workflowDoc: Document,\n path: string | any[],\n value: any\n) => {\n if (workflowDoc.hasIn(findPath(path))) {\n workflowDoc.setIn(findPath(path), value);\n } else {\n workflowDoc.addIn(findPath(path), value);\n }\n};\n\nconst mapGitLabCIWorkflowContent = async (\n cli: ContensisDev,\n workflowDoc: Document,\n workflowJS: any\n) => {\n const addGitLabJobStage: GitLabPushBlockJobStage = {\n stage: 'push-block',\n variables: {\n block_id: cli.blockId,\n alias: cli.currentEnv,\n project_id: cli.currentProject,\n client_id:\n cli.clientDetailsLocation === 'env'\n ? cli.clientId\n : '$CONTENSIS_CLIENT_ID',\n shared_secret:\n cli.clientDetailsLocation === 'env'\n ? cli.clientSecret\n : '$CONTENSIS_SHARED_SECRET',\n },\n };\n\n const addAppImageUri = async () => {\n // Look in document level \"variables\"\n const appImageUri = await determineAppImageUri(\n cli,\n Object.entries(workflowJS.variables || {}),\n '$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME/app:build-$CI_PIPELINE_IID'\n );\n\n if (appImageUri.addVar)\n setWorkflowElement(\n workflowDoc,\n `variables.${appImageUri.var}`,\n appImageUri.uri\n );\n\n if (appImageUri.var)\n addGitLabJobStage.variables['image_uri'] = `\\$${appImageUri.var}`;\n };\n\n // look for line in job\n // jobname[stage: push-block]\n const existingJobStep = findExistingJobSteps(\n '$..[?(@property === \"stage\" && @.match(/^push-block/i))]^',\n workflowJS,\n 'all'\n );\n\n // update job step\n if (existingJobStep.length) {\n // cli.log.json(existingJobStep);\n\n // The [0] index means we're only looking at updating the first instance in the file\n const step = existingJobStep[0];\n\n // Path looks like this \"$['job_name']\"\n // We want it to look like this \"job_name\"\n const stepPath = step.path\n .replace('$[', '')\n .replaceAll('][', '.')\n .replace(']', '')\n .replaceAll(\"'\", '');\n\n cli.log.info(\n `Found existing Job step:\n ${stepPath}\n stage: ${step.value.stage}\\n`\n );\n\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.alias`,\n cli.currentEnv\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.project_id`,\n cli.currentProject\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.block_id`,\n cli.blockId\n );\n\n // This is likely not needed when updating an existing push-block job step\n // we are assuming this is a forked/copied workflow with an already working image-uri reference\n // await addAppImageUri();\n\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.client_id`,\n cli.clientDetailsLocation === 'env'\n ? cli.clientId\n : '$CONTENSIS_CLIENT_ID'\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.variables.shared_secret`,\n cli.clientDetailsLocation === 'env'\n ? cli.clientSecret\n : '$CONTENSIS_SHARED_SECRET'\n );\n } else {\n // create job with push step\n\n // Does a series of checks and prompts to determine the correct image-uri\n // for the app container build\n await addAppImageUri();\n\n // Add the new \"job\" to the Yaml Document\n workflowDoc.addIn(['stages'], 'push-block');\n workflowDoc.addIn([], {\n key: 'push-to-contensis',\n value: addGitLabJobStage,\n });\n setWorkflowElement(\n workflowDoc,\n `include`,\n 'https://gitlab.zengenti.com/ops/contensis-ci/-/raw/main/push-block.yml'\n );\n }\n\n cli.log.debug(`New file content to write\\n\\n${workflowDoc}`);\n\n const newWorkflow = normaliseLineEndings(\n workflowDoc.toString({ lineWidth: 0 })\n );\n\n return newWorkflow;\n};\n\nconst mapGitHubActionCIWorkflowContent = async (\n cli: ContensisDev,\n workflowDoc: Document,\n workflowJS: any\n) => {\n const addGitHubActionJobStep: GitHubActionPushBlockJobStep = {\n name: 'Push block to Contensis',\n id: 'push-block',\n uses: 'contensis/block-push@v1',\n with: {\n 'block-id': cli.blockId,\n // 'image-uri': '${{ steps.build.outputs.image-uri }}',\n alias: cli.currentEnv,\n 'project-id': cli.currentProject,\n 'client-id':\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_CLIENT_ID }}'\n : '${{ secrets.CONTENSIS_CLIENT_ID }}',\n 'shared-secret':\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_SHARED_SECRET }}'\n : '${{ secrets.CONTENSIS_SHARED_SECRET }}',\n },\n };\n\n const addAppImageUri = async () => {\n // Look in document level \"env\" vars\n const appImageUri = await determineAppImageUri(\n cli,\n Object.entries(workflowJS.env || {}),\n 'ghcr.io/${{ github.repository }}/${{ github.ref_name }}/app'\n );\n\n if (appImageUri.addVar)\n setWorkflowElement(\n workflowDoc,\n `env.${appImageUri.var}`,\n appImageUri.uri\n );\n // workflowDoc.addIn(['env'], { [appImageUri.var]: appImageUri.uri });\n\n if (appImageUri.var)\n addGitHubActionJobStep.with[\n 'image-uri'\n ] = `\\${{ env.${appImageUri.var} }}:build-\\${{ github.run_number }}`;\n };\n\n // look for line in job\n // jobs.x.steps[uses: contensis/block-push]\n const existingJobStep = findExistingJobSteps(\n '$.jobs..steps.*[?(@property === \"uses\" && @.match(/^contensis\\\\/block-push/i))]^',\n workflowJS,\n 'all'\n );\n\n // Update 'env' and store client id and secret\n if (cli.clientDetailsLocation === 'env') {\n setWorkflowElement(workflowDoc, `env.CONTENSIS_CLIENT_ID`, cli.clientId);\n setWorkflowElement(\n workflowDoc,\n `env.CONTENSIS_SHARED_SECRET`,\n cli.clientSecret\n );\n }\n\n if (cli.clientDetailsLocation === 'git') {\n // remove env vars from yml if we choose git\n workflowDoc.deleteIn(findPath(`env.CONTENSIS_CLIENT_ID`));\n workflowDoc.deleteIn(findPath(`env.CONTENSIS_SHARED_SECRET`));\n }\n\n // update job step\n if (existingJobStep.length) {\n //cli.log.json(existingJobStep);\n\n // The [0] index means we're only looking at updating the first instance in the file\n const step = existingJobStep[0];\n\n // Path looks like this \"$['jobs']['build']['steps'][3]\"\n // We want it to look like this \"jobs.build.steps.3\"\n const stepPath = step.path\n .replace('$[', '')\n .replaceAll('][', '.')\n .replace(']', '')\n .replaceAll(\"'\", '');\n\n cli.log.info(\n `Found existing Job step: ${stepPath}\n - name: ${step.value.name}\n id: ${step.value.id}\\n`\n );\n\n setWorkflowElement(workflowDoc, `${stepPath}.with.alias`, cli.currentEnv);\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.with.project-id`,\n cli.currentProject\n );\n setWorkflowElement(workflowDoc, `${stepPath}.with.block-id`, cli.blockId);\n\n // This is likely not needed when updating an existing push-block job step\n // we are assuming this is a forked/copied workflow with an already working image-uri reference\n // await addAppImageUri();\n\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.with.client-id`,\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_CLIENT_ID }}'\n : '${{ secrets.CONTENSIS_CLIENT_ID }}'\n );\n setWorkflowElement(\n workflowDoc,\n `${stepPath}.with.shared-secret`,\n cli.clientDetailsLocation === 'env'\n ? '${{ env.CONTENSIS_SHARED_SECRET }}'\n : '${{ secrets.CONTENSIS_SHARED_SECRET }}'\n );\n } else {\n // create job with push step\n\n // is there already a job with a property name containing \"build\"?\n const existingBuildJobStep = findExistingJobSteps(\n '$.jobs[?(@property.match(/build/i))]',\n workflowJS,\n 'all'\n ) as JSONPathOptions[]; // This isn't the correct type for this object\n\n let needs: string | undefined;\n // There are multiple jobs called *build*\n if (existingBuildJobStep.length > 1) {\n // prompt which build job we should depend on before pushing the block\n const choices = existingBuildJobStep.map(s => s.parentProperty);\n choices.push(new inquirer.Separator() as any);\n choices.push('none');\n if (choices.includes('build-app')) needs = 'build-app';\n else {\n ({ needs } = await inquirer.prompt([\n {\n type: 'list',\n prefix: '\u231B',\n message: cli.messages.devinit.ciMultipleBuildJobChoices(),\n name: 'needs',\n choices,\n default: choices.find(\n s => typeof s === 'string' && s.includes('docker')\n ),\n },\n ]));\n }\n\n cli.log.raw('');\n } else if (existingBuildJobStep.length === 1)\n // Exactly one job step found containing a property name of *build*\n // we'll assume that is the one the push-block job depends on\n needs = existingBuildJobStep[0].parentProperty;\n\n if (existingBuildJobStep.length === 0 || needs === 'none') {\n // No existing build step found or chosen, offer all job steps in prompt\n const choices = Object.keys(workflowJS.jobs);\n choices.push(new inquirer.Separator() as any);\n choices.push('none');\n\n ({ needs } = await inquirer.prompt([\n {\n type: 'list',\n prefix: '\u231B',\n message: cli.messages.devinit.ciMultipleJobChoices(),\n name: 'needs',\n choices,\n default: choices.find(\n j => typeof j === 'string' && j.includes('docker')\n ),\n },\n ]));\n if (needs === 'none') needs = undefined;\n cli.log.raw('');\n }\n\n // Does a series of checks and prompts to determine the correct image-uri\n // for the app container build\n await addAppImageUri();\n\n const newJob: GitHubActionPushBlockJob = {\n name: 'Push block to Contensis',\n 'runs-on': 'ubuntu-latest',\n needs,\n steps: [addGitHubActionJobStep],\n };\n\n // Add the new \"job\" to the Yaml Document\n workflowDoc.addIn(['jobs'], {\n key: 'deploy',\n value: newJob,\n });\n }\n\n // Workflow validation provided by @action-validator/core package\n const workflowIsValid = validateWorkflowYaml(workflowDoc.toString());\n\n // We could expand validation to check for having a build step to wait for\n // or if a valid image-uri attribute is set\n if (workflowIsValid === true) {\n cli.log.success(`GitHub workflow YAML is valid`);\n cli.log.debug(`New file content to write\\n\\n${workflowDoc}`);\n } else if (Array.isArray(workflowIsValid)) {\n // Errors\n logError(\n [\n ...workflowIsValid.map(\n res => new Error(`${res.code}: ${res.detail || res.title}`)\n ),\n workflowDoc.toString(),\n ],\n `GitHub workflow YAML did not pass validation check`\n );\n }\n\n // const newWorkflow = normaliseLineEndings(\n // workflowDoc.toString({ lineWidth: 0 })\n // );\n\n const newWorkflow = workflowDoc.toString({ lineWidth: 0 });\n\n return newWorkflow;\n};\n\nconst determineAppImageUri = async (\n cli: ContensisDev,\n vars: [string, string][],\n defaultUri: string\n) => {\n // Determine container image-uri via variables and/or prompts\n\n // Find vars including the word \"image\"\n const imageVars = vars.filter(([varname]) =>\n varname.toLowerCase().includes('image')\n );\n // Find vars named \"image\" that include the word \"app\"\n const appImageVars = imageVars.filter(\n ([varname, value]) =>\n !varname.toLowerCase().includes('builder_') &&\n (varname.toLowerCase().includes('app_') ||\n varname.toLowerCase().includes('build_') ||\n value?.toLowerCase().includes('/app'))\n );\n\n const appImageUriGuess = appImageVars?.[0];\n\n let appImageUri: string | undefined;\n let appImageVar: string | undefined;\n\n if (appImageUriGuess) {\n cli.log.success(\n `Found variable ${cli.log.standardText(\n appImageUriGuess[0]\n )} we'll use for pulling the block image from: ${cli.log.infoText(\n appImageUriGuess[1]\n )}`\n );\n appImageVar = appImageUriGuess[0];\n } else {\n // Could not find a suitable var to use for block image-uri\n // prompt for an app image uri\n const choices = vars.map(v => v[0]);\n const enterOwnMsg = 'enter my own / use default';\n\n choices.push(new inquirer.Separator() as any);\n choices.push(enterOwnMsg);\n choices.push(defaultUri);\n\n ({ appImageVar, appImageUri } = await inquirer.prompt([\n // First question determines if an existing env variable\n // already containes the tagged app image uri\n {\n type: 'list',\n prefix: '\uD83D\uDC33',\n message: cli.messages.devinit.ciMultipleAppImageVarChoices(),\n name: 'appImageVar',\n choices,\n default: choices.find(\n v => typeof v === 'string' && v.toLowerCase().includes('image')\n ),\n },\n // Subsequent prompt allows input of an image-uri if needed\n {\n type: 'input',\n when(answers) {\n return [enterOwnMsg, defaultUri].includes(answers.appImageVar);\n },\n prefix: `\\n \\n\uD83D\uDD17`,\n message: cli.messages.devinit.ciEnterOwnAppImagePrompt(cli.git),\n name: 'appImageUri',\n default: defaultUri,\n },\n ]));\n cli.log.raw('');\n\n // this indicates a uri has been added and we will add a new var\n // to the workflow to encourage users to update the docker tag part\n // of their build workflow to use the same var as the push-block job/step\n if ([enterOwnMsg, defaultUri].includes(appImageVar || ''))\n appImageVar = undefined;\n }\n\n if (appImageVar)\n appImageUri =\n cli.git.type === 'github'\n ? `\\${{ env.${appImageVar} }}`\n : `\\$${appImageVar}`;\n\n // TODO: prompt further for image tag\n\n return {\n addVar: !appImageVar,\n uri: appImageUri,\n var: appImageVar || 'BUILD_IMAGE',\n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AAAA,QACN;AAAA,QACA,SAAS,QAAQ;AAAA,UACf,OAAK,OAAO,MAAM,YAAY,EAAE,YAAY,EAAE,SAAS,OAAO;AAAA,QAChE;AAAA,MACF;AAAA,MAEA;AAAA,QACE,MAAM;AAAA,QACN,KAAK,SAAS;AACZ,iBAAO,CAAC,aAAa,UAAU,EAAE,SAAS,QAAQ,WAAW;AAAA,QAC/D;AAAA,QACA,QAAQ;AAAA;AAAA;AAAA,QACR,SAAS,IAAI,SAAS,QAAQ,yBAAyB,IAAI,GAAG;AAAA,QAC9D,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AACD,QAAI,IAAI,IAAI,EAAE;AAKd,QAAI,CAAC,aAAa,UAAU,EAAE,SAAS,eAAe,EAAE;AACtD,oBAAc;AAAA,EAClB;AAEA,MAAI;AACF,kBACE,IAAI,IAAI,SAAS,WACb,YAAY,mBACZ,IAAK;AAIb,SAAO;AAAA,IACL,QAAQ,CAAC;AAAA,IACT,KAAK;AAAA,IACL,KAAK,eAAe;AAAA,EACtB;AACF;",
6
6
  "names": ["import_yaml", "inquirer"]
7
7
  }
@@ -62,8 +62,8 @@ class ContensisDev extends import_ContensisRoleService.default {
62
62
  const contensis = await this.ConnectContensis();
63
63
  if (contensis) {
64
64
  const validateBlockId = (blockId2) => {
65
- const pattern = /^[a-z-]*$/;
66
- if (typeof blockId2 === "string" && blockId2.length >= 3) {
65
+ const pattern = /^[0-9a-z](-?[0-9a-z])*$/;
66
+ if (blockId2.length >= 1 && blockId2.length <= 225) {
67
67
  return pattern.test(blockId2);
68
68
  } else
69
69
  return false;
@@ -88,8 +88,9 @@ class ContensisDev extends import_ContensisRoleService.default {
88
88
  );
89
89
  const workflowFiles = git.workflows;
90
90
  let ciFileName = git.ciFileName;
91
- const devKeyName = `${blockId} development`;
92
- const devKeyDescription = `${blockId} [contensis-cli]`;
91
+ const apiKeyName = `block-${currentProject}-${blockId}`.toLowerCase();
92
+ const devKeyName = `${apiKeyName}`;
93
+ const devKeyDescription = `Created by Contensis to allow API access from the running block`;
93
94
  let existingDevKey = apiKeyExists(devKeyName);
94
95
  if (!existingDevKey) {
95
96
  existingDevKey = await this.CreateOrUpdateApiKey(
@@ -99,8 +100,8 @@ class ContensisDev extends import_ContensisRoleService.default {
99
100
  );
100
101
  log.success("Successfully created development key");
101
102
  }
102
- const deployKeyName = `${blockId} deployment`;
103
- const deployKeyDescription = `${blockId} deploy [contensis-cli]`;
103
+ const deployKeyName = `${apiKeyName}-ci`;
104
+ const deployKeyDescription = `Created by the Contensis CLI for use in continuous integration`;
104
105
  let existingDeployKey = apiKeyExists(deployKeyName);
105
106
  if (!existingDeployKey) {
106
107
  existingDeployKey = await this.CreateOrUpdateApiKey(
@@ -219,17 +220,19 @@ class ContensisDev extends import_ContensisRoleService.default {
219
220
  if (dryRun) {
220
221
  checkpoint(`skip api key creation (dry-run)`);
221
222
  } else {
223
+ const deployRoleName = `Role for CI push of block '${blockId}'`;
224
+ const deplyRoleDescription = `Created by the Contensis CLI for use in continuous integration`;
222
225
  let existingDeployRole = (0, import_find.findByIdOrName)(
223
226
  roles || [],
224
- deployKeyName,
227
+ deployRoleName,
225
228
  true
226
229
  );
227
230
  existingDeployRole = await this.CreateOrUpdateRole(
228
231
  existingDeployRole,
229
- (0, import_DevInit_to_RolePermissions.deployKeyRole)(deployKeyName, deployKeyDescription)
232
+ (0, import_DevInit_to_RolePermissions.deployKeyRole)(deployRoleName, deplyRoleDescription)
230
233
  );
231
234
  checkpoint("deploy key role assigned");
232
- log.success(messages.devinit.createDeployKey(deployKeyName, true));
235
+ log.success(messages.devinit.createDeployKey(deployRoleName, true));
233
236
  checkpoint("api keys done");
234
237
  }
235
238
  const envFilePath = `${projectHome}/.env`;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/ContensisDevService.ts"],
4
- "sourcesContent": ["import to from 'await-to-js';\nimport { spawn } from 'child_process';\nimport inquirer from 'inquirer';\nimport path from 'path';\n\nimport { Role } from 'contensis-management-api/lib/models';\nimport { MigrateRequest } from 'migratortron';\n\nimport ContensisRole from './ContensisRoleService';\nimport { OutputOptionsConstructorArg } from '~/models/CliService';\nimport { EnvContentsToAdd } from '~/models/DevService';\nimport { mapSiteConfigYaml } from '~/mappers/DevRequests-to-RequestHanderSiteConfigYaml';\nimport { mapCIWorkflowContent } from '~/mappers/DevInit-to-CIWorkflow';\nimport {\n deployKeyRole,\n devKeyRole,\n} from '~/mappers/DevInit-to-RolePermissions';\nimport { appRootDir, readFile, writeFile } from '~/providers/file-provider';\nimport { diffFileContent } from '~/util/diff';\nimport { mergeDotEnvFileContents } from '~/util/dotenv';\nimport { findByIdOrName } from '~/util/find';\nimport { GitHelper } from '~/util/git';\nimport { jsonFormatter } from '~/util/json.formatter';\nimport { winSlash } from '~/util/os';\nimport { stringifyYaml } from '~/util/yaml';\nimport { createSpinner } from 'nanospinner';\nimport { mergeContentsToAddWithGitignore } from '~/util/gitignore';\n\nclass ContensisDev extends ContensisRole {\n git!: GitHelper;\n blockId: string;\n\n constructor(\n args: string[],\n outputOpts?: OutputOptionsConstructorArg,\n contensisOpts: Partial<MigrateRequest> = {}\n ) {\n super(args, outputOpts, contensisOpts);\n }\n\n DevelopmentInit = async (projectHome: string, opts: any) => {\n // Retrieve git info\n const git = (this.git = new GitHelper(projectHome));\n // Check if we are in a git repo\n const isRepo = git.checkIsRepo();\n if (!isRepo) return;\n\n const { dryRun = false } = opts || {};\n const { currentEnv, currentProject, log, messages } = this;\n const contensis = await this.ConnectContensis();\n\n if (contensis) {\n // First we need to get the block id from the user\n const validateBlockId = (blockId: string) => {\n const pattern = /^[a-z-]*$/;\n if (typeof blockId === 'string' && blockId.length >= 3) {\n return pattern.test(blockId);\n } else return false;\n };\n let { blockId } = await inquirer.prompt({\n name: 'blockId',\n type: 'input',\n prefix: '\uD83E\uDDF1',\n message: messages.devinit.blockIdQuestion,\n validate: validateBlockId,\n });\n // make sure block id is lowercase\n this.blockId = blockId.toLowerCase();\n log.success(`Valid block id: ${blockId.toLowerCase()}`);\n\n // Retrieve keys list for env\n const [keysErr, apiKeys] = await contensis.apiKeys.GetKeys();\n if (keysErr) {\n log.error(messages.keys.noList(currentEnv));\n log.error(jsonFormatter(keysErr));\n return;\n }\n const apiKeyExists = (findKey: string) =>\n apiKeys?.find(\n k => k.name.trim().toLowerCase() === findKey?.trim().toLowerCase()\n );\n\n // Retrieve ci workflow info\n const workflowFiles = git.workflows;\n\n // Set variables for performing operations and logging etc.\n let ciFileName = git.ciFileName;\n\n const devKeyName = `${blockId} development`;\n const devKeyDescription = `${blockId} [contensis-cli]`;\n let existingDevKey = apiKeyExists(devKeyName);\n\n // if dev api key doesn't exisit go and create it (we need this for local development, we will store these details in the .env file).\n if (!existingDevKey) {\n existingDevKey = await this.CreateOrUpdateApiKey(\n existingDevKey,\n devKeyName,\n devKeyDescription\n );\n log.success('Successfully created development key');\n }\n\n const deployKeyName = `${blockId} deployment`;\n const deployKeyDescription = `${blockId} deploy [contensis-cli]`;\n\n let existingDeployKey = apiKeyExists(deployKeyName);\n\n // if deploy api key doesn't exisit go and create it (we need this for yml file).\n if (!existingDeployKey) {\n existingDeployKey = await this.CreateOrUpdateApiKey(\n existingDeployKey,\n deployKeyName,\n deployKeyDescription\n );\n log.success('Successfully created deploy key');\n }\n\n // check we have the deply key so we can assign them to this values\n if (existingDeployKey) {\n // Add client id and secret to global 'this'\n this.clientId = existingDeployKey?.id;\n this.clientSecret = existingDeployKey?.sharedSecret;\n }\n\n // const blockId = git.name;\n const errors = [] as AppError[];\n\n // Start render console output\n log.raw('');\n log.success(messages.devinit.intro());\n log.raw('');\n log.raw(\n log.infoText(\n messages.devinit.projectDetails(\n git.name,\n currentEnv,\n currentProject,\n blockId,\n git\n )\n )\n );\n log.raw(\n log.infoText(\n messages.devinit.developmentKey(devKeyName, !!existingDevKey)\n )\n );\n log.raw(\n log.infoText(\n messages.devinit.deploymentKey(deployKeyName, !!existingDeployKey)\n )\n );\n log.raw('');\n\n if (Array.isArray(workflowFiles) && workflowFiles.length > 1) {\n // Choose GitHub workflow file (if multiple)\n ({ ciFileName } = await inquirer.prompt([\n {\n type: 'list',\n prefix: '\u29F0',\n message: messages.devinit.ciMultipleChoices(),\n name: 'ciFileName',\n choices: workflowFiles,\n default: workflowFiles.find(f => f.includes('docker')),\n },\n ]));\n log.raw('');\n git.ciFileName = ciFileName;\n }\n\n log.raw(log.infoText(messages.devinit.ciDetails(ciFileName)));\n\n let mappedWorkflow;\n // Location for Client ID / Secret.\n const { clientDetailsOption } = await inquirer.prompt({\n name: 'clientDetailsOption',\n type: 'list',\n prefix: '\uD83D\uDD11',\n // Where would you like to store your Client ID/Secret?\n message: messages.devinit.clientDetailsLocation(),\n choices: [\n messages.devinit.clientDetailsInGit(git),\n messages.devinit.clientDetailsInEnv(),\n ],\n });\n\n // global 'clientDetailsLocation' variable stores users input on where client id / secert are stored\n if (clientDetailsOption === messages.devinit.clientDetailsInEnv()) {\n this.clientDetailsLocation = 'env';\n } else {\n this.clientDetailsLocation = 'git';\n }\n\n if (this.clientDetailsLocation === 'env') {\n // Update CI Workflow to pull from ENV variables\n mappedWorkflow = await mapCIWorkflowContent(this);\n log.help(messages.devinit.ciIntro(git, 'env'));\n } else {\n // Look at the workflow file content and make updates\n mappedWorkflow = await mapCIWorkflowContent(this);\n log.help(messages.devinit.ciIntro(git, 'git'));\n }\n\n if (!dryRun) {\n // Confirm prompt\n const { confirm } = await inquirer.prompt([\n {\n type: 'confirm',\n message: messages.devinit.confirm(),\n name: 'confirm',\n default: false,\n },\n ]);\n log.raw('');\n if (!confirm) return;\n }\n\n // Fetching access token\n let accessToken: string | undefined = undefined;\n log.raw('');\n\n const spinner = createSpinner(messages.devinit.accessTokenFetch());\n spinner.start();\n\n const token = await this.GetDeliveryApiKey();\n\n if (token) {\n spinner.success();\n this.log.success(messages.devinit.accessTokenSuccess(token));\n accessToken = token;\n } else {\n spinner.error();\n this.log.error(messages.devinit.accessTokenFailed());\n return;\n }\n\n // Magic happens...\n const checkpoint = (op: string) => {\n if (errors.length) throw errors[0];\n else log.debug(`${op} completed ok`);\n return true;\n };\n\n // Arrange API keys for development and deployment\n const [getRolesErr, roles] = await to(contensis.roles.GetRoles());\n if (!roles && getRolesErr) errors.push(getRolesErr);\n checkpoint(`fetched ${roles?.length} roles`);\n if (dryRun) {\n checkpoint(`skip api key creation (dry-run)`);\n } else {\n // Ensure deploy API key is assigned to a role with the right permissions\n let existingDeployRole = findByIdOrName(\n roles || [],\n deployKeyName,\n true\n ) as Role | undefined;\n existingDeployRole = await this.CreateOrUpdateRole(\n existingDeployRole,\n deployKeyRole(deployKeyName, deployKeyDescription)\n );\n\n checkpoint('deploy key role assigned');\n log.success(messages.devinit.createDeployKey(deployKeyName, true));\n checkpoint('api keys done');\n }\n\n const envFilePath = `${projectHome}/.env`;\n const existingEnvFile = readFile(envFilePath);\n let existingEnvFileArray = (existingEnvFile || '')\n .split('\\n')\n .filter(l => !!l);\n\n // Update or create a file called .env in project home\n const envContentsToAdd: EnvContentsToAdd = {\n ALIAS: currentEnv,\n PROJECT_API_ID: currentProject,\n BLOCK_ID: blockId,\n };\n if (accessToken) envContentsToAdd['ACCESS_TOKEN'] = accessToken;\n // add client id and secret to the env file\n if (this.clientDetailsLocation === 'env') {\n envContentsToAdd['CONTENSIS_CLIENT_ID'] = existingDevKey?.id;\n envContentsToAdd['CONTENSIS_CLIENT_SECRET'] =\n existingDevKey?.sharedSecret;\n }\n\n // if we have client id / secret in our env remove it\n const removeEnvItems = (items: string[]) => {\n const indexesToRemove = [];\n\n for (let i = 0; i < existingEnvFileArray.length; i++) {\n for (const item of items) {\n if (existingEnvFileArray[i].includes(item)) {\n indexesToRemove.push(i);\n break;\n }\n }\n }\n\n for (let i = indexesToRemove.length - 1; i >= 0; i--) {\n existingEnvFileArray.splice(indexesToRemove[i], 1);\n }\n };\n\n if (this.clientDetailsLocation === 'git') {\n removeEnvItems(['CONTENSIS_CLIENT_ID', 'CONTENSIS_CLIENT_SECRET']);\n }\n\n const envFileLines = mergeDotEnvFileContents(\n existingEnvFileArray,\n envContentsToAdd\n );\n const newEnvFileContent = envFileLines.join('\\n');\n const envDiff = diffFileContent(existingEnvFile || '', newEnvFileContent);\n\n if (dryRun) {\n if (envDiff) {\n log.info(`Updating .env file ${winSlash(envFilePath)}:\\n${envDiff}`);\n log.raw('');\n }\n checkpoint('skip .env file update (dry-run)');\n } else {\n if (envDiff) log.info(`updating .env file ${winSlash(envFilePath)}`);\n writeFile(envFilePath, envFileLines.join('\\n'));\n checkpoint('.env file updated');\n log.success(messages.devinit.writeEnvFile());\n // log.help(messages.devinit.useEnvFileTip());\n }\n\n // Update git ignore\n const gitIgnorePath = `${projectHome}/.gitignore`;\n const gitIgnoreContentsToAdd = ['.env'];\n mergeContentsToAddWithGitignore(gitIgnorePath, gitIgnoreContentsToAdd);\n\n // Update CI file -- different for GH/GL\n if (mappedWorkflow?.diff) {\n log.info(\n `Updating ${winSlash(ciFileName)} file:\\n${mappedWorkflow.diff}`\n );\n log.raw('');\n }\n if (dryRun) {\n checkpoint('skip CI file update (dry-run)');\n //log.object(ciFileLines);\n } else {\n if (mappedWorkflow?.newWorkflow) {\n if (mappedWorkflow?.diff) {\n writeFile(git.ciFilePath, mappedWorkflow.newWorkflow);\n log.success(messages.devinit.writeCiFile(`./${ciFileName}`));\n log.info(\n messages.devinit.ciBlockTip(blockId, currentEnv, currentProject)\n );\n } else {\n log.info(messages.devinit.ciFileNoChanges(`./${ciFileName}`));\n }\n checkpoint('CI file updated');\n }\n }\n\n if (this.clientDetailsLocation === 'git') {\n // Echo Deployment API key to console, ask user to add secrets to repo\n log.warning(messages.devinit.addGitSecretsIntro());\n log.help(\n messages.devinit.addGitSecretsHelp(\n git,\n existingDeployKey?.id,\n existingDeployKey?.sharedSecret\n )\n );\n }\n\n if (dryRun) {\n log.success(messages.devinit.dryRun());\n log.help(messages.devinit.noChanges());\n } else {\n log.success(messages.devinit.success());\n log.help(messages.devinit.startProjectTip());\n }\n }\n };\n\n ExecRequestHandler = async (blockIds: string[], overrideArgs?: string[]) => {\n // if no request handler exe\n // download it.\n\n // if update arg, redownload it\n\n const { log } = this;\n // const getPrefixOld = log.getPrefix;\n const exeHome = path.join(appRootDir, 'reqhan');\n const exe = 'Zengenti.Contensis.RequestHandler.LocalDevelopment';\n const exePath = path.join(exeHome, exe);\n const siteConfigPath = path.join(appRootDir, 'site_config.yaml');\n\n const siteConfig = await mapSiteConfigYaml(this);\n writeFile('site_config.yaml', stringifyYaml(siteConfig));\n\n const args = overrideArgs\n ? typeof overrideArgs?.[0] === 'string' &&\n overrideArgs[0].includes(' ', 2)\n ? overrideArgs[0].split(' ')\n : overrideArgs\n : []; // args could be [ '-c .\\\\site_config.yaml' ] or [ '-c', '.\\\\site_config.yaml' ]\n\n // Add required args\n if (!args.find(a => a === '-c')) args.push('-c', siteConfigPath);\n\n // const child = execFile(exePath, args);\n\n const child = spawn(exePath, args, { stdio: 'inherit' });\n\n // log.raw('');\n log.info(`Launching request handler...`);\n if (overrideArgs?.length)\n this.log.warning(\n `Spawning process with supplied args: ${JSON.stringify(\n child.spawnargs,\n null,\n 2\n )}`\n );\n\n let isRunning = false;\n\n // Log child output through event listeners\n child?.stdout?.on('data', data => {\n isRunning = true;\n log.raw(data);\n });\n\n child?.stderr?.on('data', data => {\n log.error(data);\n });\n\n child.on('spawn', () => {\n isRunning = true;\n log.help(\n `You may see a firewall popup requesting network access, it is safe to approve`\n );\n // log.getPrefix = () => Logger.infoText(`[rqh]`);\n });\n\n child.on('exit', code => {\n isRunning = false;\n\n log[code === 0 ? 'success' : 'warning'](\n `Request handler exited with code ${code}\\n`\n );\n });\n\n child.on('error', error => {\n isRunning = false;\n log.error(`Could not launch request handler due to error \\n${error}`);\n });\n\n await new Promise(resolve => setTimeout(resolve, 2000));\n\n // keep the method running until we can return\n while (true === true) {\n if (!isRunning) {\n // log.getPrefix = getPrefixOld; // restore logger state\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 1000));\n }\n };\n}\nexport const devCommand = (\n commandArgs: string[],\n outputOpts: OutputOptionsConstructorArg,\n contensisOpts: Partial<MigrateRequest> = {}\n) => {\n return new ContensisDev(['', '', ...commandArgs], outputOpts, contensisOpts);\n};\n\nexport default ContensisDev;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAe;AACf,2BAAsB;AACtB,sBAAqB;AACrB,kBAAiB;AAKjB,kCAA0B;AAG1B,wDAAkC;AAClC,mCAAqC;AACrC,wCAGO;AACP,2BAAgD;AAChD,kBAAgC;AAChC,oBAAwC;AACxC,kBAA+B;AAC/B,iBAA0B;AAC1B,kBAA8B;AAC9B,gBAAyB;AACzB,kBAA8B;AAC9B,yBAA8B;AAC9B,uBAAgD;AAEhD,MAAM,qBAAqB,4BAAAA,QAAc;AAAA,EACvC;AAAA,EACA;AAAA,EAEA,YACE,MACA,YACA,gBAAyC,CAAC,GAC1C;AACA,UAAM,MAAM,YAAY,aAAa;AAAA,EACvC;AAAA,EAEA,kBAAkB,OAAO,aAAqB,SAAc;AAE1D,UAAM,MAAO,KAAK,MAAM,IAAI,qBAAU,WAAW;AAEjD,UAAM,SAAS,IAAI,YAAY;AAC/B,QAAI,CAAC;AAAQ;AAEb,UAAM,EAAE,SAAS,MAAM,IAAI,QAAQ,CAAC;AACpC,UAAM,EAAE,YAAY,gBAAgB,KAAK,SAAS,IAAI;AACtD,UAAM,YAAY,MAAM,KAAK,iBAAiB;AAE9C,QAAI,WAAW;AAEb,YAAM,kBAAkB,CAACC,aAAoB;AAC3C,cAAM,UAAU;AAChB,YAAI,OAAOA,aAAY,YAAYA,SAAQ,UAAU,GAAG;AACtD,iBAAO,QAAQ,KAAKA,QAAO;AAAA,QAC7B;AAAO,iBAAO;AAAA,MAChB;AACA,UAAI,EAAE,QAAQ,IAAI,MAAM,gBAAAC,QAAS,OAAO;AAAA,QACtC,MAA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ED,UAAM,GAAG,QAAQ,UAAQ;AACvB,kBAAY;AAEZ,UAAI,SAAS,IAAI,YAAY;AAAA,QAC3B,oCAAoC;AAAA;AAAA,MACtC;AAAA,IACF,CAAC;AAED,UAAM,GAAG,SAAS,WAAS;AACzB,kBAAY;AACZ,UAAI,MAAM;AAAA,EAAmD,OAAO;AAAA,IACtE,CAAC;AAED,UAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,GAAI,CAAC;AAGtD,WAAO,MAAe;AACpB,UAAI,CAAC,WAAW;AAEd;AAAA,MACF;AACA,YAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,GAAI,CAAC;AAAA,IACxD;AAAA,EACF;AACF;AACO,MAAM,aAAa,CACxB,aACA,YACA,gBAAyC,CAAC,MACvC;AACH,SAAO,IAAI,aAAa,CAAC,IAAI,IAAI,GAAG,WAAW,GAAG,YAAY,aAAa;AAC7E;AAEA,IAAO,8BAAQ;",
4
+ "sourcesContent": ["import to from 'await-to-js';\nimport { spawn } from 'child_process';\nimport inquirer from 'inquirer';\nimport path from 'path';\n\nimport { Role } from 'contensis-management-api/lib/models';\nimport { MigrateRequest } from 'migratortron';\n\nimport ContensisRole from './ContensisRoleService';\nimport { OutputOptionsConstructorArg } from '~/models/CliService';\nimport { EnvContentsToAdd } from '~/models/DevService';\nimport { mapSiteConfigYaml } from '~/mappers/DevRequests-to-RequestHanderSiteConfigYaml';\nimport { mapCIWorkflowContent } from '~/mappers/DevInit-to-CIWorkflow';\nimport {\n deployKeyRole,\n devKeyRole,\n} from '~/mappers/DevInit-to-RolePermissions';\nimport { appRootDir, readFile, writeFile } from '~/providers/file-provider';\nimport { diffFileContent } from '~/util/diff';\nimport { mergeDotEnvFileContents } from '~/util/dotenv';\nimport { findByIdOrName } from '~/util/find';\nimport { GitHelper } from '~/util/git';\nimport { jsonFormatter } from '~/util/json.formatter';\nimport { winSlash } from '~/util/os';\nimport { stringifyYaml } from '~/util/yaml';\nimport { createSpinner } from 'nanospinner';\nimport { mergeContentsToAddWithGitignore } from '~/util/gitignore';\n\nclass ContensisDev extends ContensisRole {\n git!: GitHelper;\n blockId: string;\n\n constructor(\n args: string[],\n outputOpts?: OutputOptionsConstructorArg,\n contensisOpts: Partial<MigrateRequest> = {}\n ) {\n super(args, outputOpts, contensisOpts);\n }\n\n DevelopmentInit = async (projectHome: string, opts: any) => {\n // Retrieve git info\n const git = (this.git = new GitHelper(projectHome));\n // Check if we are in a git repo\n const isRepo = git.checkIsRepo();\n if (!isRepo) return;\n\n const { dryRun = false } = opts || {};\n const { currentEnv, currentProject, log, messages } = this;\n const contensis = await this.ConnectContensis();\n\n if (contensis) {\n // First we need to get the block id from the user\n const validateBlockId = (blockId: string) => {\n const pattern = /^[0-9a-z](-?[0-9a-z])*$/;\n if (blockId.length >= 1 && blockId.length <= 225) {\n return pattern.test(blockId);\n } else return false;\n };\n let { blockId } = await inquirer.prompt({\n name: 'blockId',\n type: 'input',\n prefix: '\uD83E\uDDF1',\n message: messages.devinit.blockIdQuestion,\n validate: validateBlockId,\n });\n // make sure block id is lowercase\n this.blockId = blockId.toLowerCase();\n log.success(`Valid block id: ${blockId.toLowerCase()}`);\n\n // Retrieve keys list for env\n const [keysErr, apiKeys] = await contensis.apiKeys.GetKeys();\n if (keysErr) {\n log.error(messages.keys.noList(currentEnv));\n log.error(jsonFormatter(keysErr));\n return;\n }\n const apiKeyExists = (findKey: string) =>\n apiKeys?.find(\n k => k.name.trim().toLowerCase() === findKey?.trim().toLowerCase()\n );\n\n // Retrieve ci workflow info\n const workflowFiles = git.workflows;\n\n // Set variables for performing operations and logging etc.\n let ciFileName = git.ciFileName;\n\n const apiKeyName = `block-${currentProject}-${blockId}`.toLowerCase();\n\n const devKeyName = `${apiKeyName}`;\n const devKeyDescription = `Created by Contensis to allow API access from the running block`;\n let existingDevKey = apiKeyExists(devKeyName);\n\n // if dev api key doesn't exisit go and create it (we need this for local development, we will store these details in the .env file).\n if (!existingDevKey) {\n existingDevKey = await this.CreateOrUpdateApiKey(\n existingDevKey,\n devKeyName,\n devKeyDescription\n );\n log.success('Successfully created development key');\n }\n\n const deployKeyName = `${apiKeyName}-ci`;\n const deployKeyDescription = `Created by the Contensis CLI for use in continuous integration`;\n\n let existingDeployKey = apiKeyExists(deployKeyName);\n\n // if deploy api key doesn't exisit go and create it (we need this for yml file).\n if (!existingDeployKey) {\n existingDeployKey = await this.CreateOrUpdateApiKey(\n existingDeployKey,\n deployKeyName,\n deployKeyDescription\n );\n log.success('Successfully created deploy key');\n }\n\n // check we have the deply key so we can assign them to this values\n if (existingDeployKey) {\n // Add client id and secret to global 'this'\n this.clientId = existingDeployKey?.id;\n this.clientSecret = existingDeployKey?.sharedSecret;\n }\n\n // const blockId = git.name;\n const errors = [] as AppError[];\n\n // Start render console output\n log.raw('');\n log.success(messages.devinit.intro());\n log.raw('');\n log.raw(\n log.infoText(\n messages.devinit.projectDetails(\n git.name,\n currentEnv,\n currentProject,\n blockId,\n git\n )\n )\n );\n log.raw(\n log.infoText(\n messages.devinit.developmentKey(devKeyName, !!existingDevKey)\n )\n );\n log.raw(\n log.infoText(\n messages.devinit.deploymentKey(deployKeyName, !!existingDeployKey)\n )\n );\n log.raw('');\n\n if (Array.isArray(workflowFiles) && workflowFiles.length > 1) {\n // Choose GitHub workflow file (if multiple)\n ({ ciFileName } = await inquirer.prompt([\n {\n type: 'list',\n prefix: '\u29F0',\n message: messages.devinit.ciMultipleChoices(),\n name: 'ciFileName',\n choices: workflowFiles,\n default: workflowFiles.find(f => f.includes('docker')),\n },\n ]));\n log.raw('');\n git.ciFileName = ciFileName;\n }\n\n log.raw(log.infoText(messages.devinit.ciDetails(ciFileName)));\n\n let mappedWorkflow;\n // Location for Client ID / Secret.\n const { clientDetailsOption } = await inquirer.prompt({\n name: 'clientDetailsOption',\n type: 'list',\n prefix: '\uD83D\uDD11',\n // Where would you like to store your Client ID/Secret?\n message: messages.devinit.clientDetailsLocation(),\n choices: [\n messages.devinit.clientDetailsInGit(git),\n messages.devinit.clientDetailsInEnv(),\n ],\n });\n\n // global 'clientDetailsLocation' variable stores users input on where client id / secert are stored\n if (clientDetailsOption === messages.devinit.clientDetailsInEnv()) {\n this.clientDetailsLocation = 'env';\n } else {\n this.clientDetailsLocation = 'git';\n }\n\n if (this.clientDetailsLocation === 'env') {\n // Update CI Workflow to pull from ENV variables\n mappedWorkflow = await mapCIWorkflowContent(this);\n log.help(messages.devinit.ciIntro(git, 'env'));\n } else {\n // Look at the workflow file content and make updates\n mappedWorkflow = await mapCIWorkflowContent(this);\n log.help(messages.devinit.ciIntro(git, 'git'));\n }\n\n if (!dryRun) {\n // Confirm prompt\n const { confirm } = await inquirer.prompt([\n {\n type: 'confirm',\n message: messages.devinit.confirm(),\n name: 'confirm',\n default: false,\n },\n ]);\n log.raw('');\n if (!confirm) return;\n }\n\n // Fetching access token\n let accessToken: string | undefined = undefined;\n log.raw('');\n\n const spinner = createSpinner(messages.devinit.accessTokenFetch());\n spinner.start();\n\n const token = await this.GetDeliveryApiKey();\n\n if (token) {\n spinner.success();\n this.log.success(messages.devinit.accessTokenSuccess(token));\n accessToken = token;\n } else {\n spinner.error();\n this.log.error(messages.devinit.accessTokenFailed());\n return;\n }\n\n // Magic happens...\n const checkpoint = (op: string) => {\n if (errors.length) throw errors[0];\n else log.debug(`${op} completed ok`);\n return true;\n };\n\n // Arrange API keys for development and deployment\n const [getRolesErr, roles] = await to(contensis.roles.GetRoles());\n if (!roles && getRolesErr) errors.push(getRolesErr);\n checkpoint(`fetched ${roles?.length} roles`);\n if (dryRun) {\n checkpoint(`skip api key creation (dry-run)`);\n } else {\n // Ensure deploy API key is assigned to a role with the right permissions\n const deployRoleName = `Role for CI push of block '${blockId}'`;\n const deplyRoleDescription = `Created by the Contensis CLI for use in continuous integration`;\n let existingDeployRole = findByIdOrName(\n roles || [],\n deployRoleName,\n true\n ) as Role | undefined;\n existingDeployRole = await this.CreateOrUpdateRole(\n existingDeployRole,\n deployKeyRole(deployRoleName, deplyRoleDescription)\n );\n\n checkpoint('deploy key role assigned');\n log.success(messages.devinit.createDeployKey(deployRoleName, true));\n checkpoint('api keys done');\n }\n\n const envFilePath = `${projectHome}/.env`;\n const existingEnvFile = readFile(envFilePath);\n let existingEnvFileArray = (existingEnvFile || '')\n .split('\\n')\n .filter(l => !!l);\n\n // Update or create a file called .env in project home\n const envContentsToAdd: EnvContentsToAdd = {\n ALIAS: currentEnv,\n PROJECT_API_ID: currentProject,\n BLOCK_ID: blockId,\n };\n if (accessToken) envContentsToAdd['ACCESS_TOKEN'] = accessToken;\n // add client id and secret to the env file\n if (this.clientDetailsLocation === 'env') {\n envContentsToAdd['CONTENSIS_CLIENT_ID'] = existingDevKey?.id;\n envContentsToAdd['CONTENSIS_CLIENT_SECRET'] =\n existingDevKey?.sharedSecret;\n }\n\n // if we have client id / secret in our env remove it\n const removeEnvItems = (items: string[]) => {\n const indexesToRemove = [];\n\n for (let i = 0; i < existingEnvFileArray.length; i++) {\n for (const item of items) {\n if (existingEnvFileArray[i].includes(item)) {\n indexesToRemove.push(i);\n break;\n }\n }\n }\n\n for (let i = indexesToRemove.length - 1; i >= 0; i--) {\n existingEnvFileArray.splice(indexesToRemove[i], 1);\n }\n };\n\n if (this.clientDetailsLocation === 'git') {\n removeEnvItems(['CONTENSIS_CLIENT_ID', 'CONTENSIS_CLIENT_SECRET']);\n }\n\n const envFileLines = mergeDotEnvFileContents(\n existingEnvFileArray,\n envContentsToAdd\n );\n const newEnvFileContent = envFileLines.join('\\n');\n const envDiff = diffFileContent(existingEnvFile || '', newEnvFileContent);\n\n if (dryRun) {\n if (envDiff) {\n log.info(`Updating .env file ${winSlash(envFilePath)}:\\n${envDiff}`);\n log.raw('');\n }\n checkpoint('skip .env file update (dry-run)');\n } else {\n if (envDiff) log.info(`updating .env file ${winSlash(envFilePath)}`);\n writeFile(envFilePath, envFileLines.join('\\n'));\n checkpoint('.env file updated');\n log.success(messages.devinit.writeEnvFile());\n // log.help(messages.devinit.useEnvFileTip());\n }\n\n // Update git ignore\n const gitIgnorePath = `${projectHome}/.gitignore`;\n const gitIgnoreContentsToAdd = ['.env'];\n mergeContentsToAddWithGitignore(gitIgnorePath, gitIgnoreContentsToAdd);\n\n // Update CI file -- different for GH/GL\n if (mappedWorkflow?.diff) {\n log.info(\n `Updating ${winSlash(ciFileName)} file:\\n${mappedWorkflow.diff}`\n );\n log.raw('');\n }\n if (dryRun) {\n checkpoint('skip CI file update (dry-run)');\n //log.object(ciFileLines);\n } else {\n if (mappedWorkflow?.newWorkflow) {\n if (mappedWorkflow?.diff) {\n writeFile(git.ciFilePath, mappedWorkflow.newWorkflow);\n log.success(messages.devinit.writeCiFile(`./${ciFileName}`));\n log.info(\n messages.devinit.ciBlockTip(blockId, currentEnv, currentProject)\n );\n } else {\n log.info(messages.devinit.ciFileNoChanges(`./${ciFileName}`));\n }\n checkpoint('CI file updated');\n }\n }\n\n if (this.clientDetailsLocation === 'git') {\n // Echo Deployment API key to console, ask user to add secrets to repo\n log.warning(messages.devinit.addGitSecretsIntro());\n log.help(\n messages.devinit.addGitSecretsHelp(\n git,\n existingDeployKey?.id,\n existingDeployKey?.sharedSecret\n )\n );\n }\n\n if (dryRun) {\n log.success(messages.devinit.dryRun());\n log.help(messages.devinit.noChanges());\n } else {\n log.success(messages.devinit.success());\n log.help(messages.devinit.startProjectTip());\n }\n }\n };\n\n ExecRequestHandler = async (blockIds: string[], overrideArgs?: string[]) => {\n // if no request handler exe\n // download it.\n\n // if update arg, redownload it\n\n const { log } = this;\n // const getPrefixOld = log.getPrefix;\n const exeHome = path.join(appRootDir, 'reqhan');\n const exe = 'Zengenti.Contensis.RequestHandler.LocalDevelopment';\n const exePath = path.join(exeHome, exe);\n const siteConfigPath = path.join(appRootDir, 'site_config.yaml');\n\n const siteConfig = await mapSiteConfigYaml(this);\n writeFile('site_config.yaml', stringifyYaml(siteConfig));\n\n const args = overrideArgs\n ? typeof overrideArgs?.[0] === 'string' &&\n overrideArgs[0].includes(' ', 2)\n ? overrideArgs[0].split(' ')\n : overrideArgs\n : []; // args could be [ '-c .\\\\site_config.yaml' ] or [ '-c', '.\\\\site_config.yaml' ]\n\n // Add required args\n if (!args.find(a => a === '-c')) args.push('-c', siteConfigPath);\n\n // const child = execFile(exePath, args);\n\n const child = spawn(exePath, args, { stdio: 'inherit' });\n\n // log.raw('');\n log.info(`Launching request handler...`);\n if (overrideArgs?.length)\n this.log.warning(\n `Spawning process with supplied args: ${JSON.stringify(\n child.spawnargs,\n null,\n 2\n )}`\n );\n\n let isRunning = false;\n\n // Log child output through event listeners\n child?.stdout?.on('data', data => {\n isRunning = true;\n log.raw(data);\n });\n\n child?.stderr?.on('data', data => {\n log.error(data);\n });\n\n child.on('spawn', () => {\n isRunning = true;\n log.help(\n `You may see a firewall popup requesting network access, it is safe to approve`\n );\n // log.getPrefix = () => Logger.infoText(`[rqh]`);\n });\n\n child.on('exit', code => {\n isRunning = false;\n\n log[code === 0 ? 'success' : 'warning'](\n `Request handler exited with code ${code}\\n`\n );\n });\n\n child.on('error', error => {\n isRunning = false;\n log.error(`Could not launch request handler due to error \\n${error}`);\n });\n\n await new Promise(resolve => setTimeout(resolve, 2000));\n\n // keep the method running until we can return\n while (true === true) {\n if (!isRunning) {\n // log.getPrefix = getPrefixOld; // restore logger state\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 1000));\n }\n };\n}\nexport const devCommand = (\n commandArgs: string[],\n outputOpts: OutputOptionsConstructorArg,\n contensisOpts: Partial<MigrateRequest> = {}\n) => {\n return new ContensisDev(['', '', ...commandArgs], outputOpts, contensisOpts);\n};\n\nexport default ContensisDev;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAe;AACf,2BAAsB;AACtB,sBAAqB;AACrB,kBAAiB;AAKjB,kCAA0B;AAG1B,wDAAkC;AAClC,mCAAqC;AACrC,wCAGO;AACP,2BAAgD;AAChD,kBAAgC;AAChC,oBAAwC;AACxC,kBA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AACA,YAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,GAAI,CAAC;AAAA,IACxD;AAAA,EACF;AACF;AACO,MAAM,aAAa,CACxB,aACA,YACA,gBAAyC,CAAC,MACvC;AACH,SAAO,IAAI,aAAa,CAAC,IAAI,IAAI,GAAG,WAAW,GAAG,YAAY,aAAa;AAC7E;AAEA,IAAO,8BAAQ;",
6
6
  "names": ["ContensisRole", "blockId", "inquirer", "to", "path"]
7
7
  }
@@ -32,11 +32,18 @@ var import_logger = require("./logger");
32
32
  const mergeContentsToAddWithGitignore = (filename, contentsToAdd) => {
33
33
  if (import_fs.default.existsSync(filename)) {
34
34
  const existingContent = import_fs.default.readFileSync(filename, "utf-8");
35
- const existingLines = existingContent.split("\n").filter((line) => line.trim() !== "");
36
- const mergedLines = [...existingLines, ...contentsToAdd];
37
- const updatedContent = Array.from(new Set(mergedLines)).sort().join("\n");
38
- import_fs.default.writeFileSync(filename, updatedContent);
39
- import_logger.Logger.success(".gitignore file updated");
35
+ const existingContentSet = new Set(
36
+ existingContent.split("\n").filter((line) => line.trim() !== "")
37
+ );
38
+ const newContents = contentsToAdd.filter(
39
+ (contentsItem) => !existingContentSet.has(contentsItem)
40
+ );
41
+ if (newContents.length >= 1) {
42
+ import_fs.default.appendFileSync(filename, "\n" + newContents.join("\n"));
43
+ import_logger.Logger.success(".gitignore file updated");
44
+ } else {
45
+ import_logger.Logger.success(".gitignore checked, nothing to update");
46
+ }
40
47
  } else {
41
48
  const gitignoreContent = contentsToAdd.join("\n");
42
49
  import_fs.default.writeFileSync(filename, gitignoreContent);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/util/gitignore.ts"],
4
- "sourcesContent": ["import fs from 'fs';\nimport { Logger } from './logger';\n\nexport const mergeContentsToAddWithGitignore = (\n filename: string,\n contentsToAdd: string[]\n) => {\n // Check if .gitignore file already exists\n if (fs.existsSync(filename)) {\n // Read the existing .gitignore file\n const existingContent = fs.readFileSync(filename, 'utf-8');\n\n // Split the existing content by newline and remove empty lines\n const existingLines = existingContent\n .split('\\n')\n .filter(line => line.trim() !== '');\n\n // Merge the existing content with the new contents to add\n const mergedLines = [...existingLines, ...contentsToAdd];\n\n // Deduplicate and sort the lines\n const updatedContent = Array.from(new Set(mergedLines)).sort().join('\\n');\n\n // Write the updated content back to .gitignore\n fs.writeFileSync(filename, updatedContent);\n\n Logger.success('.gitignore file updated');\n } else {\n // If .gitignore doesn't exist, create one and add the contents to add\n const gitignoreContent = contentsToAdd.join('\\n');\n fs.writeFileSync(filename, gitignoreContent);\n\n Logger.success('.gitignore file created and updated');\n }\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,oBAAuB;AAEhB,MAAM,kCAAkC,CAC7C,UACA,kBACG;AAEH,MAAI,UAAAA,QAAG,WAAW,QAAQ,GAAG;AAE3B,UAAM,kBAAkB,UAAAA,QAAG,aAAa,UAAU,OAAO;AAGzD,UAAM,gBAAgB,gBACnB,MAAM,IAAI,EACV,OAAO,UAAQ,KAAK,KAAK,MAAM,EAAE;AAGpC,UAAM,cAAc,CAAC,GAAG,eAAe,GAAG,aAAa;AAGvD,UAAM,iBAAiB,MAAM,KAAK,IAAI,IAAI,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI;AAGxE,cAAAA,QAAG,cAAc,UAAU,cAAc;AAEzC,yBAAO,QAAQ,yBAAyB;AAAA,EAC1C,OAAO;AAEL,UAAM,mBAAmB,cAAc,KAAK,IAAI;AAChD,cAAAA,QAAG,cAAc,UAAU,gBAAgB;AAE3C,yBAAO,QAAQ,qCAAqC;AAAA,EACtD;AACF;",
4
+ "sourcesContent": ["import fs from 'fs';\nimport { Logger } from './logger';\n\nexport const mergeContentsToAddWithGitignore = (\n filename: string,\n contentsToAdd: string[]\n) => {\n // Check if .gitignore file already exists\n if (fs.existsSync(filename)) {\n // Read the existing .gitignore file\n const existingContent = fs.readFileSync(filename, 'utf-8');\n\n // Create a Set from existing patterns for fast look-up\n const existingContentSet = new Set(\n existingContent.split('\\n').filter(line => line.trim() !== '')\n );\n\n // Filter out patterns that already exist\n const newContents = contentsToAdd.filter(\n contentsItem => !existingContentSet.has(contentsItem)\n );\n\n if (newContents.length >= 1) {\n // Append the new patterns to the end of the existing .gitignore content\n fs.appendFileSync(filename, '\\n' + newContents.join('\\n'));\n Logger.success('.gitignore file updated');\n } else {\n Logger.success('.gitignore checked, nothing to update');\n }\n } else {\n // If .gitignore doesn't exist, create one and add the contents\n const gitignoreContent = contentsToAdd.join('\\n');\n fs.writeFileSync(filename, gitignoreContent);\n\n Logger.success('.gitignore file created and updated');\n }\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,oBAAuB;AAEhB,MAAM,kCAAkC,CAC7C,UACA,kBACG;AAEH,MAAI,UAAAA,QAAG,WAAW,QAAQ,GAAG;AAE3B,UAAM,kBAAkB,UAAAA,QAAG,aAAa,UAAU,OAAO;AAGzD,UAAM,qBAAqB,IAAI;AAAA,MAC7B,gBAAgB,MAAM,IAAI,EAAE,OAAO,UAAQ,KAAK,KAAK,MAAM,EAAE;AAAA,IAC/D;AAGA,UAAM,cAAc,cAAc;AAAA,MAChC,kBAAgB,CAAC,mBAAmB,IAAI,YAAY;AAAA,IACtD;AAEA,QAAI,YAAY,UAAU,GAAG;AAE3B,gBAAAA,QAAG,eAAe,UAAU,OAAO,YAAY,KAAK,IAAI,CAAC;AACzD,2BAAO,QAAQ,yBAAyB;AAAA,IAC1C,OAAO;AACL,2BAAO,QAAQ,uCAAuC;AAAA,IACxD;AAAA,EACF,OAAO;AAEL,UAAM,mBAAmB,cAAc,KAAK,IAAI;AAChD,cAAAA,QAAG,cAAc,UAAU,gBAAgB;AAE3C,yBAAO,QAAQ,qCAAqC;AAAA,EACtD;AACF;",
6
6
  "names": ["fs"]
7
7
  }
package/dist/version.js CHANGED
@@ -21,7 +21,7 @@ __export(version_exports, {
21
21
  LIB_VERSION: () => LIB_VERSION
22
22
  });
23
23
  module.exports = __toCommonJS(version_exports);
24
- const LIB_VERSION = "1.0.9-beta.8";
24
+ const LIB_VERSION = "1.0.10-beta.0";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  LIB_VERSION
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["export const LIB_VERSION = \"1.0.9-beta.8\";\n"],
4
+ "sourcesContent": ["export const LIB_VERSION = \"1.0.10-beta.0\";\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contensis-cli",
3
- "version": "1.0.9-beta.8",
3
+ "version": "1.0.10-beta.0",
4
4
  "description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
5
5
  "repository": "https://github.com/contensis/node-cli",
6
6
  "homepage": "https://github.com/contensis/node-cli/tree/main/packages/contensis-cli#readme",
@@ -403,7 +403,7 @@ const mapGitHubActionCIWorkflowContent = async (
403
403
  await addAppImageUri();
404
404
 
405
405
  const newJob: GitHubActionPushBlockJob = {
406
- name: 'Deploy container image to Contensis',
406
+ name: 'Push block to Contensis',
407
407
  'runs-on': 'ubuntu-latest',
408
408
  needs,
409
409
  steps: [addGitHubActionJobStep],
@@ -52,8 +52,8 @@ class ContensisDev extends ContensisRole {
52
52
  if (contensis) {
53
53
  // First we need to get the block id from the user
54
54
  const validateBlockId = (blockId: string) => {
55
- const pattern = /^[a-z-]*$/;
56
- if (typeof blockId === 'string' && blockId.length >= 3) {
55
+ const pattern = /^[0-9a-z](-?[0-9a-z])*$/;
56
+ if (blockId.length >= 1 && blockId.length <= 225) {
57
57
  return pattern.test(blockId);
58
58
  } else return false;
59
59
  };
@@ -86,8 +86,10 @@ class ContensisDev extends ContensisRole {
86
86
  // Set variables for performing operations and logging etc.
87
87
  let ciFileName = git.ciFileName;
88
88
 
89
- const devKeyName = `${blockId} development`;
90
- const devKeyDescription = `${blockId} [contensis-cli]`;
89
+ const apiKeyName = `block-${currentProject}-${blockId}`.toLowerCase();
90
+
91
+ const devKeyName = `${apiKeyName}`;
92
+ const devKeyDescription = `Created by Contensis to allow API access from the running block`;
91
93
  let existingDevKey = apiKeyExists(devKeyName);
92
94
 
93
95
  // if dev api key doesn't exisit go and create it (we need this for local development, we will store these details in the .env file).
@@ -100,8 +102,8 @@ class ContensisDev extends ContensisRole {
100
102
  log.success('Successfully created development key');
101
103
  }
102
104
 
103
- const deployKeyName = `${blockId} deployment`;
104
- const deployKeyDescription = `${blockId} deploy [contensis-cli]`;
105
+ const deployKeyName = `${apiKeyName}-ci`;
106
+ const deployKeyDescription = `Created by the Contensis CLI for use in continuous integration`;
105
107
 
106
108
  let existingDeployKey = apiKeyExists(deployKeyName);
107
109
 
@@ -249,18 +251,20 @@ class ContensisDev extends ContensisRole {
249
251
  checkpoint(`skip api key creation (dry-run)`);
250
252
  } else {
251
253
  // Ensure deploy API key is assigned to a role with the right permissions
254
+ const deployRoleName = `Role for CI push of block '${blockId}'`;
255
+ const deplyRoleDescription = `Created by the Contensis CLI for use in continuous integration`;
252
256
  let existingDeployRole = findByIdOrName(
253
257
  roles || [],
254
- deployKeyName,
258
+ deployRoleName,
255
259
  true
256
260
  ) as Role | undefined;
257
261
  existingDeployRole = await this.CreateOrUpdateRole(
258
262
  existingDeployRole,
259
- deployKeyRole(deployKeyName, deployKeyDescription)
263
+ deployKeyRole(deployRoleName, deplyRoleDescription)
260
264
  );
261
265
 
262
266
  checkpoint('deploy key role assigned');
263
- log.success(messages.devinit.createDeployKey(deployKeyName, true));
267
+ log.success(messages.devinit.createDeployKey(deployRoleName, true));
264
268
  checkpoint('api keys done');
265
269
  }
266
270
 
@@ -10,23 +10,25 @@ export const mergeContentsToAddWithGitignore = (
10
10
  // Read the existing .gitignore file
11
11
  const existingContent = fs.readFileSync(filename, 'utf-8');
12
12
 
13
- // Split the existing content by newline and remove empty lines
14
- const existingLines = existingContent
15
- .split('\n')
16
- .filter(line => line.trim() !== '');
13
+ // Create a Set from existing patterns for fast look-up
14
+ const existingContentSet = new Set(
15
+ existingContent.split('\n').filter(line => line.trim() !== '')
16
+ );
17
17
 
18
- // Merge the existing content with the new contents to add
19
- const mergedLines = [...existingLines, ...contentsToAdd];
18
+ // Filter out patterns that already exist
19
+ const newContents = contentsToAdd.filter(
20
+ contentsItem => !existingContentSet.has(contentsItem)
21
+ );
20
22
 
21
- // Deduplicate and sort the lines
22
- const updatedContent = Array.from(new Set(mergedLines)).sort().join('\n');
23
-
24
- // Write the updated content back to .gitignore
25
- fs.writeFileSync(filename, updatedContent);
26
-
27
- Logger.success('.gitignore file updated');
23
+ if (newContents.length >= 1) {
24
+ // Append the new patterns to the end of the existing .gitignore content
25
+ fs.appendFileSync(filename, '\n' + newContents.join('\n'));
26
+ Logger.success('.gitignore file updated');
27
+ } else {
28
+ Logger.success('.gitignore checked, nothing to update');
29
+ }
28
30
  } else {
29
- // If .gitignore doesn't exist, create one and add the contents to add
31
+ // If .gitignore doesn't exist, create one and add the contents
30
32
  const gitignoreContent = contentsToAdd.join('\n');
31
33
  fs.writeFileSync(filename, gitignoreContent);
32
34
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.9-beta.8";
1
+ export const LIB_VERSION = "1.0.10-beta.0";