Skip to content

Commit

Permalink
Add PhantomJS auto-rebuild-functionallity
Browse files Browse the repository at this point in the history
This fixes issue #2
Sadly phantomjs-prebuilt isn't working on every platform out of the box.
For that reason MarkdownConverter now checks whether phantomjs is compiled for the correct os.
If not, phantomjs will be rebuilt.
  • Loading branch information
manuth committed Apr 13, 2017
1 parent 778b998 commit 573491e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
## 0.0.7
- Adjusted the version-numbers
- Improved the date-test for security-reasons
- Added TypeScript-definitions
- Added PhantomJS-rebuild functionallity in order to build PhantomJS for the propper os. [#2](https://github.com/manuth/MarkdownConverter/issues/2)

<!--- References -->
[MarkdownItCheckbox]: https://www.npmjs.com/package/markdown-it-checkbox
6 changes: 4 additions & 2 deletions Resources/Localization/MarkdownConverter.nls.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"{0}: {1}",
"Der Zugriff auf \"{0}\" ist fehlgeschlagen.",
"Fehler: PhantomJS konnte nicht richtig ausgeführt werden.",
"Fehler: Der YAML-Block ist nicht richtig formatiert. Zeile {0}, Spalte {1}."
"Fehler: Der YAML-Block ist nicht richtig formatiert. Zeile {0}, Spalte {1}.",
"Fehler: PhantomJS konnte nicht re-kompiliert werden."
],
"keys": [
"SuccessMesage",
"OpenFileLabel",
"UnknownException",
"UnauthorizedAccessException",
"PhantomJSTimeoutException",
"YAMLException"
"YAMLException",
"PhantomRebuildException"
]
}
6 changes: 4 additions & 2 deletions Resources/Localization/MarkdownConverter.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"{0}: {1}",
"Couldn't access the \"{0}\".",
"Error: PhantomJS timed out.",
"Error: The YAML-block is malformatted. Line {0}, column {1}."
"Error: The YAML-block is malformatted. Line {0}, column {1}.",
"Error: Couldn't rebuild PhantomJS."
],
"keys": [
"SuccessMesage",
"OpenFileLabel",
"UnknownException",
"UnauthorizedAccessException",
"PhantomJSTimeoutException",
"YAMLException"
"YAMLException",
"PhantomRebuildException"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "markdown-converter",
"displayName": "MarkdownConverter",
"description": "Provides the functionallity to convert MarkDown-files to html, pdf or png.",
"version": "0.0.6",
"version": "0.0.7",
"publisher": "manuth",
"author": {
"name": "Manuel Thalmann",
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Fullname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export class Fullname
*/
private static CheckGit() : string
{
return shell.exec('git config --global user.name');
return shell.exec('git config --global user.name').stdout;
}

/**
* Tries to figure out the username using osascript.
*/
private static CheckOsaScript() : string
{
return shell.exec('osascript -e long user name of (system info)');
return shell.exec('osascript -e long user name of (system info)').stdout;
}

/**
Expand Down
20 changes: 17 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as Path from 'path';
import { ConversionType } from "./ConversionType";
import { ConfigKey } from "./Core/Constants";
import { MarkdownFileNotFoundException } from "./Core/MarkdownFileNotFoundException";
import * as nls from 'vscode-nls';
import * as NLS from 'vscode-nls';
import * as PhantomJS from 'phantomjs-prebuilt';
import { Program } from "./Program";
import { UnauthorizedAccessException } from "./Core/UnauthorizedAccessException";
import { YAMLException } from "./Core/YAMLException";
Expand All @@ -15,11 +16,24 @@ import { YAMLException } from "./Core/YAMLException";
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext)
{

// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
// console.log('Congratulations, your extension "markdown-converter" is now active!');

// Rebuilding PhantomJS if required.
if (PhantomJS.platform != process.platform)
{
try
{
require(Path.join(__dirname, '..', '..', 'node_modules', 'phantomjs-prebuilt', 'install.js'));
}
catch (e)
{
let localize : any = NLS.config({ locale: vscode.env.language })(Path.join(__dirname, '..', '..', 'Resources', 'Localization', 'MarkdownConverter'));
vscode.window.showErrorMessage(localize(6 /* PhantomRebuildException */, null))
}
}

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
Expand Down Expand Up @@ -105,7 +119,7 @@ export function activate(context: vscode.ExtensionContext)
}
catch(e)
{
let localize : any = nls.config({ locale: vscode.env.language })(Path.join(__dirname, '..', '..', 'Resources', 'Localization', 'MarkdownConverter'));
let localize : any = NLS.config({ locale: vscode.env.language })(Path.join(__dirname, '..', '..', 'Resources', 'Localization', 'MarkdownConverter'));
let message;

if (e instanceof UnauthorizedAccessException)
Expand Down

0 comments on commit 573491e

Please sign in to comment.