Skip to content

Commit

Permalink
Add new version notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
svsool committed Jul 23, 2020
1 parent fae97bb commit 64ac1b1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.vscode-test/
*.vsix
yarn-error.log
VERSION
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ yarn-error.log
**/*.map
**/*.ts
node_modules
VERSION
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ If you want to try out Memo just install it via marketplace using [this link](ht
- Leave a review on [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=svsool.markdown-memo).
- Read [CONTRIBUTING.md](CONTRIBUTING.md) for contributing to the code base.

Some ideas for contribution can be found [here](https:/svsool/vscode-memo/issues/1#issuecomment-655004112).

## Changelog

See changelog [here](CHANGELOG.md).
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
ReferenceRenameProvider,
BacklinksTreeDataProvider,
extendMarkdownIt,
newVersionNotifier,
} from './extensions';
import { cacheWorkspace } from './utils';
import commands from './commands';

const mdLangSelector = { language: 'markdown', scheme: '*' };

export const activate = async (context: vscode.ExtensionContext) => {
newVersionNotifier.activate(context);
syntaxDecorations.activate(context);
fsWatcher.activate(context);
completionProvider.activate(context);
Expand Down
1 change: 1 addition & 0 deletions src/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { default as extendMarkdownIt } from './extendMarkdownIt';
export * as fsWatcher from './fsWatcher';
export * as referenceContextWatcher from './referenceContextWatcher';
export * as syntaxDecorations from './syntaxDecorations';
export * as newVersionNotifier from './newVersionNotifier';
23 changes: 23 additions & 0 deletions src/extensions/newVersionNotifier.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ExtensionContext } from 'vscode';
import path from 'path';

import * as newVersionNotifier from './newVersionNotifier';
import { closeEditorsAndCleanWorkspace } from '../test/testUtils';

describe('newVersionNotifier extension', () => {
beforeEach(closeEditorsAndCleanWorkspace);

afterEach(closeEditorsAndCleanWorkspace);

it('should not fail on activate', () => {
expect(() => {
console.log('test', path.resolve(path.join(__dirname, '..', '..')));
const mockContext = ({
subscriptions: [],
extensionPath: path.resolve(path.join(__dirname, '..', '..')),
} as unknown) as ExtensionContext;
newVersionNotifier.activate(mockContext);
mockContext.subscriptions.forEach((sub) => sub.dispose());
}).not.toThrow();
});
});
40 changes: 40 additions & 0 deletions src/extensions/newVersionNotifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import fs from 'fs';
import path from 'path';
import { window, commands, Uri, ExtensionContext } from 'vscode';

// Add new version teasers for showing notification on extension update
const teasers: { [key: string]: string } = {
'0.1.10': 'Memo v0.1.10! Links rename, opening links in the default app and more.',
};

const showMeAction = 'Show Me';

export const activate = (context: ExtensionContext) => {
try {
const versionPath = path.join(context.extensionPath, 'VERSION');
const data = fs.readFileSync(path.join(context.extensionPath, 'package.json')).toString();
const currentVersion: string = JSON.parse(data).version;

const teaserMsg = teasers[currentVersion];

if (
!teaserMsg ||
(fs.existsSync(versionPath) && fs.readFileSync(versionPath).toString() === currentVersion)
) {
return;
}

fs.writeFileSync(versionPath, currentVersion);

window.showInformationMessage(teaserMsg, showMeAction, 'Dismiss').then((option) => {
if (option === showMeAction) {
commands.executeCommand(
'vscode.open',
Uri.parse('https:/svsool/vscode-memo/blob/master/CHANGELOG.md'),
);
}
});
} catch (error) {
console.log(error);
}
};

0 comments on commit 64ac1b1

Please sign in to comment.