mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
feature(beautify) add
This commit is contained in:
parent
3ee321bbce
commit
b65cba7410
1 changed files with 37 additions and 0 deletions
37
lib/server/beautify.js
Normal file
37
lib/server/beautify.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
|
||||
Util = require('../util'),
|
||||
tryRequire = require('./tryRequire'),
|
||||
beautify = tryRequire('js-beautify');
|
||||
|
||||
module.exports = function(name, callback) {
|
||||
var EXT = ['js', 'css', 'html'],
|
||||
ext = path
|
||||
.extname(name)
|
||||
.slice(1),
|
||||
|
||||
is = ~EXT.indexOf(ext);
|
||||
|
||||
if (!beautify)
|
||||
callback(Error('Beautify not installed'));
|
||||
else if (!is)
|
||||
callback(Error('File should be: ' + EXT));
|
||||
else
|
||||
fs.readFile(name, 'utf8', function(error, data) {
|
||||
var result;
|
||||
|
||||
if (!error)
|
||||
error = Util.exec.try(function() {
|
||||
result = beautify[ext](data);
|
||||
});
|
||||
|
||||
|
||||
callback(error, result);
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue