From 3df87e39cd7586551b657d01861bf4f38dcbbf2e Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 24 Jul 2024 00:35:05 +0530 Subject: [PATCH 01/15] fixed the SRE issues --- .../contentstack-audit/src/messages/index.ts | 10 ++-- .../src/utils/asset-helper.ts | 47 +++++++++++++---- .../src/utils/entries-helper.ts | 51 +++++++++++++++---- .../05-Update-reference-entry-from-mapper.js | 14 ++--- .../src/utils/modules.js | 9 ++-- 5 files changed, 95 insertions(+), 36 deletions(-) diff --git a/packages/contentstack-audit/src/messages/index.ts b/packages/contentstack-audit/src/messages/index.ts index 61e1e0d827..c6058e5622 100644 --- a/packages/contentstack-audit/src/messages/index.ts +++ b/packages/contentstack-audit/src/messages/index.ts @@ -76,13 +76,9 @@ function $t(msg: string, args: Record): string { if (!msg) return ''; for (const key of Object.keys(args)) { - const escapedKey = escapeRegExp(key); - const escapedKeyRegex = new RegExp(`{${escapedKey}}`, 'g'); - let { status } = validateRegex(escapedKeyRegex) - if (status === 'safe') { - const sanitizedValue = args[key] ? escapeRegExp(args[key]) : ''; - msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey); - } + const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const placeholder = `{${escapedKey}}`; + msg = msg.split(placeholder).join(args[key]); } return msg; diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index d13bb8dd57..4dc2d73b21 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -247,31 +247,56 @@ export const lookupAssets = function ( assetUids = _.uniq(assetUids); assetUrls = _.uniq(assetUrls); let entry = JSON.stringify(data.entry); + + // Note: Use this code in case production breaks + // assetUrls.forEach(function (assetUrl: any) { + // let mappedAssetUrl = mappedAssetUrls[assetUrl]; + // if (typeof mappedAssetUrl !== 'undefined') { + // //NOTE - This code was added to resolve the SRE issue but once the code was merged Assets URLs in JSON RTE started breaking + // // const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&'); + // // const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&'); + // // entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl); + // entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); + // matchedUrls.push(mappedAssetUrl); + // } else { + // unmatchedUrls.push(assetUrl); + // } + // }); + // To be deleted when prod breaks assetUrls.forEach(function (assetUrl: any) { let mappedAssetUrl = mappedAssetUrls[assetUrl]; if (typeof mappedAssetUrl !== 'undefined') { - //NOTE - This code was added to resolve the SRE issue but once the code was merged Assets URLs in JSON RTE started breaking - // const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&'); - // const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&'); - // entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl); - entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); + entry = entry.split(assetUrl).join(mappedAssetUrl); matchedUrls.push(mappedAssetUrl); } else { unmatchedUrls.push(assetUrl); } }); + // Note: Use this incase the production breaks + // assetUids.forEach(function (assetUid: any) { + // let uid = mappedAssetUids[assetUid]; + // if (typeof uid !== 'undefined') { + // const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + // const regex = new RegExp(`\\b${escapedAssetUid}\\b`, 'img'); + // let { status } = validateRegex(new RegExp(regex, 'img')); + // if (status === 'safe') { + // entry = entry.replace(regex, uid); + // matchedUids.push(assetUid); + // } + // } else { + // unmatchedUids.push(assetUid); + // } + // }); + + // To be deleted when prod breaks assetUids.forEach(function (assetUid: any) { let uid = mappedAssetUids[assetUid]; if (typeof uid !== 'undefined') { const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - const regex = new RegExp(`\\b${escapedAssetUid}\\b`, 'img'); - let { status } = validateRegex(new RegExp(regex, 'img')); - if (status === 'safe') { - entry = entry.replace(regex, uid); - matchedUids.push(assetUid); - } + entry = entry.split(escapedAssetUid).join(uid); + matchedUids.push(assetUid); } else { unmatchedUids.push(assetUid); } diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index 2a6019225c..c57f02b04f 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -89,7 +89,9 @@ export const lookupEntries = function ( } else { const key = _parent[j]; if (Object.prototype.hasOwnProperty.call(_entry, key)) { - _entry = _entry[key]; + const tempEntry = Object.create(null); + _.merge(tempEntry, _entry); + _entry = tempEntry[key]; let _keys = _.clone(_parent).splice(j + 1, len); if (Array.isArray(_entry)) { for (let i = 0, _i = _entry?.length; i < _i; i++) { @@ -201,20 +203,51 @@ export const lookupEntries = function ( uids = _.uniq(uids); let entry = JSON.stringify(data.entry); + + //Note: Use this in case prod breaks + // uids?.forEach(function (uid: any) { + // if (mappedUids.hasOwnProperty(uid)) { + // const sanitizedUid = escapeRegExp(uid); + // const escapedMappedUid = escapeRegExp(mappedUids[uid]); + // const uidRegex = new RegExp(`\\b${sanitizedUid}\\b`, 'img'); + // let { status } = validateRegex(uidRegex); + // if (status === 'safe') { + // entry = entry.replace(uidRegex, escapedMappedUid); + // mapped.push(uid); + // } + // } else { + // unmapped.push(uid); + // } + // }); + uids?.forEach(function (uid: any) { if (mappedUids.hasOwnProperty(uid)) { const sanitizedUid = escapeRegExp(uid); const escapedMappedUid = escapeRegExp(mappedUids[uid]); - const uidRegex = new RegExp(`\\b${sanitizedUid}\\b`, 'img'); - let { status } = validateRegex(uidRegex); - if (status === 'safe') { - entry = entry.replace(uidRegex, escapedMappedUid); - mapped.push(uid); + let index = entry.indexOf(sanitizedUid); + while (index !== -1) { + if ((index === 0 || !isWordCharacter(entry.charAt(index - 1))) && + (index + sanitizedUid.length === entry.length || !isWordCharacter(entry.charAt(index + sanitizedUid.length)))) { + entry = entry.substring(0, index) + escapedMappedUid + entry.substring(index + sanitizedUid.length); + index += escapedMappedUid.length; + } else { + index += sanitizedUid.length; + } + index = entry.indexOf(sanitizedUid, index); } + mapped.push(uid); } else { unmapped.push(uid); } }); + // Note: Delete when prod breaks + function escapeRegExp(str:string) { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + } + + function isWordCharacter(char:string) { + return /[a-zA-Z0-9_]/.test(char); + } if (unmapped.length > 0) { let unmappedUids = fileHelper.readFileSync(path.join(uidMapperPath, 'unmapped-uids.json')); @@ -580,9 +613,9 @@ export const restoreJsonRteEntryRefs = ( function updateUids(str: string, match: string, uidMapper: Record) { const sanitizedMatch = escapeRegExp(match); - const regex = new RegExp(`\\b${sanitizedMatch}\\b`, 'g'); - let { status } = validateRegex(regex); - if (status === 'safe') return str.replace(regex, (matchedString) => uidMapper[matchedString]); + const parts = str.split(sanitizedMatch); + let result = parts.join(uidMapper[match] || sanitizedMatch); + return result; } function setDirtyTrue(jsonRteChild: any) { diff --git a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js index d02ddc2d68..c67fd60659 100644 --- a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js +++ b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js @@ -7,7 +7,7 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf const modules = ['entries', 'assets', 'extensions', 'marketplace_apps']; const readAllModulesUids = (filePath) => { - let uidMapping = {}; + let uidMapping = Object.create(null); modules.forEach((module) => { const mappingFilePath = path.join(sanitizePath(filePath), 'mapper', sanitizePath(module), 'uid-mapping.json'); @@ -15,9 +15,11 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf const mappedIds = JSON.parse(fs.readFileSync(sanitizePath(mappingFilePath), 'utf-8')); if (module === 'marketplace_apps') { - Object.values(mappedIds).forEach((ids) => Object.assign(uidMapping, ids)); + Object.values(mappedIds).forEach((ids) => { + uidMapping = { ...uidMapping, ...sanitizeObject(ids) }; + }); } else { - Object.assign(uidMapping, sanitizeObject(mappedIds)); + uidMapping = { ...uidMapping, ...sanitizeObject(mappedIds) }; } } }); @@ -33,7 +35,7 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf } } return sanitized; - } + }; const getEntries = async (ct) => { try { @@ -73,10 +75,10 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf let oldUids = Object.keys(uidMapping); matches.forEach((m) => { if (oldUids.includes(m)) { - let regex = new RegExp(m, 'g'); + let sanitizedUid = m; let { status } = validateRegex(regex); if (status === 'safe') { - stringifiedEntry = stringifiedEntry.replace(regex, uidMapping[m]); + stringifiedEntry = stringifiedEntry.split(sanitizedUid).join(uisdMapping[sanitizedUid]); console.log(chalk.green(`Replacing the UID '${m}' with '${uidMapping[m]}'...`)); isUpdated = true; } diff --git a/packages/contentstack-migration/src/utils/modules.js b/packages/contentstack-migration/src/utils/modules.js index b6fa55b76c..da6ee5c96a 100644 --- a/packages/contentstack-migration/src/utils/modules.js +++ b/packages/contentstack-migration/src/utils/modules.js @@ -1,5 +1,5 @@ const fs = require('fs'); -const { execSync } = require('child_process'); +const { execFileSync } = require('child_process'); const path = require('path'); const { sanitizePath } = require('@contentstack/cli-utilities'); const os = require('os'); @@ -70,8 +70,11 @@ function installDependencies(dependencies, directory) { function executeShellCommand(command, directory = '') { try { - execSync(command, { stdio: 'inherit', cwd: directory }); - console.log(`Command executed successfully: ${command}`); + if (command.startsWith('npm i')) { + const [cmd, ...args] = command.split(' '); + execFileSync(cmd, args, { stdio: 'inherit', cwd: directory }); + console.log(`Command executed successfully: ${command}`); + } } catch (error) { console.error(`Error: ${error.message}`); } From e3e34cba7b0fb80c8e867c642d5bf8854f5de437 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Mon, 29 Jul 2024 15:50:02 +0530 Subject: [PATCH 02/15] feat: add flag to support variable types & respective prompt --- package-lock.json | 4 +- packages/contentstack-launch/README.md | 2 +- packages/contentstack-launch/package.json | 2 +- .../src/adapters/base-class.ts | 147 ++++++++++-------- .../src/adapters/file-upload.ts | 13 +- .../src/adapters/github.ts | 112 +++++++------ .../src/commands/launch/index.ts | 13 ++ .../contentstack-launch/src/config/index.ts | 8 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 2 +- 10 files changed, 173 insertions(+), 132 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4aa190a11..b80997cf31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24868,7 +24868,7 @@ "@contentstack/cli-cm-seed": "~1.7.7", "@contentstack/cli-command": "~1.2.19", "@contentstack/cli-config": "~1.6.5", - "@contentstack/cli-launch": "~1.0.19", + "@contentstack/cli-launch": "~1.1.0", "@contentstack/cli-migration": "~1.6.0", "@contentstack/cli-utilities": "~1.7.0", "@contentstack/management": "~1.15.3", @@ -26656,7 +26656,7 @@ }, "packages/contentstack-launch": { "name": "@contentstack/cli-launch", - "version": "1.0.19", + "version": "1.1.0", "license": "MIT", "dependencies": { "@apollo/client": "^3.7.9", diff --git a/packages/contentstack-launch/README.md b/packages/contentstack-launch/README.md index 0d25ace69f..4b32cc5840 100755 --- a/packages/contentstack-launch/README.md +++ b/packages/contentstack-launch/README.md @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-launch $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli-launch/1.0.19 darwin-arm64 node-v22.2.0 +@contentstack/cli-launch/1.1.0 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-launch/package.json b/packages/contentstack-launch/package.json index e1ceef738a..da4c676470 100755 --- a/packages/contentstack-launch/package.json +++ b/packages/contentstack-launch/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-launch", - "version": "1.0.19", + "version": "1.1.0", "description": "Launch related operations", "author": "Contentstack CLI", "bin": { diff --git a/packages/contentstack-launch/src/adapters/base-class.ts b/packages/contentstack-launch/src/adapters/base-class.ts index 650252a403..da898bb0dd 100755 --- a/packages/contentstack-launch/src/adapters/base-class.ts +++ b/packages/contentstack-launch/src/adapters/base-class.ts @@ -1,3 +1,4 @@ +import path from 'path'; import open from 'open'; import dotEnv from 'dotenv'; import map from 'lodash/map'; @@ -262,14 +263,19 @@ export default class BaseClass { this.log(error, 'error'); this.exit(1); })) || []; - this.config.selectedStack = await ux - .inquire({ - name: 'stack', - type: 'search-list', - choices: listOfStacks, - message: 'Stack', - }) - .then((name) => find(listOfStacks, { name })); + + if (this.config.selectedStack) { + this.config.selectedStack = find(listOfStacks, { api_key: this.config.selectedStack }); + } else { + this.config.selectedStack = await ux + .inquire({ + name: 'stack', + type: 'search-list', + choices: listOfStacks, + message: 'Stack', + }) + .then((name) => find(listOfStacks, { name })); + } } /** @@ -299,16 +305,19 @@ export default class BaseClass { this.exit(1); })) || []; - this.config.deliveryToken = await ux - .inquire({ - type: 'search-list', - name: 'deliveryToken', - choices: listOfDeliveryTokens, - message: 'Delivery token', - }) - .then((name) => find(listOfDeliveryTokens, { name }) as Record); - - this.config.environment = this.config.deliveryToken.scope[0]?.environments[0]?.name; + if (this.config.deliveryToken) { + this.config.deliveryToken = find(listOfDeliveryTokens, { token: this.config.deliveryToken }); + } else { + this.config.deliveryToken = await ux + .inquire({ + type: 'search-list', + name: 'deliveryToken', + choices: listOfDeliveryTokens, + message: 'Delivery token', + }) + .then((name) => find(listOfDeliveryTokens, { name }) as Record); + } + this.config.environment = this.config.deliveryToken?.scope[0]?.environments[0]?.name; } /** @@ -321,38 +330,51 @@ export default class BaseClass { let addNew = true; const envVariables = []; - do { - const variable = await ux - .inquire({ - type: 'input', - name: 'variable', - message: - 'Enter key and value with a colon between them, and use a comma(,) for the key-value pair. Format: :, : Ex: APP_ENV:prod, TEST_ENV:testVal', - }) - .then((variable) => { - return map(split(variable as string, ','), (variable) => { - let [key, value] = split(variable as string, ':'); - value = (value || '').trim(); - key = (key || '').trim(); - - return { key, value }; - }).filter(({ key }) => key); - }); + if (!this.config.envVariables) { + do { + const variable = await ux + .inquire({ + type: 'input', + name: 'variable', + message: + 'Enter key and value with a colon between them, and use a comma(,) for the key-value pair. Format: :, : Ex: APP_ENV:prod, TEST_ENV:testVal', + }) + .then((variable) => { + return map(split(variable as string, ','), (variable) => { + let [key, value] = split(variable as string, ':'); + value = (value || '').trim(); + key = (key || '').trim(); + + return { key, value }; + }).filter(({ key }) => key); + }); - envVariables.push(...variable); + envVariables.push(...variable); - if ( - !(await ux.inquire({ - type: 'confirm', - name: 'canImportFromStack', - message: 'Would you like to add more variables?', - })) - ) { - addNew = false; - } - } while (addNew); + if ( + !(await ux.inquire({ + type: 'confirm', + name: 'canImportFromStack', + message: 'Would you like to add more variables?', + })) + ) { + addNew = false; + } + } while (addNew); + + this.envVariables.push(...envVariables); + } else { + if (typeof this.config.envVariables === 'string') { + const variable = map(split(this.config.envVariables as string, ','), (variable) => { + let [key, value] = split(variable as string, ':'); + value = (value || '').trim(); + key = (key || '').trim(); - this.envVariables.push(...envVariables); + return { key, value }; + }); + this.envVariables.push(...variable); + } + } } /** @@ -492,19 +514,16 @@ export default class BaseClass { * @memberof BaseClass */ async handleEnvImportFlow(): Promise { - const variablePreparationTypeOptions = [ - 'Import variables from a stack', - 'Manually add custom variables to the list', - 'Import variables from the local env file', - ]; - const variablePreparationType: Array = await ux.inquire({ - type: 'checkbox', - name: 'variablePreparationType', - default: this.config.framework, - choices: variablePreparationTypeOptions, - message: 'Import variables from a stack and/or manually add custom variables to the list', - // validate: this.inquireRequireValidation, - }); + const variablePreparationType = + this.config.variableType || + (await ux.inquire({ + type: 'checkbox', + name: 'variablePreparationType', + default: this.config.framework, + choices: this.config.variablePreparationTypeOptions, + message: 'Import variables from a stack and/or manually add custom variables to the list', + // validate: this.inquireRequireValidation, + })); if (includes(variablePreparationType, 'Import variables from a stack')) { await this.importEnvFromStack(); @@ -519,8 +538,8 @@ export default class BaseClass { if (this.envVariables.length) { this.printAllVariables(); } else { - this.log('Import variables from a stack and/or manually add custom variables to the list', 'warn'); - // this.exit(1); + this.log('Please provide env file!', 'error'); + this.exit(1); } } @@ -533,10 +552,10 @@ export default class BaseClass { async importVariableFromLocalConfig(): Promise { const localEnv = dotEnv.config({ - path: this.config.projectBasePath, + path: `${this.config.projectBasePath}/.env.local`, }).parsed || dotEnv.config({ - path: `${this.config.projectBasePath}/.env.local`, + path: this.config.projectBasePath, }).parsed; if (!isEmpty(localEnv)) { diff --git a/packages/contentstack-launch/src/adapters/file-upload.ts b/packages/contentstack-launch/src/adapters/file-upload.ts index c8969b733c..2cc9c9f969 100755 --- a/packages/contentstack-launch/src/adapters/file-upload.ts +++ b/packages/contentstack-launch/src/adapters/file-upload.ts @@ -6,7 +6,7 @@ import FormData from 'form-data'; import filter from 'lodash/filter'; import includes from 'lodash/includes'; import { basename, resolve } from 'path'; -import { cliux, ux } from '@contentstack/cli-utilities'; +import { cliux, configHandler, ux } from '@contentstack/cli-utilities'; import { createReadStream, existsSync, PathLike, statSync } from 'fs'; import { print } from '../util'; @@ -110,9 +110,14 @@ export default class FileUpload extends BaseClass { framework, environment, 'build-command': buildCommand, - 'output-directory': outputDirectory, + 'out-dir': outputDirectory, + 'variable-type': variableType, + 'env-variables': envVariables, + alias, } = this.config.flags; - + const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {}; + this.config.selectedStack = apiKey; + this.config.deliveryToken = token; // this.fileValidation(); await this.selectOrg(); await this.createSignedUploadUrl(); @@ -166,6 +171,8 @@ export default class FileUpload extends BaseClass { message: 'Output Directory', default: (this.config.outputDirectories as Record)[this.config?.framework || 'OTHER'], })); + this.config.variableType = variableType as unknown as string; + this.config.envVariables = envVariables; await this.handleEnvImportFlow(); } diff --git a/packages/contentstack-launch/src/adapters/github.ts b/packages/contentstack-launch/src/adapters/github.ts index e6b049cf34..74946ac94b 100755 --- a/packages/contentstack-launch/src/adapters/github.ts +++ b/packages/contentstack-launch/src/adapters/github.ts @@ -1,21 +1,17 @@ -import map from "lodash/map"; -import { resolve } from "path"; -import omit from "lodash/omit"; -import find from "lodash/find"; -import split from "lodash/split"; -import { exec } from "child_process"; -import replace from "lodash/replace"; -import includes from "lodash/includes"; -import { cliux as ux } from "@contentstack/cli-utilities"; +import map from 'lodash/map'; +import { resolve } from 'path'; +import omit from 'lodash/omit'; +import find from 'lodash/find'; +import split from 'lodash/split'; +import { exec } from 'child_process'; +import replace from 'lodash/replace'; +import includes from 'lodash/includes'; +import { configHandler, cliux as ux } from '@contentstack/cli-utilities'; -import { print } from "../util"; -import BaseClass from "./base-class"; -import { getRemoteUrls } from "../util/create-git-meta"; -import { - repositoriesQuery, - userConnectionsQuery, - importProjectMutation, -} from "../graphql"; +import { print } from '../util'; +import BaseClass from './base-class'; +import { getRemoteUrls } from '../util/create-git-meta'; +import { repositoriesQuery, userConnectionsQuery, importProjectMutation } from '../graphql'; export default class GitHub extends BaseClass { /** @@ -122,32 +118,38 @@ export default class GitHub extends BaseClass { name, framework, environment, - "build-command": buildCommand, - "output-directory": outputDirectory, + 'build-command': buildCommand, + 'out-dir': outputDirectory, + 'variable-type': variableType, + 'env-variables': envVariables, + alias, } = this.config.flags; + const { token, apiKey } = configHandler.get(`tokens.${alias}`) ?? {}; + this.config.selectedStack = apiKey; + this.config.deliveryToken = token; await this.selectOrg(); print([ - { message: "?", color: "green" }, - { message: "Repository", bold: true }, - { message: this.config.repository?.fullName, color: "cyan" }, + { message: '?', color: 'green' }, + { message: 'Repository', bold: true }, + { message: this.config.repository?.fullName, color: 'cyan' }, ]); await this.selectBranch(); this.config.projectName = name || (await ux.inquire({ - type: "input", - name: "projectName", - message: "Project Name", + type: 'input', + name: 'projectName', + message: 'Project Name', default: this.config.repository?.name, validate: this.inquireRequireValidation, })); this.config.environmentName = environment || (await ux.inquire({ - type: "input", - default: "Default", - name: "environmentName", - message: "Environment Name", + type: 'input', + default: 'Default', + name: 'environmentName', + message: 'Environment Name', validate: this.inquireRequireValidation, })); if (framework) { @@ -157,9 +159,9 @@ export default class GitHub extends BaseClass { }) as Record ).value as string; print([ - { message: "?", color: "green" }, - { message: "Framework Preset", bold: true }, - { message: this.config.framework, color: "cyan" }, + { message: '?', color: 'green' }, + { message: 'Framework Preset', bold: true }, + { message: this.config.framework, color: 'cyan' }, ]); } else { await this.detectFramework(); @@ -175,13 +177,13 @@ export default class GitHub extends BaseClass { this.config.outputDirectory = outputDirectory || (await ux.inquire({ - type: "input", - name: "outputDirectory", - message: "Output Directory", - default: (this.config.outputDirectories as Record)[ - this.config?.framework || "OTHER" - ], + type: 'input', + name: 'outputDirectory', + message: 'Output Directory', + default: (this.config.outputDirectories as Record)[this.config?.framework || 'OTHER'], })); + this.config.variableType = variableType as unknown as string; + this.config.envVariables = envVariables; await this.handleEnvImportFlow(); } @@ -201,17 +203,17 @@ export default class GitHub extends BaseClass { const userConnections = await this.apolloClient .query({ query: userConnectionsQuery }) .then(({ data: { userConnections } }) => userConnections) - .catch((error) => this.log(error, "error")); + .catch((error) => this.log(error, 'error')); const userConnection = find(userConnections, { provider: this.config.provider, }); if (userConnection) { - this.log("GitHub connection identified!", "info"); + this.log('GitHub connection identified!', 'info'); this.config.userConnection = userConnection; } else { - this.log("GitHub connection not found!", "warn"); + this.log('GitHub connection not found!', 'warn'); await this.connectToAdapterOnUi(); } @@ -228,21 +230,21 @@ export default class GitHub extends BaseClass { const localRemoteUrl = (await getRemoteUrls(resolve(this.config.projectBasePath, '.git/config')))?.origin || ''; if (!localRemoteUrl) { - this.log("GitHub project not identified!", "error"); + this.log('GitHub project not identified!', 'error'); await this.connectToAdapterOnUi(); } const repositories = await this.apolloClient .query({ query: repositoriesQuery }) .then(({ data: { repositories } }) => repositories) - .catch((error) => this.log(error, "error")); + .catch((error) => this.log(error, 'error')); this.config.repository = find(repositories, { - url: replace(localRemoteUrl, ".git", ""), + url: replace(localRemoteUrl, '.git', ''), }); if (!this.config.repository) { - this.log("Repository not found in the list!", "error"); + this.log('Repository not found in the list!', 'error'); this.exit(1); } @@ -259,32 +261,26 @@ export default class GitHub extends BaseClass { return new Promise((resolve, reject) => { const self = this; const defaultBranch = this.config.repository?.defaultBranch; - if (!defaultBranch) return reject("Branch not found"); + if (!defaultBranch) return reject('Branch not found'); exec( `git push -u origin ${defaultBranch} --dry-run`, { cwd: this.config.projectBasePath }, function (err, stdout, stderr) { if (err) { - self.log(err, "error"); + self.log(err, 'error'); } if ( - includes(stderr, "Everything up-to-date") && - includes( - stdout, - `Would set upstream of '${defaultBranch}' to '${defaultBranch}' of 'origin'` - ) + includes(stderr, 'Everything up-to-date') && + includes(stdout, `Would set upstream of '${defaultBranch}' to '${defaultBranch}' of 'origin'`) ) { - self.log("User access verified", "info"); + self.log('User access verified', 'info'); return resolve(true); } - self.log( - "You do not have write access for the selected repo", - "error" - ); + self.log('You do not have write access for the selected repo', 'error'); self.exit(0); - } + }, ); }); } diff --git a/packages/contentstack-launch/src/commands/launch/index.ts b/packages/contentstack-launch/src/commands/launch/index.ts index 06abde2cd4..cbe6ca9521 100755 --- a/packages/contentstack-launch/src/commands/launch/index.ts +++ b/packages/contentstack-launch/src/commands/launch/index.ts @@ -19,6 +19,8 @@ export default class Launch extends BaseCommand { '<%= config.bin %> <%= command.id %> --data-dir --type ', '<%= config.bin %> <%= command.id %> --config --type ', '<%= config.bin %> <%= command.id %> --config --type --name= --environment= --branch= --build-command= --framework=