contensis-cli 1.0.0-beta.91 → 1.0.0-beta.93
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.
- package/dist/mappers/DevInit-to-CIWorkflow.js +4 -1
- package/dist/mappers/DevInit-to-CIWorkflow.js.map +2 -2
- package/dist/services/ContensisDevService.js +12 -10
- package/dist/services/ContensisDevService.js.map +2 -2
- package/dist/util/diff.js +6 -1
- package/dist/util/diff.js.map +2 -2
- package/dist/util/os.js +3 -0
- package/dist/util/os.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/src/mappers/DevInit-to-CIWorkflow.ts +4 -1
- package/src/services/ContensisDevService.ts +11 -10
- package/src/util/diff.ts +7 -2
- package/src/util/os.ts +5 -0
- package/src/version.ts +1 -1
|
@@ -25,6 +25,7 @@ var import_jsonpath_plus = require("jsonpath-plus");
|
|
|
25
25
|
var import_file_provider = require("../providers/file-provider");
|
|
26
26
|
var import_diff = require("../util/diff");
|
|
27
27
|
var import_logger = require("../util/logger");
|
|
28
|
+
var import_os = require("../util/os");
|
|
28
29
|
var import_yaml = require("../util/yaml");
|
|
29
30
|
const mapCIWorkflowContent = (cli, git) => {
|
|
30
31
|
const workflowFile = (0, import_file_provider.readFile)(git.ciFilePath);
|
|
@@ -112,7 +113,9 @@ ${workflowDoc}`
|
|
|
112
113
|
`GitHub workflow YAML did not pass validation check`
|
|
113
114
|
);
|
|
114
115
|
}
|
|
115
|
-
const newWorkflow =
|
|
116
|
+
const newWorkflow = (0, import_os.normaliseLineEndings)(
|
|
117
|
+
workflowDoc.toString({ lineWidth: 0 })
|
|
118
|
+
);
|
|
116
119
|
return {
|
|
117
120
|
existingWorkflow: workflowFile,
|
|
118
121
|
newWorkflow,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/mappers/DevInit-to-CIWorkflow.ts"],
|
|
4
|
-
"sourcesContent": ["import { JSONPath, JSONPathOptions } from 'jsonpath-plus';\nimport { readFile } from '~/providers/file-provider';\nimport ContensisDev from '~/services/ContensisDevService';\nimport { diffFileContent } from '~/util/diff';\nimport { GitHelper } from '~/util/git';\nimport { logError } from '~/util/logger';\nimport { parseYamlDocument, validateWorkflowYaml } from '~/util/yaml';\n\ntype MappedWorkflowOutput = {\n existingWorkflow: string;\n newWorkflow: string;\n diff: string;\n};\n\nexport const mapCIWorkflowContent = (\n cli: ContensisDev,\n git: GitHelper\n): MappedWorkflowOutput | undefined => {\n // get existing workflow file\n const workflowFile = readFile(git.ciFilePath);\n if (!workflowFile) return undefined;\n\n const blockId = git.name;\n if (git.type === 'github') {\n const addGitHubActionJobStep = {\n name: 'Push block to Contensis',\n id: 'push-block',\n uses: 'contensis/block-push@v1',\n with: {\n 'block-id': blockId,\n // 'image-uri': '${{ steps.build.outputs.image-uri }}',\n alias: cli.currentEnv,\n 'project-id': cli.currentProject,\n 'client-id': '${{ secrets.CONTENSIS_CLIENT_ID }}',\n 'shared-secret': '${{ secrets.CONTENSIS_SHARED_SECRET }}',\n },\n };\n\n // parse yaml to js\n const workflowDoc = parseYamlDocument(workflowFile);\n const workflow = workflowDoc.toJS();\n const setWorkflowElement = (path: string | any[], value: any) => {\n const findPath =\n typeof path === 'string' && path.includes('.')\n ? path\n .split('.')\n .map(p => (Number(p) || Number(p) !== 0 ? p : Number(p)))\n : path;\n\n if (workflowDoc.hasIn(findPath)) {\n workflowDoc.setIn(findPath, value);\n } else {\n workflowDoc.addIn(findPath, value);\n // }\n }\n };\n const findExistingJobSteps = (\n resultType: JSONPathOptions['resultType']\n ) => {\n // look for line in job\n // jobs.x.steps[uses: contensis/block-push]\n const path =\n git.type === 'github'\n ? '$.jobs..steps.*[?(@property === \"uses\" && @.match(/^contensis\\\\/block-push/i))]^'\n : // TODO: add jsonpath for gitlab file\n '';\n\n const existingJobStep = JSONPath({\n path,\n json: workflow,\n resultType: resultType,\n });\n\n return existingJobStep;\n };\n\n const existingJobStep = findExistingJobSteps('all');\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(`${stepPath}.with.alias`, cli.currentEnv);\n setWorkflowElement(`${stepPath}.with.project-id`, cli.currentProject);\n setWorkflowElement(`${stepPath}.with.block-id`, blockId);\n setWorkflowElement(\n `${stepPath}.with.client-id`,\n '${{ secrets.CONTENSIS_CLIENT_ID }}'\n );\n setWorkflowElement(\n `${stepPath}.with.shared-secret`,\n '${{ secrets.CONTENSIS_SHARED_SECRET }}'\n );\n } else {\n // create job with push step\n workflowDoc.addIn(['jobs'], {\n key: 'deploy',\n value: {\n name: 'Push image to Contensis',\n 'runs-on': 'ubuntu-latest',\n steps: [addGitHubActionJobStep],\n },\n });\n }\n\n // Workflow validation provided by @action-validator/core package\n const workflowIsValid = validateWorkflowYaml(workflowDoc.toString());\n\n if (workflowIsValid === true) {\n cli.log.debug(\n `New file content to write to ${git.ciFilePath}\\n\\n${workflowDoc}`\n );\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 const newWorkflow = workflowDoc.toString({ lineWidth: 0 });\n\n return {\n existingWorkflow: workflowFile,\n newWorkflow,\n diff: diffFileContent(workflowFile, newWorkflow),\n };\n }\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAA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G,EACpB,QAAQ,KAAK,EAAE,EACf,WAAW,KAAK,EAAE;AAErB,UAAI,IAAI;AAAA,QACN,4BAA4B;AAAA,oBAChB,KAAK,MAAM;AAAA,kBACb,KAAK,MAAM;AAAA;AAAA,MACvB;AAEA,yBAAmB,GAAG,uBAAuB,IAAI,UAAU;AAC3D,yBAAmB,GAAG,4BAA4B,IAAI,cAAc;AACpE,yBAAmB,GAAG,0BAA0B,OAAO;AACvD;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF;AACA;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,OAAO;AAEL,kBAAY,MAAM,CAAC,MAAM,GAAG;AAAA,QAC1B,KAAK;AAAA,QACL,OAAO;AAAA,UACL,MAAM;AAAA,UACN,WAAW;AAAA,UACX,OAAO,CAAC,sBAAsB;AAAA,QAChC;AAAA,MACF,CAAC;AAAA,IACH;AAGA,UAAM,sBAAkB,kCAAqB,YAAY,SAAS,CAAC;AAEnE,QAAI,oBAAoB,MAAM;AAC5B,UAAI,IAAI;AAAA,QACN,gCAAgC,IAAI;AAAA;AAAA,EAAiB;AAAA,MACvD;AAAA,IACF,WAAW,MAAM,QAAQ,eAAe,GAAG;AAEzC;AAAA,QACE;AAAA,UACE,GAAG,gBAAgB;AAAA,YACjB,SAAO,IAAI,MAAM,GAAG,IAAI,SAAS,IAAI,UAAU,IAAI,OAAO;AAAA,UAC5D;AAAA,UACA,YAAY,SAAS;AAAA,QACvB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,UAAM,
|
|
4
|
+
"sourcesContent": ["import { JSONPath, JSONPathOptions } from 'jsonpath-plus';\nimport { readFile } from '~/providers/file-provider';\nimport ContensisDev from '~/services/ContensisDevService';\nimport { diffFileContent } from '~/util/diff';\nimport { GitHelper } from '~/util/git';\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 = (\n cli: ContensisDev,\n git: GitHelper\n): MappedWorkflowOutput | undefined => {\n // get existing workflow file\n const workflowFile = readFile(git.ciFilePath);\n if (!workflowFile) return undefined;\n\n const blockId = git.name;\n if (git.type === 'github') {\n const addGitHubActionJobStep = {\n name: 'Push block to Contensis',\n id: 'push-block',\n uses: 'contensis/block-push@v1',\n with: {\n 'block-id': blockId,\n // 'image-uri': '${{ steps.build.outputs.image-uri }}',\n alias: cli.currentEnv,\n 'project-id': cli.currentProject,\n 'client-id': '${{ secrets.CONTENSIS_CLIENT_ID }}',\n 'shared-secret': '${{ secrets.CONTENSIS_SHARED_SECRET }}',\n },\n };\n\n // parse yaml to js\n const workflowDoc = parseYamlDocument(workflowFile);\n const workflow = workflowDoc.toJS();\n const setWorkflowElement = (path: string | any[], value: any) => {\n const findPath =\n typeof path === 'string' && path.includes('.')\n ? path\n .split('.')\n .map(p => (Number(p) || Number(p) !== 0 ? p : Number(p)))\n : path;\n\n if (workflowDoc.hasIn(findPath)) {\n workflowDoc.setIn(findPath, value);\n } else {\n workflowDoc.addIn(findPath, value);\n // }\n }\n };\n const findExistingJobSteps = (\n resultType: JSONPathOptions['resultType']\n ) => {\n // look for line in job\n // jobs.x.steps[uses: contensis/block-push]\n const path =\n git.type === 'github'\n ? '$.jobs..steps.*[?(@property === \"uses\" && @.match(/^contensis\\\\/block-push/i))]^'\n : // TODO: add jsonpath for gitlab file\n '';\n\n const existingJobStep = JSONPath({\n path,\n json: workflow,\n resultType: resultType,\n });\n\n return existingJobStep;\n };\n\n const existingJobStep = findExistingJobSteps('all');\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(`${stepPath}.with.alias`, cli.currentEnv);\n setWorkflowElement(`${stepPath}.with.project-id`, cli.currentProject);\n setWorkflowElement(`${stepPath}.with.block-id`, blockId);\n setWorkflowElement(\n `${stepPath}.with.client-id`,\n '${{ secrets.CONTENSIS_CLIENT_ID }}'\n );\n setWorkflowElement(\n `${stepPath}.with.shared-secret`,\n '${{ secrets.CONTENSIS_SHARED_SECRET }}'\n );\n } else {\n // create job with push step\n workflowDoc.addIn(['jobs'], {\n key: 'deploy',\n value: {\n name: 'Push image to Contensis',\n 'runs-on': 'ubuntu-latest',\n steps: [addGitHubActionJobStep],\n },\n });\n }\n\n // Workflow validation provided by @action-validator/core package\n const workflowIsValid = validateWorkflowYaml(workflowDoc.toString());\n\n if (workflowIsValid === true) {\n cli.log.debug(\n `New file content to write to ${git.ciFilePath}\\n\\n${workflowDoc}`\n );\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 const newWorkflow = normaliseLineEndings(\n workflowDoc.toString({ lineWidth: 0 })\n );\n\n return {\n existingWorkflow: workflowFile,\n newWorkflow,\n diff: diffFileContent(workflowFile, newWorkflow),\n };\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA0C;AAC1C,2BAAyB;AAEzB,kBAAgC;AAEhC,oBAAyB;AACzB,gBAAqC;AACrC,kBAAwD;AAQjD,MAAM,uBAAuB,CAClC,KACA,QACqC;AAErC,QAAM,mBAAe,+BAAS,IAAI,UAAU;AAC5C,MAAI,CAAC;AAAc,WAAO;AAE1B,QAAM,UA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AG,4BAA4B,IAAI,cAAc;AACpE,yBAAmB,GAAG,0BAA0B,OAAO;AACvD;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF;AACA;AAAA,QACE,GAAG;AAAA,QACH;AAAA,MACF;AAAA,IACF,OAAO;AAEL,kBAAY,MAAM,CAAC,MAAM,GAAG;AAAA,QAC1B,KAAK;AAAA,QACL,OAAO;AAAA,UACL,MAAM;AAAA,UACN,WAAW;AAAA,UACX,OAAO,CAAC,sBAAsB;AAAA,QAChC;AAAA,MACF,CAAC;AAAA,IACH;AAGA,UAAM,sBAAkB,kCAAqB,YAAY,SAAS,CAAC;AAEnE,QAAI,oBAAoB,MAAM;AAC5B,UAAI,IAAI;AAAA,QACN,gCAAgC,IAAI;AAAA;AAAA,EAAiB;AAAA,MACvD;AAAA,IACF,WAAW,MAAM,QAAQ,eAAe,GAAG;AAEzC;AAAA,QACE;AAAA,UACE,GAAG,gBAAgB;AAAA,YACjB,SAAO,IAAI,MAAM,GAAG,IAAI,SAAS,IAAI,UAAU,IAAI,OAAO;AAAA,UAC5D;AAAA,UACA,YAAY,SAAS;AAAA,QACvB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,UAAM,kBAAc;AAAA,MAClB,YAAY,SAAS,EAAE,WAAW,EAAE,CAAC;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,kBAAkB;AAAA,MAClB;AAAA,MACA,UAAM,6BAAgB,cAAc,WAAW;AAAA,IACjD;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["existingJobStep"]
|
|
7
7
|
}
|
|
@@ -32,17 +32,18 @@ var import_await_to_js = __toESM(require("await-to-js"));
|
|
|
32
32
|
var import_child_process = require("child_process");
|
|
33
33
|
var import_inquirer = __toESM(require("inquirer"));
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_yaml = require("yaml");
|
|
36
35
|
var import_ContensisRoleService = __toESM(require("./ContensisRoleService"));
|
|
37
36
|
var import_DevRequests_to_RequestHanderSiteConfigYaml = require("../mappers/DevRequests-to-RequestHanderSiteConfigYaml");
|
|
37
|
+
var import_DevInit_to_CIWorkflow = require("../mappers/DevInit-to-CIWorkflow");
|
|
38
38
|
var import_DevInit_to_RolePermissions = require("../mappers/DevInit-to-RolePermissions");
|
|
39
39
|
var import_file_provider = require("../providers/file-provider");
|
|
40
|
-
var import_json = require("../util/json.formatter");
|
|
41
|
-
var import_git = require("../util/git");
|
|
42
|
-
var import_find = require("../util/find");
|
|
43
|
-
var import_dotenv = require("../util/dotenv");
|
|
44
|
-
var import_DevInit_to_CIWorkflow = require("../mappers/DevInit-to-CIWorkflow");
|
|
45
40
|
var import_diff = require("../util/diff");
|
|
41
|
+
var import_dotenv = require("../util/dotenv");
|
|
42
|
+
var import_find = require("../util/find");
|
|
43
|
+
var import_git = require("../util/git");
|
|
44
|
+
var import_json = require("../util/json.formatter");
|
|
45
|
+
var import_os = require("../util/os");
|
|
46
|
+
var import_yaml = require("../util/yaml");
|
|
46
47
|
class ContensisDev extends import_ContensisRoleService.default {
|
|
47
48
|
constructor(args, outputOpts, contensisOpts = {}) {
|
|
48
49
|
super(args, outputOpts, contensisOpts);
|
|
@@ -191,10 +192,11 @@ class ContensisDev extends import_ContensisRoleService.default {
|
|
|
191
192
|
(existingEnvFile || "").split("\n").filter((l) => !!l),
|
|
192
193
|
envContentsToAdd
|
|
193
194
|
);
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
const newEnvFileContent = (0, import_os.normaliseLineEndings)(
|
|
196
|
+
`${envFileLines.join("\n")}
|
|
197
|
+
`
|
|
197
198
|
);
|
|
199
|
+
const envDiff = (0, import_diff.diffFileContent)(existingEnvFile || "", newEnvFileContent);
|
|
198
200
|
if (dryRun) {
|
|
199
201
|
if (envDiff) {
|
|
200
202
|
log.info(`updating .env file ${envFilePath}: ${envDiff}`);
|
|
@@ -249,7 +251,7 @@ class ContensisDev extends import_ContensisRoleService.default {
|
|
|
249
251
|
const exePath = import_path.default.join(exeHome, exe);
|
|
250
252
|
const siteConfigPath = import_path.default.join(import_file_provider.appRootDir, "site_config.yaml");
|
|
251
253
|
const siteConfig = await (0, import_DevRequests_to_RequestHanderSiteConfigYaml.mapSiteConfigYaml)(this);
|
|
252
|
-
(0, import_file_provider.writeFile)("site_config.yaml", (0, import_yaml.
|
|
254
|
+
(0, import_file_provider.writeFile)("site_config.yaml", (0, import_yaml.stringifyYaml)(siteConfig));
|
|
253
255
|
const args = overrideArgs ? typeof (overrideArgs == null ? void 0 : overrideArgs[0]) === "string" && overrideArgs[0].includes(" ", 2) ? overrideArgs[0].split(" ") : overrideArgs : [];
|
|
254
256
|
if (!args.find((a) => a === "-c"))
|
|
255
257
|
args.push("-c", siteConfigPath);
|
|
@@ -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 { execFile, spawn } from 'child_process';\nimport inquirer from 'inquirer';\nimport path from 'path';\nimport { parse, stringify } from 'yaml';\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 {\n deployKeyRole,\n devKeyRole,\n} from '~/mappers/DevInit-to-RolePermissions';\nimport { appRootDir, readFile, writeFile } from '~/providers/file-provider';\nimport { jsonFormatter } from '~/util/json.formatter';\nimport { GitHelper } from '~/util/git';\nimport { findByIdOrName } from '~/util/find';\nimport { mergeDotEnvFileContents } from '~/util/dotenv';\nimport { mapCIWorkflowContent } from '~/mappers/DevInit-to-CIWorkflow';\nimport { diffFileContent } from '~/util/diff';\n\nclass ContensisDev extends ContensisRole {\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 const { dryRun = false } = opts || {};\n const { currentEnv, currentProject, log, messages } = this;\n const contensis = await this.ConnectContensis();\n\n if (contensis) {\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 git info\n const git = new GitHelper(projectHome);\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 = `${git.name} development`;\n const devKeyDescription = `${git.name} [contensis-cli]`;\n let existingDevKey = apiKeyExists(devKeyName);\n\n const deployKeyName = `${git.name} deployment`;\n const deployKeyDescription = `${git.name} deploy [contensis-cli]`;\n\n let existingDeployKey = apiKeyExists(deployKeyName);\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 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 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 // Look at the workflow file content and make updates\n const mappedWorkflow = mapCIWorkflowContent(this, git);\n\n log.help(messages.devinit.ciIntro(git));\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 // Access token prompt\n const { accessToken }: { accessToken: string } = await inquirer.prompt([\n {\n type: 'input',\n message: messages.devinit.accessTokenPrompt(),\n name: 'accessToken',\n },\n ]);\n log.raw('');\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 existingDevKey = await this.CreateOrUpdateApiKey(\n existingDevKey,\n devKeyName,\n devKeyDescription\n );\n checkpoint('dev key created');\n\n existingDeployKey = await this.CreateOrUpdateApiKey(\n existingDeployKey,\n deployKeyName,\n deployKeyDescription\n );\n checkpoint('deploy key created');\n\n // Ensure dev API key is assigned to a role\n let existingDevRole = findByIdOrName(roles || [], devKeyName, true) as\n | Role\n | undefined;\n existingDevRole = await this.CreateOrUpdateRole(\n existingDevRole,\n devKeyRole(devKeyName, devKeyDescription)\n );\n checkpoint('dev key role assigned');\n log.success(messages.devinit.createDevKey(devKeyName, true));\n\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 // Update or create a file called .env in project home\n const envContentsToAdd: EnvContentsToAdd = {\n ALIAS: currentEnv,\n PROJECT: currentProject,\n };\n if (accessToken) envContentsToAdd['ACCESS_TOKEN'] = accessToken;\n\n const envFilePath = `${projectHome}/.env`;\n const existingEnvFile = readFile(envFilePath);\n const envFileLines = mergeDotEnvFileContents(\n (existingEnvFile || '').split('\\n').filter(l => !!l),\n envContentsToAdd\n );\n const envDiff = diffFileContent(\n existingEnvFile || '',\n envFileLines.join('\\n')\n );\n\n if (dryRun) {\n if (envDiff) {\n log.info(`updating .env file ${envFilePath}: ${envDiff}`);\n log.raw('');\n }\n checkpoint('skip .env file update (dry-run)');\n } else {\n if (envDiff) log.info(`updating .env file ${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 CI file -- different for GH/GL -- create a sample one with build?\n if (dryRun) {\n if (mappedWorkflow?.diff) {\n log.info(`updating${ciFileName} file: ${mappedWorkflow.diff}`);\n log.raw('');\n }\n checkpoint('skip CI file update (dry-run)');\n //log.object(ciFileLines);\n } else {\n if (mappedWorkflow?.diff) log.info(`updating${ciFileName} file`);\n writeFile(git.ciFilePath, [].join('\\n'));\n log.success(messages.devinit.writeCiFile(`./${ciFileName}`));\n log.info(\n messages.devinit.ciBlockTip(blockId, currentEnv, currentProject)\n );\n checkpoint('CI file updated');\n }\n\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 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', stringify(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,2BAAgC;AAChC,sBAAqB;AACrB,kBAAiB;
|
|
4
|
+
"sourcesContent": ["import to from 'await-to-js';\nimport { execFile, 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 { normaliseLineEndings } from '~/util/os';\nimport { stringifyYaml } from '~/util/yaml';\n\nclass ContensisDev extends ContensisRole {\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 const { dryRun = false } = opts || {};\n const { currentEnv, currentProject, log, messages } = this;\n const contensis = await this.ConnectContensis();\n\n if (contensis) {\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 git info\n const git = new GitHelper(projectHome);\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 = `${git.name} development`;\n const devKeyDescription = `${git.name} [contensis-cli]`;\n let existingDevKey = apiKeyExists(devKeyName);\n\n const deployKeyName = `${git.name} deployment`;\n const deployKeyDescription = `${git.name} deploy [contensis-cli]`;\n\n let existingDeployKey = apiKeyExists(deployKeyName);\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 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 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 // Look at the workflow file content and make updates\n const mappedWorkflow = mapCIWorkflowContent(this, git);\n\n log.help(messages.devinit.ciIntro(git));\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 // Access token prompt\n const { accessToken }: { accessToken: string } = await inquirer.prompt([\n {\n type: 'input',\n message: messages.devinit.accessTokenPrompt(),\n name: 'accessToken',\n },\n ]);\n log.raw('');\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 existingDevKey = await this.CreateOrUpdateApiKey(\n existingDevKey,\n devKeyName,\n devKeyDescription\n );\n checkpoint('dev key created');\n\n existingDeployKey = await this.CreateOrUpdateApiKey(\n existingDeployKey,\n deployKeyName,\n deployKeyDescription\n );\n checkpoint('deploy key created');\n\n // Ensure dev API key is assigned to a role\n let existingDevRole = findByIdOrName(roles || [], devKeyName, true) as\n | Role\n | undefined;\n existingDevRole = await this.CreateOrUpdateRole(\n existingDevRole,\n devKeyRole(devKeyName, devKeyDescription)\n );\n checkpoint('dev key role assigned');\n log.success(messages.devinit.createDevKey(devKeyName, true));\n\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 // Update or create a file called .env in project home\n const envContentsToAdd: EnvContentsToAdd = {\n ALIAS: currentEnv,\n PROJECT: currentProject,\n };\n if (accessToken) envContentsToAdd['ACCESS_TOKEN'] = accessToken;\n\n const envFilePath = `${projectHome}/.env`;\n const existingEnvFile = readFile(envFilePath);\n const envFileLines = mergeDotEnvFileContents(\n (existingEnvFile || '').split('\\n').filter(l => !!l),\n envContentsToAdd\n );\n const newEnvFileContent = normaliseLineEndings(\n `${envFileLines.join('\\n')}\\n`\n );\n const envDiff = diffFileContent(existingEnvFile || '', newEnvFileContent);\n\n if (dryRun) {\n if (envDiff) {\n log.info(`updating .env file ${envFilePath}: ${envDiff}`);\n log.raw('');\n }\n checkpoint('skip .env file update (dry-run)');\n } else {\n if (envDiff) log.info(`updating .env file ${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 CI file -- different for GH/GL -- create a sample one with build?\n if (dryRun) {\n if (mappedWorkflow?.diff) {\n log.info(`updating${ciFileName} file: ${mappedWorkflow.diff}`);\n log.raw('');\n }\n checkpoint('skip CI file update (dry-run)');\n //log.object(ciFileLines);\n } else {\n if (mappedWorkflow?.diff) log.info(`updating${ciFileName} file`);\n writeFile(git.ciFilePath, [].join('\\n'));\n log.success(messages.devinit.writeCiFile(`./${ciFileName}`));\n log.info(\n messages.devinit.ciBlockTip(blockId, currentEnv, currentProject)\n );\n checkpoint('CI file updated');\n }\n\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 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,2BAAgC;AAChC,sBAAqB;AACrB,kBAAiB;AA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AM;AACtB,kBAAY;AACZ,UAAI;AAAA,QACF;AAAA,MACF;AAAA,IAEF,CAAC;AAED,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;",
|
|
6
6
|
"names": ["ContensisRole", "inquirer", "to", "path"]
|
|
7
7
|
}
|
package/dist/util/diff.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(diff_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(diff_exports);
|
|
31
31
|
var import_chalk = __toESM(require("chalk"));
|
|
32
32
|
var import_diff = require("diff");
|
|
33
|
+
var import_os = require("./os");
|
|
33
34
|
const diffLogStrings = (updates, previous) => {
|
|
34
35
|
const lastFewLines = previous.split("\n").slice(-10);
|
|
35
36
|
const incomingLines = updates.split("\n");
|
|
@@ -42,7 +43,11 @@ const diffLogStrings = (updates, previous) => {
|
|
|
42
43
|
return incomingLines.slice(differentFromPos).join("\n");
|
|
43
44
|
};
|
|
44
45
|
const diffFileContent = (existingContent, newContent) => {
|
|
45
|
-
const
|
|
46
|
+
const existingContentNormalised = (0, import_os.normaliseLineEndings)(existingContent, "\n");
|
|
47
|
+
const newContentNormalised = (0, import_os.normaliseLineEndings)(newContent, "\n");
|
|
48
|
+
const diff = (0, import_diff.diffLines)(existingContentNormalised, newContentNormalised, {
|
|
49
|
+
newlineIsToken: true
|
|
50
|
+
});
|
|
46
51
|
const diffRanges = addDiffPositionInfo(diff);
|
|
47
52
|
const output = [];
|
|
48
53
|
const lnSpaceLength = Math.max(
|
package/dist/util/diff.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/diff.ts"],
|
|
4
|
-
"sourcesContent": ["import chalk from 'chalk';\nimport { Change, diffLines } from 'diff';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,kBAAkC;
|
|
4
|
+
"sourcesContent": ["import chalk from 'chalk';\nimport { Change, diffLines } from 'diff';\nimport { normaliseLineEndings } from './os';\n\nexport const diffLogStrings = (updates: string, previous: string) => {\n const lastFewLines = previous.split('\\n').slice(-10);\n const incomingLines = updates.split('\\n');\n\n // Find the line indices in the incoming lines\n // of the last few lines previously rendered\n const incomingLineIndices = [];\n for (const lastRenderedLine of lastFewLines) {\n if (lastRenderedLine.length > 10)\n incomingLineIndices.push(incomingLines.lastIndexOf(lastRenderedLine));\n }\n\n // Get the new lines from the next position on from the last of the already shown lines\n const differentFromPos = Math.max(...incomingLineIndices) + 1 || 0;\n // Return just the incoming lines from the position we matched\n return incomingLines.slice(differentFromPos).join('\\n');\n};\n\nexport const diffFileContent = (\n existingContent: string,\n newContent: string\n) => {\n const existingContentNormalised = normaliseLineEndings(existingContent, '\\n');\n const newContentNormalised = normaliseLineEndings(newContent, '\\n');\n\n const diff = diffLines(existingContentNormalised, newContentNormalised, {\n newlineIsToken: true,\n });\n const diffRanges = addDiffPositionInfo(diff);\n\n // Create formatted output for console\n const output: string[] = [];\n const lnSpaceLength = Math.max(\n ...diffRanges.map(d => d.startLineNumber.toString().length)\n );\n\n const lnSpaces = Array(lnSpaceLength).join(' ');\n\n for (let i = 0; i < diffRanges.length; i++) {\n const part = diffRanges[i];\n if (part.added || part.removed) {\n const colour = part.added ? 'green' : part.removed ? 'red' : 'grey';\n\n if (part.value !== '\\n')\n output.push(\n `\\n${part.value\n .split('\\n')\n .map((ln, idx) =>\n ln.trim() !== ''\n ? `${\n part.startLineNumber ? part.startLineNumber + idx : lnSpaces\n }${part.added ? '+' : part.removed ? '-' : ' '} ${chalk[\n colour\n ](`${ln}`)}`\n : ln\n )\n .join('\\n')}`\n );\n }\n }\n\n return output.join('');\n // return retOutput.endsWith('\\n') ? retOutput : `${retOutput}\\n`;\n};\n\nconst addDiffPositionInfo = (diff: Change[]) => {\n const diffRanges: (Change & {\n startLineNumber: number;\n startColumn: number;\n endLineNumber: number;\n endColumn: number;\n })[] = [];\n\n let lineNumber = 0;\n let column = 0;\n for (let partIndex = 0; partIndex < diff.length; partIndex++) {\n const part = diff[partIndex];\n\n // // Skip any parts that aren't in `after`\n // if (part.removed === true) {\n // continue;\n // }\n\n const startLineNumber = lineNumber;\n const startColumn = column;\n\n // Split the part into lines. Loop throug these lines to find\n // the line no. and column at the end of this part.\n const substring = part.value;\n const lines = substring.split('\\n');\n lines.forEach((line, lineIndex) => {\n // The first `line` is actually just a continuation of the last line\n if (lineIndex === 0) {\n column += line.length;\n // All other lines come after a line break.\n } else if (lineIndex > 0) {\n lineNumber += 1;\n column = line.length;\n }\n });\n\n // Save a range for all of the parts with position info added\n if (part.added === true || part.removed === true) {\n diffRanges.push({\n startLineNumber: startLineNumber + 1,\n startColumn: startColumn,\n endLineNumber: lineNumber,\n endColumn: column,\n ...part,\n });\n }\n }\n return diffRanges;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,kBAAkC;AAClC,gBAAqC;AAE9B,MAAM,iBAAiB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,UACN,EACC,KAAK,IAAI;AAAA,QACd;AAAA,IACJ;AAAA,EACF;AAEA,SAAO,OAAO,KAAK,EAAE;AAEvB;AAEA,MAAM,sBAAsB,CAAC,SAAmB;AAC9C,QAAM,aAKC,CAAC;AAER,MAAI,aAAa;AACjB,MAAI,SAAS;AACb,WAAS,YAAY,GAAG,YAAY,KAAK,QAAQ,aAAa;AAC5D,UAAM,OAAO,KAAK;AAOlB,UAAM,kBAAkB;AACxB,UAAM,cAAc;AAIpB,UAAM,YAAY,KAAK;AACvB,UAAM,QAAQ,UAAU,MAAM,IAAI;AAClC,UAAM,QAAQ,CAAC,MAAM,cAAc;AAEjC,UAAI,cAAc,GAAG;AACnB,kBAAU,KAAK;AAAA,MAEjB,WAAW,YAAY,GAAG;AACxB,sBAAc;AACd,iBAAS,KAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAGD,QAAI,KAAK,UAAU,QAAQ,KAAK,YAAY,MAAM;AAChD,iBAAW,KAAK;AAAA,QACd,iBAAiB,kBAAkB;AAAA,QACnC;AAAA,QACA,eAAe;AAAA,QACf,WAAW;AAAA,QACX,GAAG;AAAA,MACL,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
package/dist/util/os.js
CHANGED
|
@@ -25,15 +25,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var os_exports = {};
|
|
26
26
|
__export(os_exports, {
|
|
27
27
|
linuxSlash: () => linuxSlash,
|
|
28
|
+
normaliseLineEndings: () => normaliseLineEndings,
|
|
28
29
|
winSlash: () => winSlash
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(os_exports);
|
|
31
32
|
var import_os = __toESM(require("os"));
|
|
32
33
|
const winSlash = (str) => import_os.default.platform() === "win32" ? str.replaceAll("/", "\\") : str;
|
|
33
34
|
const linuxSlash = (str) => import_os.default.platform() === "win32" ? str.replaceAll("\\", "/") : str;
|
|
35
|
+
const normaliseLineEndings = (str, lineEnd = import_os.default.platform() === "win32" ? "\r\n" : "n") => str.replace(/\r?\n/g, lineEnd);
|
|
34
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
37
|
0 && (module.exports = {
|
|
36
38
|
linuxSlash,
|
|
39
|
+
normaliseLineEndings,
|
|
37
40
|
winSlash
|
|
38
41
|
});
|
|
39
42
|
//# sourceMappingURL=os.js.map
|
package/dist/util/os.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/os.ts"],
|
|
4
|
-
"sourcesContent": ["import os from 'os';\n\nexport const winSlash = (str: string) =>\n os.platform() === 'win32' ? str.replaceAll('/', '\\\\') : str;\n\nexport const linuxSlash = (str: string) =>\n os.platform() === 'win32' ? str.replaceAll('\\\\', '/') : str;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAER,MAAM,WAAW,CAAC,QACvB,UAAAA,QAAG,SAAS,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,IAAI;AAEnD,MAAM,aAAa,CAAC,QACzB,UAAAA,QAAG,SAAS,MAAM,UAAU,IAAI,WAAW,MAAM,GAAG,IAAI;",
|
|
4
|
+
"sourcesContent": ["import os from 'os';\n\nexport const winSlash = (str: string) =>\n os.platform() === 'win32' ? str.replaceAll('/', '\\\\') : str;\n\nexport const linuxSlash = (str: string) =>\n os.platform() === 'win32' ? str.replaceAll('\\\\', '/') : str;\n\nexport const normaliseLineEndings = (\n str: string,\n lineEnd = os.platform() === 'win32' ? '\\r\\n' : 'n'\n) => str.replace(/\\r?\\n/g, lineEnd);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAER,MAAM,WAAW,CAAC,QACvB,UAAAA,QAAG,SAAS,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,IAAI;AAEnD,MAAM,aAAa,CAAC,QACzB,UAAAA,QAAG,SAAS,MAAM,UAAU,IAAI,WAAW,MAAM,GAAG,IAAI;AAEnD,MAAM,uBAAuB,CAClC,KACA,UAAU,UAAAA,QAAG,SAAS,MAAM,UAAU,SAAS,QAC5C,IAAI,QAAQ,UAAU,OAAO;",
|
|
6
6
|
"names": ["os"]
|
|
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.0-beta.
|
|
24
|
+
const LIB_VERSION = "1.0.0-beta.93";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
LIB_VERSION
|
package/dist/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.
|
|
4
|
+
"sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.93\";\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.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.93",
|
|
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",
|
|
@@ -4,6 +4,7 @@ import ContensisDev from '~/services/ContensisDevService';
|
|
|
4
4
|
import { diffFileContent } from '~/util/diff';
|
|
5
5
|
import { GitHelper } from '~/util/git';
|
|
6
6
|
import { logError } from '~/util/logger';
|
|
7
|
+
import { normaliseLineEndings } from '~/util/os';
|
|
7
8
|
import { parseYamlDocument, validateWorkflowYaml } from '~/util/yaml';
|
|
8
9
|
|
|
9
10
|
type MappedWorkflowOutput = {
|
|
@@ -139,7 +140,9 @@ export const mapCIWorkflowContent = (
|
|
|
139
140
|
`GitHub workflow YAML did not pass validation check`
|
|
140
141
|
);
|
|
141
142
|
}
|
|
142
|
-
const newWorkflow =
|
|
143
|
+
const newWorkflow = normaliseLineEndings(
|
|
144
|
+
workflowDoc.toString({ lineWidth: 0 })
|
|
145
|
+
);
|
|
143
146
|
|
|
144
147
|
return {
|
|
145
148
|
existingWorkflow: workflowFile,
|
|
@@ -2,7 +2,6 @@ import to from 'await-to-js';
|
|
|
2
2
|
import { execFile, spawn } from 'child_process';
|
|
3
3
|
import inquirer from 'inquirer';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import { parse, stringify } from 'yaml';
|
|
6
5
|
|
|
7
6
|
import { Role } from 'contensis-management-api/lib/models';
|
|
8
7
|
import { MigrateRequest } from 'migratortron';
|
|
@@ -11,17 +10,19 @@ import ContensisRole from './ContensisRoleService';
|
|
|
11
10
|
import { OutputOptionsConstructorArg } from '~/models/CliService';
|
|
12
11
|
import { EnvContentsToAdd } from '~/models/DevService';
|
|
13
12
|
import { mapSiteConfigYaml } from '~/mappers/DevRequests-to-RequestHanderSiteConfigYaml';
|
|
13
|
+
import { mapCIWorkflowContent } from '~/mappers/DevInit-to-CIWorkflow';
|
|
14
14
|
import {
|
|
15
15
|
deployKeyRole,
|
|
16
16
|
devKeyRole,
|
|
17
17
|
} from '~/mappers/DevInit-to-RolePermissions';
|
|
18
18
|
import { appRootDir, readFile, writeFile } from '~/providers/file-provider';
|
|
19
|
-
import { jsonFormatter } from '~/util/json.formatter';
|
|
20
|
-
import { GitHelper } from '~/util/git';
|
|
21
|
-
import { findByIdOrName } from '~/util/find';
|
|
22
|
-
import { mergeDotEnvFileContents } from '~/util/dotenv';
|
|
23
|
-
import { mapCIWorkflowContent } from '~/mappers/DevInit-to-CIWorkflow';
|
|
24
19
|
import { diffFileContent } from '~/util/diff';
|
|
20
|
+
import { mergeDotEnvFileContents } from '~/util/dotenv';
|
|
21
|
+
import { findByIdOrName } from '~/util/find';
|
|
22
|
+
import { GitHelper } from '~/util/git';
|
|
23
|
+
import { jsonFormatter } from '~/util/json.formatter';
|
|
24
|
+
import { normaliseLineEndings } from '~/util/os';
|
|
25
|
+
import { stringifyYaml } from '~/util/yaml';
|
|
25
26
|
|
|
26
27
|
class ContensisDev extends ContensisRole {
|
|
27
28
|
constructor(
|
|
@@ -211,10 +212,10 @@ class ContensisDev extends ContensisRole {
|
|
|
211
212
|
(existingEnvFile || '').split('\n').filter(l => !!l),
|
|
212
213
|
envContentsToAdd
|
|
213
214
|
);
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
envFileLines.join('\n')
|
|
215
|
+
const newEnvFileContent = normaliseLineEndings(
|
|
216
|
+
`${envFileLines.join('\n')}\n`
|
|
217
217
|
);
|
|
218
|
+
const envDiff = diffFileContent(existingEnvFile || '', newEnvFileContent);
|
|
218
219
|
|
|
219
220
|
if (dryRun) {
|
|
220
221
|
if (envDiff) {
|
|
@@ -282,7 +283,7 @@ class ContensisDev extends ContensisRole {
|
|
|
282
283
|
const siteConfigPath = path.join(appRootDir, 'site_config.yaml');
|
|
283
284
|
|
|
284
285
|
const siteConfig = await mapSiteConfigYaml(this);
|
|
285
|
-
writeFile('site_config.yaml',
|
|
286
|
+
writeFile('site_config.yaml', stringifyYaml(siteConfig));
|
|
286
287
|
|
|
287
288
|
const args = overrideArgs
|
|
288
289
|
? typeof overrideArgs?.[0] === 'string' &&
|
package/src/util/diff.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { Change, diffLines } from 'diff';
|
|
3
|
-
import {
|
|
3
|
+
import { normaliseLineEndings } from './os';
|
|
4
4
|
|
|
5
5
|
export const diffLogStrings = (updates: string, previous: string) => {
|
|
6
6
|
const lastFewLines = previous.split('\n').slice(-10);
|
|
@@ -24,7 +24,12 @@ export const diffFileContent = (
|
|
|
24
24
|
existingContent: string,
|
|
25
25
|
newContent: string
|
|
26
26
|
) => {
|
|
27
|
-
const
|
|
27
|
+
const existingContentNormalised = normaliseLineEndings(existingContent, '\n');
|
|
28
|
+
const newContentNormalised = normaliseLineEndings(newContent, '\n');
|
|
29
|
+
|
|
30
|
+
const diff = diffLines(existingContentNormalised, newContentNormalised, {
|
|
31
|
+
newlineIsToken: true,
|
|
32
|
+
});
|
|
28
33
|
const diffRanges = addDiffPositionInfo(diff);
|
|
29
34
|
|
|
30
35
|
// Create formatted output for console
|
package/src/util/os.ts
CHANGED
|
@@ -5,3 +5,8 @@ export const winSlash = (str: string) =>
|
|
|
5
5
|
|
|
6
6
|
export const linuxSlash = (str: string) =>
|
|
7
7
|
os.platform() === 'win32' ? str.replaceAll('\\', '/') : str;
|
|
8
|
+
|
|
9
|
+
export const normaliseLineEndings = (
|
|
10
|
+
str: string,
|
|
11
|
+
lineEnd = os.platform() === 'win32' ? '\r\n' : 'n'
|
|
12
|
+
) => str.replace(/\r?\n/g, lineEnd);
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.0.0-beta.
|
|
1
|
+
export const LIB_VERSION = "1.0.0-beta.93";
|