Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
fixed compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 6, 2018
1 parent 80652f6 commit 72938c7
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)


## 0.22.0 (January 6th, 2018; [compiler](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_compiler) target)

* fixed generating output files in [compiler target](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_compiler)
* updated [npm packages](https://www.npmjs.com):
* [node-eumerable](https://www.npmjs.com/package/node-eumerable) to `^3.9.0`

## 0.21.0 (January 5th, 2018; copy remote directory to clipboard)

* can copy directory path to clipboard, when [list of remote directory](https://github.com/mkloubert/vscode-deploy-reloaded#list-remote-files-), now, s. [issue #10](https://github.com/mkloubert/vscode-deploy-reloaded/issues/10)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.21.0",
"version": "0.22.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down Expand Up @@ -54564,7 +54564,7 @@
"@types/ssh2-sftp-client": "^2.0.0",
"@types/tmp": "0.0.33",
"@types/uuid": "^3.4.3",
"typescript": "^2.6.1",
"typescript": "^2.6.2",
"vscode": "^1.1.10"
},
"icon": "icon.png",
Expand Down Expand Up @@ -54614,7 +54614,7 @@
"moment-timezone": "^0.5.14",
"mssql": "^4.1.0",
"mysql": "^2.15.0",
"node-enumerable": "^3.8.0",
"node-enumerable": "^3.9.0",
"node-simple-socket": "^2.8.1",
"node-zip": "^1.1.1",
"nodemailer": "^4.4.1",
Expand Down
76 changes: 74 additions & 2 deletions src/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export enum Compiler {
* Options for compiliation.
*/
export interface CompileOptions<TOptions = any> extends deploy_contracts.FileFilter {
/**
* The custom base directory.
*/
readonly baseDirectory?: string;
/**
* Special options directly for the underlying compiler.
*/
Expand Down Expand Up @@ -197,6 +201,72 @@ export async function compile(compiler: Compiler, opts: CompileOptions): Promise
compiler));
}

/**
* Returns the base directory from compiler options.
*
* @param {CompileOptions} opts The options.
*
* @return {string} The full path of the base directory.
*/
export function getBaseDirectory(opts: CompileOptions) {
if (!opts) {
opts = <any>{};
}

const WORKSPACE = opts.workspace;

let baseDirectory = WORKSPACE.replaceWithValues(opts.baseDirectory);
if (deploy_helpers.isEmptyString(baseDirectory)) {
baseDirectory = WORKSPACE.rootPath;
}
if (!Path.isAbsolute(baseDirectory)) {
baseDirectory = Path.join(WORKSPACE.rootPath, baseDirectory);
}

return Path.resolve(baseDirectory);
}

/**
* Returns the full output path for a file.
*
* @param {string} file The input file path.
* @param {CompileOptions} opts The options.
*
* @return {string} The output file path.
*/
export function getFullOutputPathForSourceFile(file: string, opts: CompileOptions) {
file = deploy_helpers.toStringSafe(file);

if (!opts) {
opts = <any>{};
}

const WORKSPACE = opts.workspace;

const BASE_DIR = getBaseDirectory(opts);

if (!Path.isAbsolute(file)) {
file = Path.join(BASE_DIR, file);
}

let outputDir = getOutputDirectory(opts);
if (false === outputDir) {
outputDir = Path.dirname(file);
}
outputDir = Path.resolve(outputDir);

if (file.startsWith(BASE_DIR)) {
// re-map

file = Path.join(
outputDir,
file.substr(BASE_DIR.length), // relative path of 'file'
);
}

return Path.resolve(file);
}

/**
* Returns the output directory from compiler options.
*
Expand All @@ -211,11 +281,13 @@ export function getOutputDirectory(opts: CompileOptions): string | false {

const WORKSPACE = opts.workspace;

let customOutDir: string | false = WORKSPACE.replaceWithValues(opts.outDirectory);
const BASE_DIR = getBaseDirectory(opts);

let customOutDir = WORKSPACE.replaceWithValues(opts.outDirectory);
if (!deploy_helpers.isEmptyString(customOutDir)) {
if (!Path.isAbsolute(customOutDir)) {
customOutDir = Path.join(
WORKSPACE.rootPath,
BASE_DIR,
customOutDir
);
}
Expand Down
14 changes: 7 additions & 7 deletions src/compilers/coffeescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ export async function compile(compileOpts: CompileOptions) {
let msg: CompileResultMessage;

try {
let outDir = deploy_compilers.getOutputDirectory(compileOpts);
if (false === outDir) {
outDir = Path.dirname(FTC);
}
const OUTPUT_FILE_PATH = deploy_compilers.getFullOutputPathForSourceFile(FTC, compileOpts);
const OUT_DIR = Path.dirname(OUTPUT_FILE_PATH);

const EXT = Path.extname(FTC);
const FILENAME = Path.basename(FTC, EXT);
await deploy_helpers.createDirectoryIfNeeded(OUT_DIR);

const OUTPUT_FILE = Path.join(outDir,
const EXT = Path.extname(OUTPUT_FILE_PATH);
const FILENAME = Path.basename(OUTPUT_FILE_PATH, EXT);

const OUTPUT_FILE = Path.join(OUT_DIR,
FILENAME + '.' + outExt);

const JS_CODE: string = CoffeeScript.compile((await deploy_helpers.readFile(FTC)).toString(enc),
Expand Down
16 changes: 8 additions & 8 deletions src/compilers/htmlminifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,20 @@ export async function compile(compileOpts: CompileOptions) {
let msg: CompileResultMessage;

try {
let outDir = deploy_compilers.getOutputDirectory(compileOpts);
if (false === outDir) {
outDir = Path.dirname(FTC);
}
const OUTPUT_FILE_PATH = deploy_compilers.getFullOutputPathForSourceFile(FTC, compileOpts);
const OUT_DIR = Path.dirname(OUTPUT_FILE_PATH);

await deploy_helpers.createDirectoryIfNeeded(OUT_DIR);

const EXT = Path.extname(FTC);
const FILENAME = Path.basename(FTC, EXT);
const EXT = Path.extname(OUTPUT_FILE_PATH);
const FILENAME = Path.basename(OUTPUT_FILE_PATH, EXT);

let outputFile: string;
if ('' === outExt) {
outputFile = FTC;
outputFile = OUTPUT_FILE_PATH;
}
else {
outputFile = Path.join(outDir,
outputFile = Path.join(OUT_DIR,
FILENAME + '.' + outExt);
}
outputFile = Path.resolve(outputFile);
Expand Down
14 changes: 7 additions & 7 deletions src/compilers/less.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ export async function compile(compileOpts: CompileOptions) {
try {
const LESS_CODE = (await deploy_helpers.readFile(FTC)).toString(enc);

let outDir = deploy_compilers.getOutputDirectory(compileOpts);
if (false === outDir) {
outDir = Path.dirname(FTC);
}
const OUTPUT_FILE_PATH = deploy_compilers.getFullOutputPathForSourceFile(FTC, compileOpts);
const OUT_DIR = Path.dirname(OUTPUT_FILE_PATH);

const EXT = Path.extname(FTC);
const FILENAME = Path.basename(FTC, EXT);
await deploy_helpers.createDirectoryIfNeeded(OUT_DIR);

const OUTPUT_FILE = Path.join(outDir,
const EXT = Path.extname(OUTPUT_FILE_PATH);
const FILENAME = Path.basename(OUTPUT_FILE_PATH, EXT);

const OUTPUT_FILE = Path.join(OUT_DIR,
FILENAME + '.' + outExt);

const LESS_OUTPUT = await LESS.render(LESS_CODE, OPTS);
Expand Down
14 changes: 7 additions & 7 deletions src/compilers/pug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ export async function compile(compileOpts: CompileOptions) {
const PUG_OPTS = deploy_helpers.cloneObject(OPTS);
PUG_OPTS.filename = FTC;

let outDir = deploy_compilers.getOutputDirectory(compileOpts);
if (false === outDir) {
outDir = Path.dirname(FTC);
}
const OUTPUT_FILE_PATH = deploy_compilers.getFullOutputPathForSourceFile(FTC, compileOpts);
const OUT_DIR = Path.dirname(OUTPUT_FILE_PATH);

const EXT = Path.extname(FTC);
const FILENAME = Path.basename(FTC, EXT);
await deploy_helpers.createDirectoryIfNeeded(OUT_DIR);

const OUTPUT_FILE = Path.join(outDir,
const EXT = Path.extname(OUTPUT_FILE_PATH);
const FILENAME = Path.basename(OUTPUT_FILE_PATH, EXT);

const OUTPUT_FILE = Path.join(OUT_DIR,
FILENAME + '.' + outExt);

const HTML = Pug.render((await deploy_helpers.readFile(FTC)).toString(enc),
Expand Down
16 changes: 8 additions & 8 deletions src/compilers/uglifyjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ export async function compile(compileOpts: CompileOptions) {
let msg: CompileResultMessage;

try {
let outDir = deploy_compilers.getOutputDirectory(compileOpts);
if (false === outDir) {
outDir = Path.dirname(FTC);
}
const OUTPUT_FILE_PATH = deploy_compilers.getFullOutputPathForSourceFile(FTC, compileOpts);
const OUT_DIR = Path.dirname(OUTPUT_FILE_PATH);

await deploy_helpers.createDirectoryIfNeeded(OUT_DIR);

const EXT = Path.extname(FTC);
const FILENAME = Path.basename(FTC, EXT);
const EXT = Path.extname(OUTPUT_FILE_PATH);
const FILENAME = Path.basename(OUTPUT_FILE_PATH, EXT);

let outputFile: string;
if ('' === outExt) {
outputFile = FTC;
outputFile = OUTPUT_FILE_PATH;
}
else {
outputFile = Path.join(outDir,
outputFile = Path.join(OUT_DIR,
FILENAME + '.' + outExt);
}
outputFile = Path.resolve(outputFile);
Expand Down
19 changes: 19 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,25 @@ export function createCompletedAction<TResult = any>(resolve: (value?: TResult |
};
}

/**
* Creates a directory (if needed).
*
* @param {string} dir The path of the directory to create.
*
* @return {Promise<boolean>} The promise that indicates if directory has been created or not.
*/
export async function createDirectoryIfNeeded(dir: string) {
dir = toStringSafe(dir);

if (!(await exists(dir))) {
await mkdirs(dir);

return true;
}

return false;
}

/**
* Handles a value as string and checks if it does match at least one (minimatch) pattern.
*
Expand Down

0 comments on commit 72938c7

Please sign in to comment.