Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dx 544 add boilerplates #272

Merged
merged 8 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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.2.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshithad0703 , minor version bump as it's enhancement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version bump to 1.3.0

"description": "App ClI",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/contentstack-apps-cli",
Expand Down
38 changes: 32 additions & 6 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
getAppName,
getDirName,
getOrgAppUiLocation,
sanitizePath
sanitizePath,
selectedBoilerplate,
} from "../../util";

export default class Create extends BaseCommand<typeof Create> {
Expand Down Expand Up @@ -96,7 +97,15 @@ export default class Create extends BaseCommand<typeof Create> {
message: this.messages.CONFIRM_CLONE_BOILERPLATE,
}))
) {
await this.boilerplateFlow();
const boilerplate = await selectedBoilerplate();
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved
if (boilerplate) {
this.sharedConfig.boilerplateName = boilerplate.name
.toLowerCase()
.replace(/ /g, "-");
aman19K marked this conversation as resolved.
Show resolved Hide resolved
this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
this.sharedConfig.appName = this.sharedConfig.boilerplateName;
await this.boilerplateFlow();
}
} else {
this.manageManifestToggeling();
await this.registerTheAppOnDeveloperHub(false);
Expand All @@ -120,6 +129,12 @@ export default class Create extends BaseCommand<typeof Create> {
await this.unZipBoilerplate(await this.cloneBoilerplate());
tmp.setGracefulCleanup(); // NOTE If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit

// Update the sharedConfig.appName with the actual folder name
this.sharedConfig.appName =
this.sharedConfig.folderPath.split("/").pop() ||
this.sharedConfig.appName;
this.tempAppData.name = this.sharedConfig.appName;

this.manageManifestToggeling();

// NOTE Step 2: Registering the app
Expand Down Expand Up @@ -198,7 +213,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 All @@ -225,6 +244,10 @@ export default class Create extends BaseCommand<typeof Create> {
reject(error);
});
});
// Update the app name and folder path
this.sharedConfig.appName =
this.sharedConfig.folderPath.split("/").pop() ||
this.sharedConfig.appName;
}

/**
Expand All @@ -236,8 +259,8 @@ export default class Create extends BaseCommand<typeof Create> {
manageManifestToggeling() {
// NOTE Use boilerplate manifest if exist
const manifestPath = resolve(
this.sharedConfig.folderPath || "",
"manifest.json"
this.sharedConfig.folderPath,
`${this.sharedConfig.folderPath}/manifest.json`
);
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved

if (existsSync(manifestPath)) {
Expand Down Expand Up @@ -301,7 +324,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,
`${this.sharedConfig.folderPath}/manifest.json`
),
JSON.stringify(this.appData),
{
encoding: "utf8",
Expand Down
3 changes: 2 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { resolve } from "path";

const config = {
defaultAppName: "app-boilerplate",
manifestPath: resolve(__dirname, "manifest.json"),
manifestPath: resolve(__dirname, ""),
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved
boilerplateName: "marketplace-app-boilerplate-main",
developerHubBaseUrl: "",
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;
105 changes: 0 additions & 105 deletions src/config/manifest.json
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

12 changes: 12 additions & 0 deletions src/util/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
} from "../types";
import { askProjectName } from "./inquirer";
import { deployAppMsg } from "../messages";
import config from "../config";
import axios from "axios";

export type CommonOptions = {
log: LogFn;
Expand Down Expand Up @@ -396,6 +398,15 @@ const handleProjectNameConflict = async (
}
return projectName;
};
async function fetchBoilerplateDetails(): Promise<Record<string, any>[]> {
try {
const url = config.boilerplatesUrl;
const content = await axios.get(url);
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved
return content.data.templates
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
throw error;
}
}

export {
getOrganizations,
Expand All @@ -418,4 +429,5 @@ export {
disconnectApp,
formatUrl,
handleProjectNameConflict,
fetchBoilerplateDetails
};
20 changes: 19 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,22 @@ function inquireRequireValidation(input: any): string | boolean {
return true;
}

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

const response = await cliux
harshithad0703 marked this conversation as resolved.
Show resolved Hide resolved
.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);
});
return response;
};

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