Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/apps-cli",
"version": "1.2.1",
"version": "1.3.0",
"description": "App ClI",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
Expand Down
36 changes: 26 additions & 10 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ import {
flags,
HttpClient,
configHandler,
FlagInput
FlagInput,
} from "@contentstack/cli-utilities";

import { BaseCommand } from "../../base-command";
import { AppManifest, AppType } from "../../types";
import { AppManifest, AppType, BoilerplateAppType } from "../../types";
import { appCreate, commonMsg } from "../../messages";
import {
getOrg,
getAppName,
getDirName,
getOrgAppUiLocation,
sanitizePath
sanitizePath,
selectedBoilerplate,
} from "../../util";

export default class Create extends BaseCommand<typeof Create> {
Expand Down Expand Up @@ -96,7 +97,18 @@ export default class Create extends BaseCommand<typeof Create> {
message: this.messages.CONFIRM_CLONE_BOILERPLATE,
}))
) {
await this.boilerplateFlow();
const boilerplate: BoilerplateAppType = await selectedBoilerplate();

if (boilerplate) {
this.sharedConfig.boilerplateName = boilerplate.name
.toLowerCase()
.replace(/ /g, "-");
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
this.sharedConfig.appName = await getAppName(
this.sharedConfig.boilerplateName
);
await this.boilerplateFlow();
}
} else {
this.manageManifestToggeling();
await this.registerTheAppOnDeveloperHub(false);
Expand Down Expand Up @@ -198,7 +210,11 @@ export default class Create extends BaseCommand<typeof Create> {
const zip = new AdmZip(filepath);
const dataDir = this.flags["data-dir"] ?? process.cwd();
let targetPath = resolve(dataDir, this.sharedConfig.appName);
const sourcePath = resolve(dataDir, this.sharedConfig.boilerplateName);

// Get the directory inside the zip file
const zipEntries = zip.getEntries();
const firstEntry = zipEntries[0];
const sourcePath = resolve(dataDir, firstEntry.entryName.split("/")[0]);

if (this.flags["data-dir"] && !existsSync(this.flags["data-dir"])) {
mkdirSync(this.flags["data-dir"], { recursive: true });
Expand Down Expand Up @@ -235,10 +251,7 @@ export default class Create extends BaseCommand<typeof Create> {
*/
manageManifestToggeling() {
// NOTE Use boilerplate manifest if exist
const manifestPath = resolve(
this.sharedConfig.folderPath || "",
"manifest.json"
);
const manifestPath = resolve(this.sharedConfig.folderPath, "manifest.json");

if (existsSync(manifestPath)) {
this.sharedConfig.manifestPath = manifestPath;
Expand Down Expand Up @@ -301,7 +314,10 @@ export default class Create extends BaseCommand<typeof Create> {
this.appData = merge(this.appData, pick(response, validKeys));
if (saveManifest) {
writeFileSync(
resolve(this.sharedConfig.folderPath, "manifest.json"),
resolve(
this.sharedConfig.folderPath,
"manifest.json"
),
JSON.stringify(this.appData),
{
encoding: "utf8",
Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const config = {
appBoilerplateGithubUrl:
"https://codeload.github.com/contentstack/marketplace-app-boilerplate/zip/refs/heads/main",
defaultAppFileName: "manifest",
boilerplatesUrl: 'https://marketplace-artifacts.contentstack.com/cli/starter-template.json'
};

export default config;
9 changes: 9 additions & 0 deletions src/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ export interface LaunchProjectRes {
environmentUid: any;
developerHubAppUid: any;
}

export interface BoilerplateAppType {
name: string;
description?: string;
link: string;
tags?: string[];
created_at?: string;
updated_at?: string;
}
11 changes: 11 additions & 0 deletions src/util/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
cliux,
Stack,
FsUtility,
HttpClient,
} from "@contentstack/cli-utilities";
import { projectsQuery } from "../graphql/queries";
import { apiRequestHandler } from "./api-request-handler";
Expand All @@ -19,6 +20,7 @@ import {
} from "../types";
import { askProjectName } from "./inquirer";
import { deployAppMsg } from "../messages";
import config from "../config";

export type CommonOptions = {
log: LogFn;
Expand Down Expand Up @@ -396,6 +398,14 @@ const handleProjectNameConflict = async (
}
return projectName;
};
async function fetchBoilerplateDetails(): Promise<Record<string, any>[]> {
try {
const content = await new HttpClient().get(config.boilerplatesUrl);
return content?.data?.templates ?? [];
} catch (error) {
throw error;
}
}

export {
getOrganizations,
Expand All @@ -418,4 +428,5 @@ export {
disconnectApp,
formatUrl,
handleProjectNameConflict,
fetchBoilerplateDetails
};
19 changes: 18 additions & 1 deletion src/util/inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
fetchApps,
sanitizePath,
MarketPlaceOptions,
fetchBoilerplateDetails,
} from "./common-utils";
import { LaunchProjectRes } from "../types";

Expand Down Expand Up @@ -385,6 +386,21 @@ function inquireRequireValidation(input: any): string | boolean {
return true;
}

const selectedBoilerplate = async (): Promise<any> => {
const boilerplates = await fetchBoilerplateDetails();

return await cliux
.inquire({
type: "search-list",
name: "App",
choices: boilerplates.map((bp) => bp.name),
message: "Select a boilerplate from search list",
})
.then((name) => {
return find(boilerplates, (boilerplate) => boilerplate.name === name);
});
};

export {
getOrg,
getAppName,
Expand All @@ -399,5 +415,6 @@ export {
askProjectType,
askConfirmation,
selectProject,
askProjectName
askProjectName,
selectedBoilerplate,
};