New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

includejs

Package Overview
Dependencies
Maintainers
1
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

includejs - npm Package Compare versions

Comparing version 0.3.5 to 0.3.6

build.config

43

lib/action/build.js

@@ -17,6 +17,7 @@ void

if (i > includeIndex) {
var s = String.format( //
"var include = new IncludeResource('%1','%2','%3',null,null,'%4')", //
x.type, x.namespace ? '' : x.url, x.namespace || '', x.id //
);
var s = String.format("include.setCurrent({ id: '#{id}', namespace: '#{namespace}', url: '{url}'});", {
id: x.id,
namespace: x.namespace,
url: !x.namespace ? x.url : ''
});
output.js.push(s);

@@ -28,5 +29,6 @@ }

var info = String.format("include.cfg(%1); include.register(%2)", //
JSON.stringify(window.include.cfg()), //
JSON.stringify(solution.bin));
var info = String.format("include.cfg(#{config}); include.register(#{register})", {
config: JSON.stringify(window.include.cfg()),
register: JSON.stringify(solution.bin)
});

@@ -39,8 +41,4 @@ output.js.splice(includeIndex + 1, 0, info);

css: function(solution, stack, output) {
for (var i = 0, x, length = stack.length; x = stack[i], i < length; i++) {
var images = new w.handler.CssHandler(solution.uri, solution.uris.outputDirectory.toDir(), x);
if (images && images.length) {
(new handler.io.FileCopier()).copySync(images);
}
new w.handler.CssHandler(solution.uri, solution.uris.outputDirectory, x);
}

@@ -72,4 +70,4 @@ output.css = r.arr.select(stack, 'source').join(w.sys.newLine);

include.promise('action').builder = {
include.promise('action').builder = {
ofType: function(type, solution) {

@@ -84,3 +82,3 @@ var stack = includesStack.resolve(type, solution.resource.includes);

combine: function(solution) {
build: function(solution) {
solution.output = {};

@@ -95,2 +93,15 @@ solution.bin = {};

this.ofType('js', solution);
if (solution.output.js){
new io.File(solution.uris.outputDirectory.combine('script.js')).write(solution.output.js);
}
if (solution.output.css) {
new io.File(solution.uris.outputDirectory.combine('style.css')).write(solution.output.css);
}
HtmlDocument.createSolutionHtml(solution, solution.output);
new io.File(solution.uris.outputMain).write(solution.output.html);
}

@@ -103,3 +114,3 @@ }

var includesStack = (function() {
function build(type, includes) {

@@ -106,0 +117,0 @@ if (!includes && !includes.length) return null;

include.js({
framework: ['utils', 'arr', 'net/uri'],
handler: 'io',
'': '/lib/helpers.js'
handler: ['files/includeRoutes']
}).done(function() {
var program = require('commander');
var w = window,
p = w.program,
path = p.args[1],
targetUri = new net.URI(process.cwd() + '/'),
sourceDir = new io.Directory(io.env.applicationDir.combine('/template/').combine(path));
var TemplateProject = Class({
process: function(includeJSDir, path) {
var targetUri = new net.URI(process.cwd() + '/'),
sourceDir = new net.URI(includeJSDir).combine('/template/').combine(path),
files = app.service('io', 'file/allSync', {
dir: sourceDir.toLocalDir()
});
if (sourceDir.exists() == false) {
return console.error('Source Directory Not Found - ', sourceDir.uri.toString());
}
sourceDir.readFiles().copyTo(targetUri);
this.files = ruqq.arr.map(files, function(x) {
return {
copyTo: targetUri.combine(x),
copyFrom: sourceDir.combine(x)
}
});
for (var i = 0, x, length = this.files.length; x = this.files[i], i < length; i++) {
if (app.service('io', 'file/exists', {
file: x.copyTo.toLocalFile()
})) {
program.prompt('Some Files already exists in target Directory. Replace(y/n)? ', this.copy.bind(this));
return;
}
}
this.copy('y');
},
copy: function(r) {
if (r == 'y') {
new window.handler.io.FileCopier().copySync(this.files);
} else {
console.log('Canceled');
}
process.exit();
}
});
return new TemplateProject;
});
return 0;
});

@@ -14,27 +14,20 @@ void function(){

include.promise('handler').CssHandler = Class({
Construct: function(solutionUri, outputDirectory, resource){
Construct: function(solutionUri, outputDirectoryUri, resource){
var handlePath = true, copyImages;
var copyImages = !urlhelper.isSubDir(solutionUri.toString(), resource.uri.toString()),
images = w.parser.css.extractImages(solutionUri, resource.uri, resource.source);
if (urlhelper.isSubDir(solutionUri.toString(), resource.uri.toString()) == false){
copyImages = true;
}
var images = w.parser.css.extractImages(solutionUri, resource.uri, resource.source);
var arr = [];
for(var i = 0, x, length = images.length; x = images[i], i<length; i++){
if (!copyImages){
x.replaceWith = helper.getRewritenPath(x.uri, x.href, outputDirectory);
}else{
var path = net.URI.combine(outputDirectory, 'images', resource.id || ''),
if (copyImages){
var path = outputDirectoryUri.combine('images/').combine(resource.id || ''),
uri = solutionUri.combine(path).combine(resource.file);
x.replaceWith = helper.getRewritenPath(uri, x.href, outputDirectory);
arr.push({
copyFrom: x.uri,
copyTo: uri
});
new io.File(x.uri).copyTo(uri);
x.replaceWith = helper.getRewritenPath(uri, x.href, outputDirectoryUri.toDir());
}else{
x.replaceWith = helper.getRewritenPath(x.uri, x.href, outputDirectoryUri.toDir());
}

@@ -46,3 +39,2 @@

return arr;

@@ -49,0 +41,0 @@ }

@@ -1,60 +0,148 @@

void function(w) {
void
w.include.promise('handler').io = {
FileCopier: Class({
Construct: function(list, idfr){
this.list = list;
this.idfr = idfr;
this.index = -1;
},
process: function(){
if (++this.index > this.list.length){
this.idfr.resolve(this);
return this;
}
var current = this.list[this.index],
from = current.copyFrom.toLocalFile(),
to = current.copyTo.toLocalFile();
this.idfr.progress && this.idfr.progress(this, String.format('Copy: %1 to %2', from, to));
w.app.service('io','file/copy',{
from: from,
to: to
}, this.process.bind(this));
return this;
},
function() {
var w = global,
program = require('commander'),
fs = require('fs');
w.include.promise('io').File = Class({
Construct: function(path, data) {
this.uri = new net.URI(path);
copySync: function(files){
for(var i = 0, x, length = files.length; x = files[i], i<length; i++){
if (this.__proto__ == io.File.prototype){
var handler = io.fileFactory.resolveHandler(this.uri);
if (handler) return new handler(this.uri, data);
}
return this;
},
read: function() {
return app.service('io', 'file/readSync', {
file: this.uri.toLocalFile()
});
},
write: function(content) {
return app.service('io', 'file/save', {
path: this.uri.toLocalFile(),
content: content
});
},
copyTo: function(targetUri) {
w.app.service('io', 'file/copySync', {
from: this.uri.toLocalFile(),
to: targetUri.toLocalFile()
});
},
exists: function() {
return w.app.service('io', 'file/exists', {
file: this.uri.toLocalFile()
});
}
});
w.include.promise('io').fileFactory = new(Class({
handlers: [],
registerHandler: function(regexp,handler){
this.handlers.push({
handler: handler,
regexp: regexp
});
},
resolveHandler: function(uri){
var str = uri.toString();
var handler = ruqq.arr.first(this.handlers, function(item){
var isarray = item.regexp instanceof Array,
length = isarray ? item.regexp.length : 1,
x = null;
var from = x.copyFrom.toLocalFile(),
to = x.copyTo.toLocalFile();
console.log("Copy: %s to %s", from, to);
w.app.service('io','file/copySync',{
from: from,
to: to
});
for (var i = 0; x = isarray ? item.regexp[i] : item.regexp, isarray ? i < length : i < 1; i++) {
if (x.test(str)) return true;
}
},
return false;
});
Static: {
copySync: function(fromURI, toURI){
var from = fromURI.toLocalFile(),
to = toURI.toLocalFile();
console.log("Copy: %s to %s", from, to);
w.app.service('io','file/copySync',{
from: from,
to: to
});
return handler && handler.handler || null;
}
}))();
w.include.promise('io').Directory = Class({
Construct: function(directory) {
this.uri = new net.URI(directory);
delete this.uri.file;
},
exists: function(){
return fs.existsSync(this.uri.toLocalDir());
},
ensure: function(){
app.service('io','folder/ensure', {
folder: this.uri.toLocalDir()
});
return this;
},
readFiles: function() {
var files = w.app.service('io', 'file/allSync', {
dir: this.uri.toLocalDir()
});
this.files = ruqq.arr.map(files, function(x) {
return new w.io.File(this.uri.combine(x));
}.bind(this));
return this;
},
copyTo: function(targetUri, options, index, idfr) {
if (this.files instanceof Array === false) return this;
for (var i = index || 0, x, length = this.files.length; x = this.files[i], i < length; i++) {
var relative = x.uri.toRelativeString(this.uri),
file = new io.File(this.uri.combine(relative));
if (options && options.indexOf('-v') == -1 && file.exists()) {
program.prompt(String.format('File already exists: #{file}. Replace(y/n)? ', {
file: file.uri.toLocalFile()
}), this.copy.bind(this, targetUri, options, i, idfr));
return this;
}
x.copyTo(targetUri.combine(relative));
}
})
}
idfr && idfr.resolve && idfr.resolve();
return this;
},
getName: function(){
return this.uri.path.replace(/^.*\/([^\/]+)\/?$/,'$1');
},
rename: function(name){
if (!name) {
console.error('New Name is not defined');
return;
}
var oldpath = this.uri.toLocalFile();
var newpath = oldpath.replace(/[^\/]+\/?$/g, name);
console.log('rename', oldpath, newpath);
fs.renameSync(oldpath, newpath);
}
});
}(window);
w.include.promise('io').env = new (Class({
Construct: function(){
var path = process.argv[1].replace(/\\/g,'/');
this.applicationDir = new net.URI(path);
if (this.applicationDir.file == null){
this.applicationDir.path = w.urlhelper.getDir(this.applicationDir.path);
}
this.currentDir = new net.URI(process.cwd());
}
}))
}();
void
function() {
var w = window;
var w = window,
fs = require('fs');

@@ -24,17 +25,3 @@ w.urlhelper = {

return uri.isRelative() ? (new net.URI(parentLocation)).combine(uri) : uri;
//////var _url = '';
//////
//////if (url[0] == '/') {
////// _url = solution.directory + url.substring(1);
//////}
//////else if (url.substring(0, 4) == 'file') {
////// _url = url;
//////} else if (parentLocation != null) {
////// _url = net.URI.combine(parentLocation, url);
//////}
//////
//////return new net.URI(_url);
return uri.isRelative() ? (new net.URI(parentLocation)).combine(uri) : uri;
},

@@ -54,2 +41,20 @@ getDir: function(url) {

w.referenceHelper = {
create: function(solutionDir, name, referenceSource){
var dir = new io.Directory(referenceSource);
if (dir.exists() == false) return console.error('Directory do not exist.');
if (name == null) name = dir.getName();
var targetDir = new io.Directory(solutionDir.combine('.reference/' + name))
if (targetDir.exists()) return console.error('Reference with the name "%s" already exists', name);
new io.Directory(solutionDir.combine('.reference/')).ensure();
fs.symlinkSync(dir.uri.toLocalDir(), targetDir.uri.toLocalDir(), 'dir');
return null;
}
}

@@ -56,0 +61,0 @@ w.xhr = {

@@ -44,3 +44,3 @@ void

w.include.promise('parser').html = {
rewriteUrls: function(resource, rewrites) {
rewriteUrls: function(resource, line1, line2) {
var json = {},

@@ -50,63 +50,68 @@ docHelper = HtmlDocument.helper,

doc.removeAll('script', 'src').removeAll('link', 'rel', 'stylesheet');
for (var i = 0, x, length = resource.includes.length; x = resource.includes[i], i < length; i++) {
var url = x.rewrite || x.url;
switch (x.type) {
case 'css':
doc.appendResource('link', {
href: url,
rel: 'stylesheet'
});
break;
case 'js':
doc.appendResource('script', {
src: url,
type: 'application/javascript'
});
break;
var arr = doc.getElementsByTagName('script');
for (var i = 0, x, length = arr.length; x = arr[i], i < length; i++) {
var src = x.getAttribute('src');
if (src && src.indexOf(line1) > -1) {
x.setAttribute('src', src.replace(line1, line2));
}
}
////////////////doc.removeAll('script', 'src').removeAll('link', 'rel', 'stylesheet');
////////////////
////////////////for (var i = 0, x, length = resource.includes.length; x = resource.includes[i], i < length; i++) {
//////////////// var url = x.rewrite || x.url;
////////////////
//////////////// switch (x.type) {
//////////////// case 'css':
//////////////// doc.appendResource('link', {
//////////////// href: url,
//////////////// rel: 'stylesheet'
//////////////// });
//////////////// break;
//////////////// case 'js':
//////////////// doc.appendResource('script', {
//////////////// src: url,
//////////////// type: 'application/javascript'
//////////////// });
//////////////// break;
//////////////// }
////////////////}
////////////////
////////////////for (var key in rewrites) {
//////////////// var x = rewrites[key];
//////////////// if (!x.path) continue;
////////////////
//////////////// json[x.id] = x.rewrite;
//////////////// helper.rewriteResource(doc, rewrites[key]);
////////////////}
////////////////
////////////////var tag = doc.createTag('script', {
//////////////// type: 'application/javascript',
//////////////// innerHTML: "window.IncludeRewrites = " + JSON.stringify(json)
////////////////}),
//////////////// head = doc.first('head');
////////////////
////////////////head.insertBefore(tag, head.childNodes[0]);
////////////////
////////////////if (solution.loader && solution.loader.config) {
//////////////// var tag = doc.createTag('script', {
//////////////// type: 'application/javascript',
//////////////// innerHTML: "include.cfg(" + JSON.stringify(solution.loader.config) + ");"
//////////////// });
//////////////// var $include = doc.first('script', function(x) {
//////////////// var src = x.getAttribute('src');
//////////////// return src && src.indexOf('include.js') > -1;
//////////////// });
////////////////
//////////////// if (!$include) throw new Error('include.js is not in document, oder was renamed.');
////////////////
//////////////// var $parent = $include.parentNode,
//////////////// fn = $include.nextSibling ? 'insertBefore' : 'appendChild';
////////////////
//////////////// $parent[fn](tag, $include.nextSibling);
////////////////
////////////////}
for (var key in rewrites) {
var x = rewrites[key];
if (!x.path) continue;
json[x.id] = x.rewrite;
helper.rewriteResource(doc, rewrites[key]);
}
var tag = doc.createTag('script', {
type: 'application/javascript',
innerHTML: "window.IncludeRewrites = " + JSON.stringify(json)
}),
head = doc.first('head');
head.insertBefore(tag, head.childNodes[0]);
if (solution.loader && solution.loader.config) {
var tag = doc.createTag('script', {
type: 'application/javascript',
innerHTML: "include.cfg(" + JSON.stringify(solution.loader.config) + ");"
});
var $include = doc.first('script', function(x) {
var src = x.getAttribute('src');
return src && src.indexOf('include.js') > -1;
});
if (!$include) throw new Error('include.js is not in document, oder was renamed.');
var $parent = $include.parentNode,
fn = $include.nextSibling ? 'insertBefore' : 'appendChild';
$parent[fn](tag, $include.nextSibling);
}
resource.source = "<!DOCTYPE html>" + sys.newLine + doc.documentElement.innerHTML;

@@ -113,0 +118,0 @@

@@ -226,3 +226,3 @@ void

}
break;

@@ -295,10 +295,2 @@ case ';':

Parser.include(S, includes);
//////
//////var end = S.index;
//////if (end > start) {
////// js += ';' + S.text.substring(start, end + 1);
//////} else {
////// console.warn('Include is empty');
//////}
}

@@ -305,0 +297,0 @@

@@ -49,12 +49,12 @@ void

},
onload: function(source) {
if (typeof source === 'object' && source.load) source = source.load[0];
if (!source) {
console.error('Page cannt be loaded', this.url);
this.idfr.resolve(this);
load: function(){
var file = new io.File(this.uri);
if (file.exists() == false){
console.log('File Not Exists - ', this.uri.toLocalFile());
return;
}
this.source = source;
this.source = file.read();
switch (this.type) {

@@ -65,3 +65,3 @@ case 'html':

var includes = w.parser[this.type].extractIncludes(source, solution.directory, solution.variables);
var includes = w.parser[this.type].extractIncludes(this.source, solution.directory, solution.variables);

@@ -72,8 +72,6 @@ this.includes = r.arr.map(includes, function(x){

break;
case 'css':
case 'load':
case 'lazy':
this.idfr.resolve(this);
case 'lazy':
return;

@@ -84,20 +82,7 @@ default:

}
this.process();
},
process: function() {
if (this.source == null) {
w.xhr.load(this.uri.toLocalFile(), this.onload.bind(this));
return;
}
if (++this.index > this.includes.length - 1) {
this.idfr.resolve(this);
return;
}
this.includes[this.index].process();
},
resolve: function(resource) {
this.process();
r.arr.invoke(this.includes, 'load');
}
});
}();

@@ -76,5 +76,3 @@ include.js('resource.js').done(function() {

config = w.include.cfg();
for(var key in config){
delete config[key];
}
for(var key in config) delete config[key];
},

@@ -84,59 +82,9 @@

process: function() {
this.resource.process();
//-this.resource.process();
this.resource.load();
this.idfr && this.idfr && this.idfr.resolve(this);
return this;
},
resolve: function(sender) {
if (sender == this.resource) {
if (this.config.action == "import") {
w.action.importer.importResources(this);
return;
}
w.action.builder.combine(this);
if (this.minify) {
var ast = jsp.parse(output.js);
ast = pro.ast_mangle(ast);
//-ast = pro.ast_squeeze(ast);
this.output.js = pro.gen_code(ast);
this.output.css = cssmin(this.output.css);
}
if (this.resource.type == 'html') {
HtmlDocument.createSolutionHtml(this, this.output);
}
this.save();
this.idfr && this.idfr && this.idfr.resolve(this);
}
},
save: function() {
if (this.output.js){
app.service('io', 'file/save', {
content: this.output.js,
path: this.uris.outputDirectory.combine('script.js').toLocalFile()
});
}
if (this.output.css) {
app.service('io', 'file/save', {
content: this.output.css,
path: this.uris.outputDirectory.combine('style.css').toLocalFile()
});
}
if (this.type == 'html') {
app.service('io', 'file/save', {
content: this.output.html,
path: this.uris.outputMain.toLocalFile()
});
}
}
});
});
});

@@ -22,14 +22,11 @@ var fs = require('fs'),

io: {
'file/save': function(data) {
console.log('saving', data.path);
'file/save': function(data) {
var folder = urlhelper.getDir(data.path);
if (folder && fs.existsSync(folder) == false) {
try {
fs.mkdirSync(folder);
} catch (e) {};
//try {
fsextra.mkdirpSync(folder);
//} catch (e) {};
}
fs.writeFile(data.path, data.content);
fs.writeFileSync(data.path, data.content);
},

@@ -47,3 +44,3 @@ 'file/copy': function(data, callback) {

var folder = urlhelper.getDir(data.to);
if (fs.existsSync(folder) == false) fs.mkdirSync(folder);
if (fs.existsSync(folder) == false) fsextra.mkdirpSync(folder);

@@ -57,4 +54,4 @@ fs.copy(data.from, data.to, callback);

}
var folder = urlhelper.getDir(data.to);
if (fs.existsSync(folder) == false) fs.mkdirSync(folder);
var folder = urlhelper.getDir(data.to);
if (fs.existsSync(folder) == false) fsextra.mkdirpSync(folder);

@@ -71,2 +68,5 @@ copyFileSync(data.from, data.to);

return walk(data.dir);
},
'folder/ensure': function(data){
if (fs.existsSync(data.folder) == false) fsextra.mkdirpSync(data.folder);
}

@@ -73,0 +73,0 @@ }

@@ -9,3 +9,3 @@ {

},
"version": "0.3.5",
"version": "0.3.6",
"main": "./include.js",

@@ -12,0 +12,0 @@ "bin": {

@@ -143,3 +143,3 @@ ;

return str + helper.combinePathes(this.host, this.path, this.file) + (this.search || '');
},
},
/**

@@ -157,3 +157,2 @@ * @return Current URI Path{String} that is relative to @arg1 URI

}
/** sub folder */

@@ -186,4 +185,2 @@ var current = this.path.split('/');

}
return this.toString();

@@ -201,6 +198,5 @@ },

toDir: function(){
var str = this.toString(),
index = str.lastIndexOf('/');
return str.substring(0, index + 1);
var str = this.toString();
return this.file ? str.substring(0, str.lastIndexOf('/') + 1) : str;
},

@@ -207,0 +203,0 @@ isRelative: function() {

@@ -35,3 +35,2 @@ void

}

@@ -59,2 +58,40 @@

Object.getProperty = function(o, chain) {
if (typeof o !== 'object' || chain == null) return o;
if (typeof chain === 'string') chain = chain.split('.');
if (chain.length === 1) return o[chain[0]];
return Object.getProperty(o[chain.shift()], chain);
}
Object.observe = function(obj, property, callback) {
if (obj.__observers == null) obj.__observers = {};
if (obj.__observers[property]) {
obj.__observers[property].push(callback);
return;
};
(obj.__observers[property] || (obj.__observers[property] = [])).push(callback);
var chain = property.split('.'),
parent = obj,
key = property;
if (chain.length > 1) {
key = chain.pop();
parent = Object.getProperty(obj, chain);
}
var value = parent[key];
Object.defineProperty(parent, key, {
get: function() {
return value;
},
set: function(x) {
value = x;
for (var i = 0, fn, length = obj.__observers[property].length; fn = obj.__observers[property][i], i < length; i++) {
fn(x);
}
}
})
}
Date.format = function(date, format) {

@@ -78,2 +115,4 @@ if (!format) format = "MM/dd/yyyy";

}
}();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc