"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Project = void 0; const vscode = require("vscode"); const fs = require("fs-extra"); const path = require("path"); const vscode_ui_1 = require("./vscode-ui"); class Project { constructor(context) { this.directories = new Array('.vscode', 'xlsx_to_py'); this.context = context; } createFiles({ type, location }) { return __awaiter(this, void 0, void 0, function* () { try { const tasksPath = path.join(this.context.extensionPath, 'templates', 'tasks.json'); const launchPath = path.join(this.context.extensionPath, 'templates', 'launch.json'); const settingsPath = path.join(this.context.extensionPath, 'templates', 'settings.json'); const p7zip = path.join(this.context.extensionPath, 'templates', '7za.exe'); const pypy3Path = path.join(this.context.extensionPath, 'templates', '.pypy3.7z'); const venvPath = path.join(this.context.extensionPath, 'templates', '.venv.7z'); const classesPath = path.join(this.context.extensionPath, 'templates', 'classes.py'); const mainPath = path.join(this.context.extensionPath, 'templates', type, `main.py`); const mainXLSXPath = path.join(this.context.extensionPath, 'templates', type, `main.xlsx`); fs.writeFileSync(path.join(location, '.vscode', 'tasks.json'), fs.readFileSync(tasksPath, 'utf-8')); fs.writeFileSync(path.join(location, '.vscode', 'launch.json'), fs.readFileSync(launchPath, 'utf-8')); fs.writeFileSync(path.join(location, '.vscode', 'settings.json'), fs.readFileSync(settingsPath, 'utf-8')); fs.writeFileSync(path.join(location, '.vscode', '7za.exe'), fs.readFileSync(p7zip, 'binary'), 'binary'); fs.writeFileSync(path.join(location, `main.py`), fs.readFileSync(mainPath, 'utf-8')); fs.writeFileSync(path.join(location, 'xlsx_to_py', 'classes.py'), fs.readFileSync(classesPath, 'utf-8')); fs.writeFileSync(path.join(location, `main.xlsx`), fs.readFileSync(mainXLSXPath, 'binary'), 'binary'); fs.writeFileSync(path.join(location, `.pypy3.7z`), fs.readFileSync(pypy3Path, 'binary'), 'binary'); fs.writeFileSync(path.join(location, `.venv.7z`), fs.readFileSync(venvPath, 'binary'), 'binary'); vscode.workspace.openTextDocument(path.join(location, 'main.py')) .then(doc => vscode.window.showTextDocument(doc, { preview: false })); } catch (err) { console.error(err); } }); } createFolders(location) { return __awaiter(this, void 0, void 0, function* () { this.directories.forEach((dir) => { try { fs.ensureDirSync(path.join(location, dir)); } catch (err) { console.error(err); } }); }); } createProject(type) { return __awaiter(this, void 0, void 0, function* () { const result = yield vscode_ui_1.VSCodeUI.openDialogForFolder(); if (result && result.fsPath) { yield vscode.commands.executeCommand('vscode.openFolder', result); yield this.createFolders(result.fsPath); yield this.createFiles({ type, location: result.fsPath }); } }); } } exports.Project = Project; //# sourceMappingURL=project.js.map