Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Umoxfo committed Nov 8, 2017
0 parents commit 268a21f
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
test/
build/
package-lock.json
29 changes: 29 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const gulp = require('gulp'),
composer = require('gulp-uglify/composer'),
zip = require('gulp-zip');
const del = require('del'),
exec = require('child_process').exec,
uglifyes = require('uglify-es'),
merge = require('event-stream').merge;
const pkgInfo = require('./package.json'),
uglify = composer(uglifyes, console);

gulp.task('clean', () => del(['build/']));

gulp.task('resolve:node-deps', () => exec('cd ./node && npm install && npm update'));

gulp.task('build', ['clean', 'resolve:node-deps'], () => {
let copy = gulp.src(['package.json', 'node/node_modules/**/*'], {base: '.'}).pipe(gulp.dest('build'));
let minify = gulp.src(['main.js', 'node/*.js'], {base: '.'})
.pipe(uglify({}))
.pipe(gulp.dest('build'));

return merge(copy, minify).on('end', () =>
gulp.src('build/**/*', {base: 'build'})
.pipe(zip(`${pkgInfo.name}-${pkgInfo.version}.zip`))
.pipe(gulp.dest('build/dist')));
});

gulp.task('default', ['build']);
100 changes: 100 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $ */

define(function (require, exports, module) {
'use strict';

const NodeDomain = brackets.getModule('utils/NodeDomain'),
ExtensionUtils = brackets.getModule('utils/ExtensionUtils'),
CodeInspection = brackets.getModule('language/CodeInspection'),
AppInit = brackets.getModule('utils/AppInit'),
Menus = brackets.getModule('command/Menus'),
CommandManager = brackets.getModule('command/CommandManager'),
DocumentManager = brackets.getModule('document/DocumentManager');

const w3cvalidatorSever = new NodeDomain('w3cvalidator', ExtensionUtils.getModulePath(module, 'node/ValidationServer'));

const COMMAND_ID = 'w3cvalidator.refresh',
PROVIDER_ID = 'w3cvalidator';

//var Strings = require("strings");

/**
* Validation Server launcher in standalone
*/
function runServer() {
w3cvalidatorSever.exec('runServer');
}

/**
* Validation handler as a client
*/
function handleValidation(text, fullPath) {
let response = $.Deferred();
let result = {
errors: []
};

$.ajax({
url: "http://localhost:8888/?out=json",
type: 'POST',
contentType: 'text/html; charset=utf-8',
data: text,
cache: false,
processData: false
}).done(function (data, textStatus, jqXHR) {
let messages = data.messages;

if (messages.length) {
messages.forEach(function (item) {
let type;
switch (item.type) {
case 'warning':
type = CodeInspection.Type.WARNING;
break;
case 'error':
type = CodeInspection.Type.ERROR;
break;
}

result.errors.push({
pos: {
line: item.lastLine - 1,
ch: 0
},
message: item.message,
type: type
});
});
}

response.resolve(result);
});

return response.promise();
}

// Listen a file saved event
function refreshValidation() {
DocumentManager.getCurrentDocument().notifySaved();
}

// Register the HTML Linting
AppInit.appReady(function () {
CodeInspection.register("html", {
name: PROVIDER_ID,
scanFileAsync: handleValidation
});
});

// Command
//CommandManager.register(Strings.REFRESH_W3C_VALIDATION, COMMAND_ID, _refreshValidation);
CommandManager.register("Refresh W3C validation", COMMAND_ID, refreshValidation);

// Menu
const editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
editMenu.addMenuItem(COMMAND_ID, "F9");

// Server launcher when extension is loaded
runServer();
});
40 changes: 40 additions & 0 deletions node/ValidationServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */
/*global $, require */

(function () {
'use strict';

const exec = require('child_process').exec,
vnu = require('vnu-jar');

/**
* @private
* Handler function for the w3cvalidator.validate command.
*/
function runServer() {
exec(`java -Xss1m -cp ${vnu} nu.validator.servlet.Main 8888`);
}

/**
* Initializes the test domain with several test commands.
* @param {DomainManager} domainManager The DomainManager for the server
*/
function init(domainManager) {
if (!domainManager.hasDomain('w3cvalidator')) {
domainManager.registerDomain('w3cvalidator', {
major: 0,
minor: 1
});
}

domainManager.registerCommand(
'w3cvalidator',
'runServer',
runServer,
false,
'Runs the validation server in standalone.'
);
}

exports.init = init;
}());
6 changes: 6 additions & 0 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"vnu-jar": "latest"
}
}
55 changes: 55 additions & 0 deletions node/w3cvalidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */
/*global */

(function () {
'use strict';

const exec = require('child_process').execSync,
vnu = require('vnu-jar');

/**
* @private
* Handler function for the w3cvalidator.validate command.
* @param {string} the file path for verification
* @return {string} the validation report
*/
function validate(path) {
exec(`java -Xss2m -jar ${vnu} --format text --skip-non-html ${path}`, (error, stdout, stderr) => {
console.log('stdout: ' + stdout);
console.log('stderror: ' + stderr);

return stderr;
});
}

/**
* Initializes the test domain with several test commands.
* @param {DomainManager} domainManager The DomainManager for the server
*/
function init(domainManager) {
if (!domainManager.hasDomain('w3cvalidator')) {
domainManager.registerDomain('w3cvalidator', {
major: 0,
minor: 1
});
}

domainManager.registerCommand(
'w3cvalidator',
'validate',
validate,
true,
'Returns the validation report of a file', [{
name: 'path',
type: 'string',
description: 'the file path for verification'
}], [{
name: 'report',
type: 'string',
description: 'validation report in JSON format'
}]
);
}

exports.init = init;
}());
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "umoxfo.w3cvalidation",
"title": "W3C Validation (by Umoxfo)",
"version": "1.0.0",
"description": "Adds W3C validation support to Brackets.",
"homepage": "",
"keywords": [
"html",
"lint",
"linting",
"linter"
],
"categories": "linting",
"author": "Makoto Sakaguchi <ycco34vx@gmail.com>",
"license": "MIT",
"engines": {
"brackets": ">=0.24.0"
},
"devDependencies": {
"gulp": "latest",
"gulp-uglify": "latest",
"gulp-zip": "latest",
"del": "latest",
"uglify-es": "latest",
"event-stream": "latest"
}
}

0 comments on commit 268a21f

Please sign in to comment.