Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commonplace

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commonplace - npm Package Compare versions

Comparing version 0.2.7 to 0.2.8

128

lib/build.js

@@ -16,2 +16,3 @@ var fs = require('fs');

'include.css',
'splash.css'
];

@@ -63,55 +64,97 @@

function concatCSS(src_dir, callback) {
var css_pattern = /href="(\/media\/css\/.+\.styl\.css)"/g;
var url_pattern = /url\(([^)]+)\)/g;
var img_urls = [];
var css_dir = path.resolve(src_dir, 'media', 'css');
var imgurls_fn = path.resolve(src_dir, 'media', 'imgurls.txt');
function fix_urls(img_urls, css_dir, src_dir, url_pattern, data) {
var has_origin = false;
function fix_urls(data) {
return data.replace(url_pattern, function(match, url, offset, string) {
url = url.replace(/"|'/g, '');
has_origin = false;
return data.replace(url_pattern, function(match, url, offset, string) {
url = url.replace(/"|'/g, '');
has_origin = false;
if (url.substring(0, 5) === 'data:') {
return 'url(' + url + ')';
}
if (url.substring(0, 5) === 'data:') {
return 'url(' + url + ')';
}
if (url.search(/(https?):|\/\//) === 0) {
// Do not cachebust `https:`, `http:`, and `//` URLs.
if (url.search(/(https?):|\/\//) === 0) {
// Do not cachebust `https:`, `http:`, and `//` URLs.
has_origin = true;
} else {
if (url[0] === '/') {
has_origin = true;
} else {
if (url[0] === '/') {
has_origin = true;
}
}
var timestamp = new Date().getTime();
var timestamp = new Date().getTime();
var chunks = url.split('#');
if (chunks[1]) {
// If there was a hash, move it to the end of the URL
// after the `?timestamp`.
url = chunks[0] + '?' + timestamp + '#' + chunks[1];
} else {
url += '?' + timestamp;
}
var chunks = url.split('#');
if (chunks[1]) {
// If there was a hash, move it to the end of the URL
// after the `?timestamp`.
url = chunks[0] + '?' + timestamp + '#' + chunks[1];
} else {
url += '?' + timestamp;
}
}
if (img_urls.indexOf(url) === -1) {
if (has_origin) {
img_urls.push(url);
} else {
// Filename started with `../` or is a relative path.
var absolute_path = path.join(css_dir, url);
// Record the absolute URL, starting with `/media/`.
img_urls.push('/' + path.relative(src_dir, absolute_path));
}
if (img_urls.indexOf(url) === -1) {
if (has_origin) {
img_urls.push(url);
} else {
// Filename started with `../` or is a relative path.
var absolute_path = path.join(css_dir, url);
// Record the absolute URL, starting with `/media/`.
img_urls.push('/' + path.relative(src_dir, absolute_path));
}
}
return 'url(' + url + ')';
return 'url(' + url + ')';
});
}
function minifyCSS(src_dir, src, callback) {
var css_pattern = new RegExp('href=".+' + src + '"', 'g');
var url_pattern = /url\(([^)]+)\)/g;
var img_urls = [];
var css_dir = path.resolve(src_dir, 'media/css');
var imgurls_fn = path.resolve(src_dir, 'media/imgurls.txt');
var index_html = fs.readFile(path.resolve(src_dir, 'index.html'), function(err, data) {
if (err) {
console.error('Could not read `index.html`.', err);
return;
}
var match;
var files = [];
data = data.toString();
while (match = css_pattern.exec(data)) {
files.push(path.resolve(src_dir + match[1]));
}
var output = '';
compileStylus(path.resolve(src_dir, src).replace('.styl.css', '.styl'), function(err, data) {
if (err) {
console.warn(err);
} else {
output = fix_urls(img_urls, css_dir, src_dir, url_pattern, data + '\n');
}
fs.appendFile(imgurls_fn, img_urls.join('\n') + '\n', function(err) {
if (err) {
console.error('Error writing `imgurls.txt` to disk.');
return;
}
console.log('Created ' + imgurls_fn);
});
callback(output);
});
}
});
}
function concatCSS(src_dir, callback) {
var css_pattern = /href="(\/media\/css\/.+\.styl\.css)"/g;
var url_pattern = /url\(([^)]+)\)/g;
var img_urls = [];
var css_dir = path.resolve(src_dir, 'media/css');
var imgurls_fn = path.resolve(src_dir, 'media/imgurls.txt');
var has_origin = false;
var index_html = fs.readFile(path.resolve(src_dir, 'index.html'), function(err, data) {

@@ -139,3 +182,3 @@ if (err) {

} else {
output[index] = fix_urls(data + '\n');
output[index] = fix_urls(img_urls, css_dir, src_dir, url_pattern, data + '\n');
}

@@ -146,3 +189,3 @@ remaining--;

if (err) {
console.error('Error writing `cssurls.txt` to disk.');
console.error('Error writing `imgurls.txt` to disk.');
return;

@@ -216,2 +259,3 @@ }

module.exports.css = concatCSS;
module.exports.cssMinify = minifyCSS;
module.exports.html = compileHTML;

@@ -291,2 +291,3 @@ var child_process = require('child_process');

'media/imgurls.txt',
'media/css/splash.css',
'media/css/include.css',

@@ -573,5 +574,7 @@ 'media/js/include.js',

var cleancss = (new (require('clean-css')));
build.css(src_dir, function(data) {
if (!raw) {
data = (new (require('clean-css'))).minify(data);
data = cleancss.minify(data);
}

@@ -589,3 +592,25 @@ var include_css = path.resolve(src_dir, 'media', 'css', 'include.css');

completed();
// The stylesheet used for the splash screen needs to happen after the
// other files have been processed (because of the `imgurls.txt` file).
console.log( path.resolve(src_dir, 'media', 'css', 'splash.styl') )
fs.exists(path.resolve(src_dir, 'media', 'css', 'splash.styl'), function (exists) {
if (!exists) {
return completed();
}
build.cssMinify(src_dir, 'media/css/splash.styl.css', function(data) {
if (!raw) {
data = cleancss.minify(data);
}
var splash_css = path.resolve(src_dir, 'media', 'css', 'splash.css');
fs.writeFile(splash_css, data, function(err) {
if (err) {
console.error('Error writing `splash.css` to disk.');
return;
}
console.log('Created ' + splash_css);
completed();
});
});
});
}

@@ -592,0 +617,0 @@

{
"name": "commonplace",
"version": "0.2.7",
"version": "0.2.8",
"preferGlobal": true,

@@ -5,0 +5,0 @@ "repository": {

@@ -111,2 +111,5 @@ define('helpers',

get_permission: user.get_permission,
has_developed: user.has_developed,
has_installed: user.has_installed,
has_purchased: user.has_purchased,
logged_in: user.logged_in

@@ -119,2 +122,4 @@ };

apiParams: require('urls').api.params,
anonApi: require('urls').api.unsigned.url,
anonApiParams: require('urls').api.unsigned.params,
url: require('urls').reverse,

@@ -121,0 +126,0 @@ media: require('urls').media,

@@ -102,2 +102,3 @@ define('login',

user.update_permissions(data.permissions);
user.update_apps(data.apps);
console.log('Login succeeded, preparing the app');

@@ -104,0 +105,0 @@

@@ -5,3 +5,3 @@ define('urls',

var group_pattern = /\(.+\)/;
var group_pattern = /\([^\)]+\)/;
var optional_pattern = /(\(.*\)|\[.*\]|.)\?/g;

@@ -47,8 +47,3 @@ var reverse = function(view_name, args) {

}
var blacklist = settings.api_param_blacklist || [];
for (var key in args) {
if (!args[key] || blacklist.indexOf(key) !== -1) {
delete args[key];
}
}
_removeBlacklistedParams(args);
return require('utils').urlparams(out, args);

@@ -58,2 +53,20 @@ };

function _anonymousArgs(func) {
return function() {
var out = func.apply(this, arguments);
var args = api_args();
_removeBlacklistedParams(args);
return require('utils').urlparams(out, args);
};
}
function _removeBlacklistedParams(args) {
var blacklist = settings.api_param_blacklist || [];
for (var key in args) {
if (!args[key] || blacklist.indexOf(key) !== -1) {
delete args[key];
}
}
}
function api(endpoint, args, params) {

@@ -92,3 +105,8 @@ if (!(endpoint in api_endpoints)) {

sign: _userArgs(function(url) {return url;}),
unsign: _anonymousArgs(function(url) {return url;}),
unsigned: {
url: _anonymousArgs(api),
params: _anonymousArgs(apiParams)
},
base: {
url: api,

@@ -95,0 +113,0 @@ params: apiParams

@@ -10,2 +10,7 @@ define('user',

var permissions = {};
var apps = {
'installed': [],
'purchased': [],
'developed': []
};

@@ -19,2 +24,6 @@ var save_to_ls = !capabilities.phantom;

permissions = JSON.parse(storage.getItem('permissions') || '{}');
var _stored = storage.getItem('user_apps');
if (_stored) {
apps = JSON.parse(_stored);
}
}

@@ -39,2 +48,8 @@

save_permissions();
apps = {
'installed': [],
'purchased': [],
'developed': []
};
save_apps();
}

@@ -56,2 +71,18 @@ token = null;

function get_apps() {
return apps;
}
function has_developed(app_id) {
return apps.developed.indexOf(app_id) !== -1;
}
function has_installed(app_id) {
return apps.installed.indexOf(app_id) !== -1;
}
function has_purchased(app_id) {
return apps.purchased.indexOf(app_id) !== -1;
}
function set_token(new_token, new_settings) {

@@ -112,14 +143,51 @@ console.log('Setting new user token');

function update_apps(data) {
if (!data) {
return;
}
console.log('Updating user apps', data);
apps = data;
save_apps();
}
function update_install(app_id) {
console.log('Adding to user apps.installed', app_id);
apps.installed.push(app_id);
save_apps();
}
function update_purchased(app_id) {
console.log('Adding to user apps.purchased', app_id);
apps.purchased.push(app_id);
save_apps();
}
function save_apps() {
if (save_to_ls) {
console.log('Saving user apps to localStorage');
storage.setItem('user_apps', JSON.stringify(apps));
} else {
console.log('User apps not saved to localStorage');
}
}
return {
clear_settings: clear_settings,
clear_token: clear_token,
get_apps: get_apps,
get_permission: get_permission,
get_setting: get_setting,
get_permission: get_permission,
get_settings: get_settings,
get_token: function() {return token;},
has_developed: has_developed,
has_installed: has_installed,
has_purchased: has_purchased,
logged_in: function() {return !!token;},
set_token: set_token,
update_apps: update_apps,
update_install: update_install,
update_permissions: update_permissions,
update_purchased: update_purchased,
update_settings: update_settings,
update_permissions: update_permissions
};
});

@@ -64,2 +64,12 @@ (function() {

test('reverse multiple args', function(done, fail) {
mock_routes([
{pattern: '^/apps/([0-9]+)/reviews/([0-9]+)$', view_name: 'two_args'},
], function() {
var reversed = urls.reverse('two_args', [10, 20]);
eq_('/apps/10/reviews/20', reversed);
done();
}, fail);
});
test('api url', function(done, fail) {

@@ -90,9 +100,21 @@ mock(

routes_api_args: function() {return function() {return function() {return {foo: 'bar'};};};}, // Functions get pre-evaluated.
settings: {api_url: 'api:'}
settings: {api_url: 'api:'},
user: {
logged_in: function() { return true; },
get_setting: function(x) {},
get_token: function() { return 'mytoken';}
}
}, function(urls) {
var homepage_url = urls.api.unsigned.url('homepage');
var homepage_url, homepage_base_url = urls.api.base.url('homepage');
homepage_url = homepage_base_url;
eq_(homepage_url, 'api:/foo/homepage');
eq_(urls.api.sign(homepage_url), urls.api.url('homepage'));
disincludes(homepage_url, 'foo=bar');
contains(urls.api.sign(homepage_url), 'foo=bar');
homepage_url = urls.api.url('homepage');
eq_(homepage_url, urls.api.sign(homepage_base_url));
contains(homepage_url, '_user=mytoken');
homepage_url = urls.api.unsigned.url('homepage');
eq_(homepage_url, urls.api.unsign(homepage_base_url));
disincludes(homepage_url, '_user=mytoken');
done();

@@ -99,0 +121,0 @@ },

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