async InitializeProject()

in src/projectInitializer.ts [31:135]


  async InitializeProject(
    context: vscode.ExtensionContext,
    channel: vscode.OutputChannel,
    telemetryContext: TelemetryContext
  ): Promise<void> {
    // Only create project when not in remote environment
    RemoteExtension.ensureLocalBeforeRunCommand("init project", context);

    let openInNewWindow = false;
    // If current window contains other project, open the created project in new
    // window.
    if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
      openInNewWindow = true;
    }

    // Initial project
    await vscode.window.withProgress(
      {
        title: "Project initialization",
        location: vscode.ProgressLocation.Window
      },
      async progress => {
        progress.report({
          message: "Updating a list of available template"
        });

        const scaffoldType = ScaffoldType.Local;

        // Step 1: Get project name
        const projectPath = await this.generateProjectFolder(telemetryContext, scaffoldType);
        if (!projectPath) {
          throw new OperationCanceledError(`Project initialization cancelled: Project name input cancelled.`);
        }

        // Step 2: Select platform
        const platformSelection = await utils.selectPlatform(scaffoldType, context);
        if (!platformSelection) {
          throw new OperationCanceledError(`Project initialization cancelled: Platform selection cancelled.`);
        } else {
          telemetryContext.properties.platform = platformSelection.label;
        }

        // Step 3: Select template
        const templateJson = await utils.getTemplateJson(context, scaffoldType);
        let templateName: string | undefined;
        if (platformSelection.label === PlatformType.Arduino) {
          const templateSelection = await this.selectTemplate(templateJson, PlatformType.Arduino);

          if (!templateSelection) {
            throw new OperationCanceledError(`Project initialization cancelled: Project template selection cancelled.`);
          } else {
            telemetryContext.properties.template = templateSelection.label;
            if (templateSelection.label === constants.noDeviceMessage) {
              await utils.takeNoDeviceSurvey(telemetryContext, context);
              return;
            }
          }
          templateName = templateSelection.label;
        } else {
          // If choose Embedded Linux platform, generate C project template
          // directly
          templateName = constants.embeddedLinuxProjectName;
        }

        const template: ProjectTemplate = templateJson.templates.find((template: ProjectTemplate) => {
          return template.platform === platformSelection.label && template.name === templateName;
        });
        if (!template) {
          throw new ResourceNotFoundError(
            "initialize iot project",
            `project template in template json file with the given template name ${templateName} \
            and platform ${platformSelection.label}`,
            ""
          );
        }

        // Step 4: Load the list of template files
        const projectTemplateType: ProjectTemplateType = utils.getEnumKeyByEnumValue(
          ProjectTemplateType,
          template.type
        );

        const resourceRootPath = context.asAbsolutePath(
          path.join(FileNames.resourcesFolderName, FileNames.templatesFolderName)
        );
        const templateFolder = path.join(resourceRootPath, template.path);
        const templateFilesInfo = await utils.getTemplateFilesInfo(templateFolder);

        let project;
        if (template.platform === PlatformType.EmbeddedLinux) {
          project = new ioTContainerizedProjectModule.IoTContainerizedProject(
            context,
            channel,
            telemetryContext,
            projectPath
          );
        } else if (template.platform === PlatformType.Arduino) {
          project = new ioTWorkspaceProjectModule.IoTWorkspaceProject(context, channel, telemetryContext, projectPath);
        } else {
          throw new TypeNotSupportedError("platform", `${template.platform}`);
        }
        await project.create(templateFilesInfo, projectTemplateType, template.boardId, openInNewWindow);
      }
    );
  }