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: Support for Windows #38

Merged
merged 13 commits into from
Sep 18, 2021
Prev Previous commit
Next Next commit
fix view custom profile details
mrsauravsahu committed Aug 19, 2021
commit 90bd565d1cf8a00f1cadb73891558828181c7366
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ import { CommandGeneratorService } from './services/command-generator.service'
// your extension is activated the very first time the command is executed
export async function activate(context: vscode.ExtensionContext) {
// TODO: Make rootPath cross platform
const customProfileService = new CustomProfileService()
const commandGeneratorService = new CommandGeneratorService()
const customProfileService = new CustomProfileService(commandGeneratorService)
const customProfilesProvider = new CustomProfilesProvider(context, customProfileService)

vscode.window.registerTreeDataProvider('customProfiles', customProfilesProvider)
19 changes: 12 additions & 7 deletions src/services/custom-profile.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as fs from 'fs'
import * as path from 'path'
import * as child_process from 'child_process'
import * as child_process from 'child-process-promise'
import * as vscode from 'vscode'
import * as json5 from 'json5'
import * as constants from '../constants'
import {CustomProfile} from '../models/custom-profile'
import { CustomProfile } from '../models/custom-profile'
import { CommandGeneratorService } from './command-generator.service'

export class CustomProfileService {
public constructor(private readonly commandGeneratorService: CommandGeneratorService) { }

getAll(): CustomProfile[] {
const {rootStoragePath} = constants
const { rootStoragePath } = constants

// Check if dir exists
const rootExists = fs.existsSync(rootStoragePath)
@@ -17,7 +20,7 @@ export class CustomProfileService {
fs.mkdirSync(rootStoragePath)
}

const rootItems = fs.readdirSync(rootStoragePath, {withFileTypes: true})
const rootItems = fs.readdirSync(rootStoragePath, { withFileTypes: true })
const profileNames = rootItems.filter(item => {
return item.isDirectory()
})
@@ -44,11 +47,11 @@ export class CustomProfileService {
}

async generateProfileJson(profileName: string): Promise<string> {
const userSettingsPath = path.join(constants.rootStoragePath,profileName, 'data','User','settings.json');
const userSettingsPath = path.join(constants.rootStoragePath, profileName, 'data', 'User', 'settings.json');

let userSettingsString = '{}'
if (fs.existsSync(userSettingsPath)) {
userSettingsString = await fs.promises.readFile(userSettingsPath, {encoding: 'utf-8'})
userSettingsString = await fs.promises.readFile(userSettingsPath, { encoding: 'utf-8' })
}

// Get user settings
@@ -60,8 +63,10 @@ export class CustomProfileService {
}

// Get extensions
const getExtensionsCommandOutput = child_process.execSync(`powershell -Command "code --user-data-dir='${path.join(constants.rootStoragePath,profileName,'data')} --extensions-dir='${path.join(constants.rootStoragePath,profileName,'extensions')}' --list-extensions"`)
const getExtensionsCommand = this.commandGeneratorService.generateCommand('code', `--user-data-dir='${path.join(constants.rootStoragePath, profileName, 'data')}' --extensions-dir='${path.join(constants.rootStoragePath, profileName, 'extensions')}' --list-extensions`)
const getExtensionsCommandOutput = await child_process.exec(getExtensionsCommand)
const extensions = getExtensionsCommandOutput
.stdout
.toString()
.trim()
.split(/[\n\r]/)