Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
use Settings enum for the template proj. url preference lookup, updat…
Browse files Browse the repository at this point in the history
…e proj. context after project folder is created (#62)
  • Loading branch information
RandomFractals committed Jun 5, 2023
1 parent 37469a8 commit 158405e
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import {
OutputChannel
} from 'vscode';

import * as path from 'path';
import {
Settings,
getConfig,
getWorkspaceFolder,
updateProjectContext
} from '../config';

import { getConfig } from '../config';
import { cloneTemplateRepository } from './template';
import { getOutputChannel } from '../output';
import { statusBar } from '../statusBar';
import { cloneTemplateRepository } from './template';
import { getExtensionFileUri } from '../extensionContext';
import { folderExists } from '../utils/fsUtils';

Expand All @@ -28,18 +33,11 @@ import {
const extensionTemplateProjectFolderName: string = 'template';

/**
* Evidence template project Url setting name.
*
* @see https://github.com/evidence-dev/evidence-vscode/issues/62
*/
const templateProjectUrlSetting = 'templateProjectUrl';

/**
* Default evdinecence template project url setting value
* Default Evidence template project url setting value.
*
* @see https://github.com/evidence-dev/evidence-vscode/issues/62
*/
const templateProjectUrlSettingDefault = '/template';
const templateProjectUrlSetting = '/template';

/**
* Creates a new Evidence project.
Expand All @@ -64,6 +62,8 @@ export async function createNewProject(projectFolder?: Uri) {
const projectFiles = await workspace.findFiles(
new RelativePattern(projectFolder.fsPath, '**/*'));

console.log(projectFiles);

// check if the selected folder is empty
if (projectFiles.length > 0 ) {

Expand All @@ -88,7 +88,7 @@ export async function createNewProject(projectFolder?: Uri) {
// use new evidence template project Url setting
// @see https://github.com/evidence-dev/evidence-vscode/issues/62
const templateProjectUrl =
<string>getConfig('templateProjectUrl', templateProjectUrlSettingDefault);
<string>getConfig(Settings.TemplateProjectUrl, templateProjectUrlSetting);
const projectTemplateUrl = templateProjectUrl;

if (projectTemplateUrl.startsWith('https://')) {
Expand All @@ -112,7 +112,7 @@ export async function createNewProject(projectFolder?: Uri) {
outputChannel.appendLine(`✗ Ivalid Template Project Folder: ${projectTemplateUrl}`);
}
}
else if (projectTemplateUrl === templateProjectUrlSettingDefault) {
else if (projectTemplateUrl === templateProjectUrlSetting) {

// get built-in /template folder Uri from extension context
const templateFolder: Uri = getExtensionFileUri(extensionTemplateProjectFolderName);
Expand Down Expand Up @@ -146,6 +146,16 @@ async function createProjectFolder(templateFolder: Uri, projectFolder: Uri) {
// copy template folder to the new project folder
const projectFolderCreated: boolean = await copyFolder(templateFolder, projectFolder);
if (projectFolderCreated) {

// check if new Evidence project was created in the top workspace folder
const workspaceFolder = getWorkspaceFolder();
if (workspaceFolder?.uri.fsPath === projectFolder.fsPath) {
// update Evidence project context and status bar
// to enable all the Evidence project commands, etc
updateProjectContext();
statusBar.showInstall();
}

// display Open Folder prompt to open newly created Evidence project
// in a new VS Code workspace window and enable all Evidence extensioin commands
// in the open workspace with an Evidence project for the app and markdown pages development
Expand Down

0 comments on commit 158405e

Please sign in to comment.