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

add extension templates in new project #461

Merged
merged 1 commit into from
Jul 13, 2021
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
14 changes: 9 additions & 5 deletions src/examples/Example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export interface IExampleCategory {
}

export function getExamplesList(
targetFrameworkFolder: string
targetFrameworkFolder: string,
examplesContainer: string = "examples"
): IExampleCategory {
const examplesRoot = path.join(targetFrameworkFolder, "examples");
const rootName = path.basename(targetFrameworkFolder);
const examplesRoot = path.join(targetFrameworkFolder, examplesContainer);
const examplesPathList = utils.getSubProjects(examplesRoot);
const rootFolder: IExampleCategory = {
name: examplesRoot,
name: rootName,
examples: [],
subcategories: [],
};
Expand All @@ -42,8 +44,10 @@ export function getExamplesList(
.split(path.sep);
addSubCategory(rootFolder, examplePath, pathSegments);
}
const getStarted = rootFolder.subcategories.findIndex((subCat) => subCat.name === "get-started");
rootFolder.subcategories.splice(0, 0, rootFolder.subcategories.splice(getStarted, 1)[0]);
const getStartedIndex = rootFolder.subcategories.findIndex((subCat) => subCat.name === "get-started");
if (getStartedIndex !== -1) {
rootFolder.subcategories.splice(0, 0, rootFolder.subcategories.splice(getStartedIndex, 1)[0]);
}
return rootFolder;
}

Expand Down
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,10 @@ export async function activate(context: vscode.ExtensionContext) {
cancelToken: vscode.CancellationToken
) => {
try {
const newProjectArgs = await getNewProjectArgs(progress);
const newProjectArgs = await getNewProjectArgs(
context.extensionPath,
progress
);
if (!newProjectArgs || !newProjectArgs.targetList) {
throw new Error("Could not find ESP-IDF Targets");
}
Expand Down
4 changes: 3 additions & 1 deletion src/newProject/newProjectInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export async function getBoards() {
}

export async function getNewProjectArgs(
extensionPath: string,
progress: Progress<{ message: string; increment: number }>
) {
progress.report({ increment: 10, message: "Loading ESP-IDF components..." });
Expand All @@ -131,7 +132,8 @@ export async function getNewProjectArgs(
const espIdfPath = idfConf.readParameter("idf.espIdfPath") as string;
const espAdfPath = idfConf.readParameter("idf.espAdfPath") as string;
const espMdfPath = idfConf.readParameter("idf.espMdfPath") as string;
let templates: { [key:string]: IExampleCategory} = {};
let templates: { [key: string]: IExampleCategory } = {};
templates["Extension"] = getExamplesList(extensionPath, "templates");
const idfExists = await dirExistPromise(espIdfPath);
if (idfExists) {
const idfTemplates = getExamplesList(espIdfPath);
Expand Down
2 changes: 1 addition & 1 deletion src/views/new-project/Templates.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Templates extends Vue {
this.storeTemplatesRootPath &&
this.storeTemplatesRootPath[this.selectedFramework]
) {
return this.storeTemplatesRootPath[this.selectedFramework].subcategories;
return [this.storeTemplatesRootPath[this.selectedFramework]];
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/views/new-project/components/templateList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<li>
<h3 class="category is-3" v-text="node.name"></h3>
<ul class="subcategories">
<ul
class="subcategories"
v-if="node.subcategories && node.subcategories.length"
>
<TemplateList
v-for="nodeSubCat in node.subcategories"
:key="nodeSubCat.name"
Expand Down