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

assets-manager

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assets-manager - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

dist/replace.js

105

dist/file.js

@@ -21,2 +21,6 @@ 'use strict';

var _replace2 = require('./replace');
var _replace3 = _interopRequireDefault(_replace2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -46,2 +50,28 @@

}, {
key: 'exists',
value: function exists(filename, options) {
try {
return _fsExtra2.default.statSync(this.locate(filename, options)).isFile();
} catch (e) {
if (e.code === 'ENOENT') {
return false;
}
throw e;
}
}
}, {
key: 'isDirectory',
value: function isDirectory(directory, options) {
try {
return _fsExtra2.default.statSync(this.locate(directory, options)).isDirectory();
} catch (e) {
if (e.code === 'ENOENT') {
return false;
}
throw e;
}
}
}, {
key: 'remove',

@@ -68,2 +98,6 @@ value: function remove(filepath, options) {

options = Object.assign({
encoding: 'utf-8'
}, options);
return new Promise(function (resolve, reject) {

@@ -80,34 +114,42 @@ _fsExtra2.default.readFile(_this2.locate(filename, options), function (err, content) {

}, {
key: 'exists',
value: function exists(filename, options) {
try {
return _fsExtra2.default.statSync(this.locate(filename, options)).isFile();
} catch (e) {
if (e.code === 'ENOENT') {
return false;
}
key: 'copy',
value: function copy(src, dest, options) {
var _this3 = this;
throw e;
}
return new Promise(function (resolve, reject) {
_fsExtra2.default.copy(_this3.locate(src, options), _this3.locate(dest, options), options || {}, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
}, {
key: 'isDirectory',
value: function isDirectory(directory, options) {
try {
return _fsExtra2.default.statSync(this.locate(directory, options)).isDirectory();
} catch (e) {
if (e.code === 'ENOENT') {
return false;
}
key: 'replace',
value: function replace(src, dest, rules, options) {
var _this4 = this;
throw e;
}
options = Object.assign({
encoding: 'utf-8'
}, options);
return this.read(src, options).then(function (content) {
content = (0, _replace3.default)(content.toString(options.encoding), rules);
return _this4.write(dest, content, options);
});
}
}, {
key: 'copy',
value: function copy(src, dest, options) {
var _this3 = this;
key: 'write',
value: function write(src, content, options) {
var _this5 = this;
options = Object.assign({
encoding: 'utf-8'
}, options);
return new Promise(function (resolve, reject) {
_fsExtra2.default.copy(_this3.locate(src, options), _this3.locate(dest, options), options || {}, function (err) {
_fsExtra2.default.writeFile(_this5.locate(src, options), content, options || {}, function (err) {
if (err) {

@@ -124,2 +166,6 @@ reject(err);

value: function readJSON(filepath, defaults, options) {
options = Object.assign({
encoding: 'utf-8'
}, options);
filepath = this.locate(filepath, options);

@@ -140,3 +186,3 @@

value: function cleanFiles(files, options) {
var _this4 = this;
var _this6 = this;

@@ -161,3 +207,3 @@ options = Object.assign({

var all = files.map(function (target) {
return _this4.remove(target, opts).then(log(_chalk2.default.red('Removing: ') + target)).catch(function (err) {
return _this6.remove(target, opts).then(log(_chalk2.default.red('Removing: ') + target)).catch(function (err) {
if (options.ignore === false) {

@@ -175,3 +221,3 @@ reject('Cannot clean \'' + target + '\': ' + err.code);

value: function copyFiles(files, options) {
var _this5 = this;
var _this7 = this;

@@ -181,3 +227,4 @@ options = Object.assign({

override: true,
log: console.log
log: console.log,
replaces: {}
}, options);

@@ -201,3 +248,3 @@

var all = files.map(function (target) {
return _this5.copy(target.src, target.dest, opts).then(log(_chalk2.default.green('Copying: ') + target.src + _chalk2.default.cyan(' -> ') + target.dest)).catch(function (err) {
return _this7.copy(target.src, target.dest, opts).then(log(_chalk2.default.green('Copying: ') + target.src + _chalk2.default.cyan(' -> ') + target.dest)).catch(function (err) {
reject('Cannot copy ' + target.src + '\'\' to \'' + target.dest + '\': ' + err.message);

@@ -204,0 +251,0 @@ });

@@ -145,3 +145,3 @@ 'use strict';

var files = [];
var renameRules = Object.assign(this.getConfigure('rename'), pkg.options.rename);
var renameRules = Object.assign(this.getConfigure('renames'), pkg.options.renames);

@@ -202,5 +202,8 @@ var _loop = function _loop(type) {

var pkg = this.getPackage(name);
options = Object.assign({
verbose: this.getConfigure('verbose'),
override: this.getConfigure('override')
override: this.getConfigure('override'),
replaces: Object.assign(this.getConfigure('replaces'), pkg.options.replaces)
}, options);

@@ -308,4 +311,4 @@

this.setConfigure('types', this.data.types, _types2.default);
this.setConfigure('rename', this.data.types, {});
this.setConfigure('replace', this.data.types, {});
this.setConfigure('renames', this.data.renames, {});
this.setConfigure('replaces', this.data.replaces, {});

@@ -312,0 +315,0 @@ var cwd = this.data.cwd;

@@ -61,4 +61,4 @@ 'use strict';

registry: _configure2.default.get('defaultRegistry', 'npm'),
rename: {},
replace: {}
renames: {},
replaces: {}
}, options);

@@ -144,3 +144,3 @@

this.options.rename[_path2.default.basename(defination[type][_file])] = _file;
this.options.renames[_path2.default.basename(defination[type][_file])] = _file;
}

@@ -147,0 +147,0 @@ } else {

@@ -11,13 +11,16 @@ 'use strict';

if (Array.isArray(rules[glob])) {
var regex = rules[glob][0];
var search = rules[glob][0];
var replacement = rules[glob][1];
if (typeof regex === 'string') {
regex = new RegExp(regex);
(0, _assert2.default)(typeof replacement === 'string', 'The second params of ' + glob + ' should be string');
var regex = (0, _toRegExp2.default)(search);
if (regex) {
return filename.replace(regex, replacement);
}
(0, _assert2.default)(regex instanceof RegExp, 'The first params of ' + glob + ' should be regexp');
(0, _assert2.default)(typeof rules[glob][1] === 'string', 'The second params of ' + glob + ' should be string');
return filename.replace(regex, rules[glob][1]);
} else {
return rules[glob];
return filename.split(search).join(replacement);
}
return rules[glob];
}

@@ -37,4 +40,8 @@ }

var _toRegExp = require('./toRegExp');
var _toRegExp2 = _interopRequireDefault(_toRegExp);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports['default'];
{
"name": "assets-manager",
"version": "0.1.2",
"version": "0.1.3",
"description": "Copy packages files based on manifest file",

@@ -71,2 +71,3 @@ "homepage": "https://github.com/amazingSurge/assets-manager",

"dot-prop": "^4.0.0",
"escape-string-regexp": "^1.0.5",
"fs-extra": "^0.30.0",

@@ -73,0 +74,0 @@ "globby": "^6.0.0",

@@ -289,7 +289,9 @@ # assets-manager [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]

#### replace
#### replaces
It will replace the content when copy to target directory. Regex supported.
```js
"replace": {
"replaces": {
"*.css": {
"../fonts": "path-to-fonts"
"../fonts": "path-to-fonts",
"/fa-(\w+)/g": "icon-$1"
}

@@ -299,7 +301,8 @@ }

#### rename
#### renames
It will rename the files when copy to target directory. Regex supported.
```js
"rename": {
"renames": {
"jquery.min.js": "jquery.js",
"*.min.css": [/\.min.css$/, ".css"]
"*.min.css": ["/\.min\.css$/", ".css"]
}

@@ -306,0 +309,0 @@ ```

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