-
Notifications
You must be signed in to change notification settings - Fork 23
Help me with beforeDeploy #33
Comments
Try to wrap the code with try-catch-blocks and see if an error messages is shown as popup: var vscode = require('vscode');
try {
var fs = require('fs');
var pug = require('pug');
var glob = require('glob');
var path = require('path');
// console.log('building *.pug');
vscode.window.showInformationMessage('build.js: building *.pug');
glob('*.pug', {}, function(error, files){
try {
files.forEach(function(file, index) {
var htmlFilename = path.basename(file, '.pug')+'.html';
console.log(file+' => '+htmlFilename);
fs.writeFile(htmlFilename, pug.renderFile(file, {pretty: true}));
});
resolve(); // tell that anything went fine
}
catch (e) {
vscode.window.showErrorMessage('build.js.forEach(): ' + e);
reject(e);
}
});
}
catch (e) {
vscode.window.showErrorMessage('build.js: ' + e);
reject(e);
} I think the problem is that you have to link the pug module inside your project folder. It is not part of the extension. For |
I had the problem, after I removed the The problem is that this is no NodeJS API / VSCode module. After I replaced var glob = require('glob'); with var glob = args.require('glob'); it works. The require method of These are the modules, the extension currently uses (s. package.json)
BTW: If you want to include own modules, you have to the NodeJS way: // relative to the 'build.js' path
var myModule = require('./my-module.js'); |
Now it seems to work. Open your terminal / command line, go to the folder where your npm link pug It will create a var pug = require('pug'); |
@mkloubert Seems like they are deploying only on Ctrl+Alt+W, but not on Ctr+Alt+F |
@mkloubert
that will be really great. |
There is still a deploy on change feature :-) But before we start: Upgrade at least to version 5.19.1 1. We have to compile the PUG files to HTMLCreate a package that tracks the {
"deploy": {
// ...
"packages": [
// ...
{
"name": "PUG to HTML",
"description": "The files that should be compiled to HTML files.",
"files": [
"/**/*.pug"
],
"deployOnSave": [ "PUG Compiler" ]
}
// ...
]
// ...
}
} This will send all {
"deploy": {
// ...
"targets": [
// ...
{
"name": "PUG Compiler",
"description": "Compiles an HTML file to PUG",
"type": "script",
"script": "./build.js"
}
// ...
]
// ...
}
} This script target will use your function deployFile(args) {
return new Promise(function(resolve, reject) {
var onCompleted = function(err) {
if (err) {
reject(err);
}
else {
resolve(args); // send input arguments
// back to the extension
}
};
if (args.context.isCancelling()) {
// cancellation request
args.canceled = true; // tell the extension
// that we have cancelled
onCompleted();
return;
}
try {
var fs = require('fs');
var path = require('path');
var pug = require('pug');
var file = args.file;
var htmlFilename = path.basename(file, '.pug') + '.html';
var htmlFile = path.join(path.dirname(file),
htmlFilename); // I hope that HTML files
// should be created in
// same directory as PUGs
if (args.deployOptions.onBeforeDeploy) {
// use this to tell the extension that
// we begin to deploy the file
args.deployOptions.onBeforeDeploy(args.sender, {
destination: htmlFilename, // this is only a string
// to display in the output window
file: file,
target: args.target
});
}
// render from PUG to HTML
var pugData = pug.renderFile(file, {
pretty: true
});
// write to HTML file async
fs.writeFile(htmlFile, pugData, (err) => {
onCompleted(err); // tell extenstion that we have finished
});
}
catch (e) {
onCompleted(e);
}
});
}
exports.deployFile = deployFile; Now, when you save PUG files, it automatically compiles then to HTML. 2. Automatically deploy HTML after compilationWhen a HTML file has been generated / changed, you can use the deploy on change feature: Add a second package that tracks changed HTML files: {
"deploy": {
// ...
"packages": [
// ...
{
"name": "HTML from PUG",
"description": "The files that should be deployed after compilation.",
"files": [
"/**/*.html"
],
"deployOnChange": true,
"deployOnSave": [ "HTML target" ]
}
// ...
]
// ...
}
} This will send all modifed / created HTML to the second target, called {
"deploy": {
// ...
"targets": [
// ...
{
"name": "HTML target",
"description": "Deploys HTML files",
"type": "test"
}
// ...
]
// ...
}
} In my example I only used a mock target. Have a look at the wiki where all target types are listed. |
@mkloubert But small mistake in your code // render from PUG to HTML
var pugData = pug.renderFile(htmlFilename, {
pretty: true
});
and that's is not obvious that it's possible to use
and another proposal is to make this combination of two targets to work a little faster. |
Thats right, it needs a better documentation. I described it here, but the better way is to write it down to a separate wiki article, were you find examples for such scenarios. I will do this the next days. With the speed problem, you seem to have the same problem as @rshakespear I realeased version 5.20.0 that should reduce the delay, as you can read here. |
@mkloubert |
Hi, before deploy a want call "gulp build" command for workspace, how i must write it in section "beforeDeploy": [] |
You can use the open operation type: {
"deploy": {
// ...
"targets": [
{
"name": "My target",
"type": "test",
"beforeDeploy": [
{
"type": "open",
"target": "gulp", "arguments": [ "build" ]
}
]
}
]
}
} If the extension cannot execute your npm link gulp |
it working, but it call new cmd window, that after operation not close. Can we use vs code terminal? |
@LexRiver I had same Error: Timed out while waiting for handshake in out\src\plugins\sftp.js, line 179, add readyTimeout: 99999
|
Great! I will add and release a new version that can define that value in about 2 or 3 hours. |
Since version 5.32.0 there is now a readTimeout property: {
"deploy": {
// ...
"targets": [
{
"name": "My target",
"type": "sftp",
"readyTimeout": 99999
}
]
}
} |
Sorry, when I answer so late ... since version 7.0.0 I have implemented the feature of running apps and "bash" scripts inside the integrated terminal (by setting {
"deploy": {
// ...
"targets": [
{
"name": "My target",
"type": "test",
"beforeDeploy": [
{
"type": "open",
"target": "gulp", "arguments": [ "build" ],
"runInTerminal": true
}
]
}
]
}
} |
I'm trying to compile *.pug templates to *.html before deploy.
I have a script which I run like
node build.js
and it works good. But when I'm trying to use it in sectionbeforeDeploy
nothing happens.here is my working script:
and here is my
beforeDeploy
part:and here is my
build.js
script for vs-deploy:So I have no console outputs, no compilation of my *.pug and no errors:
So what I'm doing wrong?
The text was updated successfully, but these errors were encountered: