Skip to content

Commit

Permalink
Adds better support for insiders version
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 24, 2020
1 parent 90a1c90 commit 25ecfbe
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 27 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/cd-insiders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ jobs:
node-version: '12.x'
- name: Install
run: yarn
- name: Patch README.md
run: node -e "var insert = fs.readFileSync('./README.insiders.md'); var d = fs.readFileSync('./README.md'); fs.writeFileSync('./README.md', insert + '\n' + d);"
- name: Patch package.json
run: |
node -e "var d = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })); var p = require('./package.json'); p = JSON.stringify({...p, name: p.name + '-insiders', displayName: p.displayName + ' (Insiders)', version: '' + d.getFullYear() + '.' + (d.getMonth() + 1) + '.' + d.getDate() + String(d.getHours()).padStart(2, '0') }); fs.writeFileSync('./package.json', p);"
- name: Apply insiders patch
run: yarn run patch-insiders
- name: Setup Environment
run: node -e "console.log('PACKAGE_VERSION=' + require('./package.json').version + '\nPACKAGE_NAME=' + require('./package.json').name + '-' + require('./package.json').version)" >> $GITHUB_ENV
- name: Package extension
Expand Down
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist/webviews/*.css
emoji/**
images/docs/**
node_modules/**
scripts/**
src/**
test/**
**/*.fig
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8115,6 +8115,7 @@
"lint": "eslint src/**/*.ts --fix --cache",
"optimize:webviews": "webpack --config-name webviews --env.optimizeImages",
"pack": "vsce package --yarn",
"patch-insiders": "node ./scripts/applyPatchForInsiders.js",
"pretty": "prettier --config .prettierrc --loglevel warn --write .",
"pub": "vsce publish --yarn",
"rebuild": "yarn run reset && yarn run build",
Expand All @@ -8124,7 +8125,7 @@
"watch:webviews": "webpack --watch --mode development --config-name webviews",
"update-dts": "pushd \"src/@types\" && npx vscode-dts dev && popd",
"update-dts:master": "pushd \"src/@types\" && npx vscode-dts master && popd",
"update-emoji": "node ./generateEmojiShortcodeMap.js",
"update-emoji": "node ./scripts/generateEmojiShortcodeMap.js",
"vscode:prepublish": "yarn run bundle"
},
"dependencies": {
Expand Down
25 changes: 25 additions & 0 deletions scripts/applyPatchForInsiders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable import/order */
/* eslint-disable @typescript-eslint/no-var-requires */
'use strict';
const fs = require('fs');

// Patch README
const insert = fs.readFileSync('./README.insiders.md', { encoding: 'utf8' });
const data = fs.readFileSync('./README.md', { encoding: 'utf8' });
fs.writeFileSync('./README.md', `${insert}\n${data}`);

// Patch package.json
const date = new Date(new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }));
let json = require('../package.json');

json = JSON.stringify({
...json,
name: `${json.name}-insiders`,
displayName: `${json.displayName} (Insiders)`,
version: `${String(date.getFullYear())}.${date.getMonth() + 1}.${date.getDate()}${String(date.getHours()).padStart(
2,
'0',
)}`,
preview: true,
});
fs.writeFileSync('./package.json', json);
File renamed without changes.
9 changes: 4 additions & 5 deletions src/commands/setViewsLayout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
import { commands, window } from 'vscode';
import { viewsConfigKeys } from '../configuration';
import { extensionId } from '../constants';
import { command, Command, Commands } from './common';

enum ViewsLayout {
Expand Down Expand Up @@ -53,8 +52,8 @@ export class SetViewsLayoutCommand extends Command {
let count = 0;
while (count++ < 2) {
void (await commands.executeCommand('vscode.moveViews', {
viewIds: viewsConfigKeys.map(view => `${extensionId}.views.${view}`),
destinationId: `workbench.view.extension.${extensionId}`,
viewIds: viewsConfigKeys.map(view => `gitlens.views.${view}`),
destinationId: 'workbench.view.extension.gitlens',
}));
}
} catch {}
Expand All @@ -66,13 +65,13 @@ export class SetViewsLayoutCommand extends Command {
let count = 0;
while (count++ < 2) {
void (await commands.executeCommand('vscode.moveViews', {
viewIds: viewsConfigKeys.map(view => `${extensionId}.views.${view}`),
viewIds: viewsConfigKeys.map(view => `gitlens.views.${view}`),
destinationId: 'workbench.view.scm',
}));
}
} catch {
for (const view of viewsConfigKeys) {
void (await commands.executeCommand(`${extensionId}.views.${view}.resetViewLocation`));
void (await commands.executeCommand(`gitlens.views.${view}.resetViewLocation`));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
workspace,
} from 'vscode';
import { Config } from './config';
import { extensionId } from './constants';
import { Objects } from './system';

const extensionId = 'gitlens';

type ConfigInspection<T> = {
key: string;
defaultValue?: T;
Expand Down
6 changes: 0 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { commands, TextDocument, TextEditor, window } from 'vscode';
import { ViewShowBranchComparison } from './config';
import { SearchPattern } from './git/git';

export const applicationInsightsKey = 'a9c302f8-6483-4d01-b92c-c159c799c679';
export const extensionId = 'gitlens';
export const extensionOutputChannelName = 'GitLens';
export const extensionQualifiedId = `eamodio.${extensionId}`;
export const extensionTerminalName = 'GitLens';

export const quickPickTitleMaxChars = 80;

export enum BuiltInCommands {
Expand Down
12 changes: 11 additions & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class Container {
| ((e: ConfigurationChangeEvent) => ConfigurationChangeEvent)
| undefined;

static initialize(context: ExtensionContext, config: Config) {
static initialize(extensionId: string, context: ExtensionContext, config: Config) {
this._extensionId = extensionId;
this._context = context;
this._config = Container.applyMode(config);

Expand Down Expand Up @@ -171,6 +172,11 @@ export class Container {
return this._contributorsView;
}

private static _extensionId: string;
static get extensionId() {
return this._extensionId;
}

private static _fileAnnotationController: FileAnnotationController;
static get fileAnnotations() {
return this._fileAnnotationController;
Expand Down Expand Up @@ -208,6 +214,10 @@ export class Container {
}
}

static get insiders() {
return this._extensionId.endsWith('-insiders');
}

private static _keyboard: Keyboard;
static get keyboard() {
return this._keyboard;
Expand Down
22 changes: 19 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
import * as paths from 'path';
import { commands, ExtensionContext, extensions, window, workspace } from 'vscode';
import { Commands, registerCommands } from './commands';
import { configuration, Configuration } from './configuration';
import { ContextKeys, extensionQualifiedId, GlobalState, GlyphChars, setContext, SyncedState } from './constants';
import { ContextKeys, GlobalState, GlyphChars, setContext, SyncedState } from './constants';
import { Container } from './container';
import { Git, GitCommit } from './git/git';
import { GitService } from './git/gitService';
Expand All @@ -15,6 +16,21 @@ import { ViewNode } from './views/nodes';
export async function activate(context: ExtensionContext) {
const start = process.hrtime();

let extensionId = 'eamodio.gitlens';
if (paths.basename(context.globalStorageUri.fsPath) === 'eamodio.gitlens-insiders') {
extensionId = 'eamodio.gitlens-insiders';

// Ensure that stable isn't also installed
const stable = extensions.getExtension('eamodio.gitlens');
if (stable != null) {
Logger.log('GitLens (Insiders) was NOT activated because GitLens is also installed');

void Messages.showInsidersErrorMessage();

return;
}
}

// Pretend we are enabled (until we know otherwise) and set the view contexts to reduce flashing on load
void setContext(ContextKeys.Enabled, true);

Expand Down Expand Up @@ -42,7 +58,7 @@ export async function activate(context: ExtensionContext) {
return undefined;
});

const gitlens = extensions.getExtension(extensionQualifiedId)!;
const gitlens = extensions.getExtension(extensionId)!;
const gitlensVersion = gitlens.packageJSON.version;

const syncedVersion = context.globalState.get<string>(SyncedState.Version);
Expand Down Expand Up @@ -108,7 +124,7 @@ export async function activate(context: ExtensionContext) {
return;
}

Container.initialize(context, cfg);
Container.initialize(extensionId, context, cfg);

registerCommands(context);

Expand Down
4 changes: 2 additions & 2 deletions src/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
import { commands, Disposable } from 'vscode';
import { ContextKeys, extensionId, setContext } from './constants';
import { ContextKeys, setContext } from './constants';
import { Logger } from './logger';
import { log } from './system';

Expand Down Expand Up @@ -152,7 +152,7 @@ export class Keyboard implements Disposable {

constructor() {
const subscriptions = keys.map(key =>
commands.registerCommand(`${extensionId}.key.${key}`, () => this.execute(key), this),
commands.registerCommand(`gitlens.key.${key}`, () => this.execute(key), this),
);
this._disposable = Disposable.from(...subscriptions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
import { ExtensionContext, ExtensionMode, OutputChannel, Uri, window } from 'vscode';
import { TraceLevel } from './configuration';
import { extensionOutputChannelName } from './constants';
import { getCorrelationContext, getNextCorrelationId } from './system';

const emptyStr = '';
const extensionOutputChannelName = 'GitLens';
const ConsolePrefix = `[${extensionOutputChannelName}]`;

export { TraceLevel } from './configuration';
Expand Down
10 changes: 9 additions & 1 deletion src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Messages {
static showGitDisabledErrorMessage() {
return Messages.showMessage(
'error',
'GitLens requires Git to be enabled. Please re-enable Git \u2014 set `git.enabled` to true and reload',
'GitLens requires Git to be enabled. Please re-enable Git \u2014 set `git.enabled` to true and reload.',
SuppressedMessages.GitDisabledWarning,
);
}
Expand All @@ -78,6 +78,14 @@ export class Messages {
);
}

static showInsidersErrorMessage() {
return Messages.showMessage(
'error',
'GitLens (Insiders) cannot be used while GitLens is also installed. Please ensure that only one version of GitLens is installed.',
SuppressedMessages.GitDisabledWarning,
);
}

static showLineUncommittedWarningMessage(message: string): Promise<MessageItem | undefined> {
return Messages.showMessage(
'warn',
Expand Down
3 changes: 2 additions & 1 deletion src/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';
import { Disposable, Terminal, window } from 'vscode';
import { extensionTerminalName } from './constants';
import { Container } from './container';

let _terminal: Terminal | undefined;
let _terminalCwd: string | undefined;
let _disposable: Disposable | undefined;

const extensionTerminalName = 'GitLens';

function ensureTerminal(cwd: string): Terminal {
if (_terminal === undefined) {
_terminal = window.createTerminal(extensionTerminalName);
Expand Down

0 comments on commit 25ecfbe

Please sign in to comment.