Skip to content

Commit 5e69ab6

Browse files
committed
SRE fixes and version bump
1 parent c7169c0 commit 5e69ab6

File tree

6 files changed

+31
-23
lines changed

6 files changed

+31
-23
lines changed

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/apps-cli",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "App ClI",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
@@ -99,4 +99,4 @@
9999
"app:uninstall": "APUI"
100100
}
101101
}
102-
}
102+
}

src/commands/app/create.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getAppName,
3232
getDirName,
3333
getOrgAppUiLocation,
34+
sanitizePath
3435
} from "../../util";
3536

3637
export default class Create extends BaseCommand<typeof Create> {
@@ -386,7 +387,7 @@ export default class Create extends BaseCommand<typeof Create> {
386387

387388
this.sharedConfig.folderPath = resolve(
388389
dirname(this.sharedConfig.folderPath),
389-
this.appData.name
390+
sanitizePath(this.appData.name)
390391
);
391392
this.sharedConfig.nameChanged = true;
392393

src/util/common-utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ async function fetchInstalledApps(
225225
return batchRequests.flat();
226226
}
227227

228+
229+
// To remove the relative path
230+
const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, '');
231+
228232
export {
229233
getOrganizations,
230234
getOrgAppUiLocation,
@@ -237,4 +241,5 @@ export {
237241
fetchStack,
238242
uninstallApp,
239243
fetchInstalledApps,
244+
sanitizePath
240245
};

src/util/fs.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { existsSync, readdirSync, writeFileSync, mkdirSync } from "fs";
22
import { resolve } from "path";
33
import config from "../config";
4-
import messages, {$t} from "../messages";
4+
import messages, { $t } from "../messages";
55
import { LogFn } from "../types";
66
import { cliux } from "@contentstack/cli-utilities";
7+
import { sanitizePath } from './common-utils'
78

8-
export async function writeFile(dir: string=process.cwd(), force: boolean=false, data: Record<string, any> | undefined={}, log: LogFn=console.log) {
9+
export async function writeFile(dir: string = process.cwd(), force: boolean = false, data: Record<string, any> | undefined = {}, log: LogFn = console.log) {
910
await ensureDirectoryExists(dir)
1011
const files = readdirSync(dir)
1112
const latestFileName = files.filter(fileName => fileName.match(new RegExp(config.defaultAppFileName))).pop()?.split('.')[0] || config.defaultAppFileName;
12-
let target = resolve(dir, `${latestFileName}.json`)
13+
let target = resolve(sanitizePath(dir), `${latestFileName}.json`)
1314
if (existsSync(target)) {
1415
const userConfirmation: boolean = force || (await cliux.confirm($t(messages.FILE_ALREADY_EXISTS, { file: `${config.defaultAppFileName}.json` })))
1516
if (userConfirmation) {
16-
target = resolve(dir, `${config.defaultAppFileName}.json`);
17+
target = resolve(sanitizePath(dir), `${sanitizePath(config.defaultAppFileName)}.json`);
1718
} else {
18-
target = resolve(dir, `${incrementName(latestFileName)}.json`);
19+
target = resolve(sanitizePath(dir), `${sanitizePath(incrementName(latestFileName))}.json`);
1920
}
2021
}
2122
await writeFileSync(target, JSON.stringify(data))
@@ -24,10 +25,10 @@ export async function writeFile(dir: string=process.cwd(), force: boolean=false,
2425

2526
async function ensureDirectoryExists(dir: string) {
2627
if (!existsSync(dir)) {
27-
await mkdirSync(dir, {recursive: true})
28+
await mkdirSync(dir, { recursive: true })
2829
}
2930
}
3031

3132
function incrementName(name: string) {
32-
return `${config.defaultAppFileName}${Number(name.split(config.defaultAppFileName).pop())+1}`
33+
return `${config.defaultAppFileName}${Number(name.split(config.defaultAppFileName).pop()) + 1}`
3334
}

src/util/inquirer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
fetchAppInstallations,
2121
fetchInstalledApps,
2222
fetchApps,
23+
sanitizePath,
2324
} from "./common-utils";
2425

2526
/**
@@ -64,14 +65,14 @@ async function getDirName(path: string): Promise<string> {
6465
return $t(errors.INVALID_NAME, { min: "3", max: "50" });
6566
}
6667

67-
if (existsSync(join(basePath, name))) {
68+
if (existsSync(join(sanitizePath(basePath), sanitizePath(name)))) {
6869
return messages.DIR_EXIST;
6970
}
7071

7172
return true;
7273
},
7374
})
74-
.then((name) => join(basePath, name as string));
75+
.then((name) => join(sanitizePath(basePath), sanitizePath(name as string)));
7576
}
7677

7778
/**

0 commit comments

Comments
 (0)