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

asset-assistant

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-assistant - npm Package Compare versions

Comparing version 0.0.17 to 0.0.18

9

package.json
{
"name": "asset-assistant",
"version": "0.0.17",
"version": "0.0.18",
"keywords": [

@@ -15,10 +15,7 @@ "util",

"dependencies": {
"fs": "0.0.1-security",
"glob": "^7.1.3",
"rimraf": "^2.6.3",
"yargs": "^12.0.5"
"mkdirp": "^0.5.1"
},
"bin": {
"assets": "src/assets.js",
"clean": "src/clean.js"
"assets": "src/assets.js"
},

@@ -25,0 +22,0 @@ "main": "src/LoadAssets.js",

@@ -1,2 +0,1 @@

const fs = require("fs");
const glob = require('glob');

@@ -9,3 +8,2 @@ const HasLog = require('./HasLog');

this.depth = 0;
this.dry = false;
this.parentPackage = this;

@@ -40,10 +38,2 @@ this.flat = false;

setDry(){
this.dry = true;
}
isDry(){
return this.dry;
}
isTopLevel() {

@@ -50,0 +40,0 @@ return this.depth === 0;

@@ -6,40 +6,44 @@ #!/usr/bin/env node

const InitAssets = require('./InitAssets');
const fs = require("fs");
const rimraf = require("rimraf");
const yargs = require('yargs');
const argv = yargs
.usage("$0 [options]")
.boolean("s")
.boolean("v")
.boolean("d")
.boolean("dry")
.boolean("t")
.default("s", false)
.default("v", false)
.default("d", false)
.default("dry", false)
.default("t", false)
.default("init", false)
.describe("dry", "do not perform task, only console output")
.describe("init", "setup package.json file with default asset settings")
.describe("t", "terminal, set to true to not recurse over modules")
.describe("s", "silent, do not print out to console")
.describe("v", "verbose, print out more information")
.describe("d", "debug, print out even more information")
.argv;
const argv = {
s : false, // silent
v : false, // verbose
d : false, // debug
t : false, // do not recurse over modules
p : "package.json",
init : false, // perform auto setup
field : "assets"
};
if (argv._.length === 0) argv._.push("src");
if (process.argv.length === 2){
console.log("usage: assets [-s] [-v] [-d] [-t] [-p=package_file] [--init] [field_name]");
console.log("--init: setup package.json file with default asset settings");
console.log("-t: terminal, set to true to not recurse over modules");
console.log("-s: silent, do not print out to console");
console.log("-v: verbose, print out more information");
console.log("-d: debug, print out even more information");
console.log("-p: package file, defaults to 'package.json'");
console.log("field_name: field in package.json to get targets, defaults to 'assets'");
}
if (!argv.s) console.log(`Asset Assistant : v0.0.16`);
if (argv.d){
console.log(`-s ${argv.s}`);
console.log(`-v ${argv.v}`);
console.log(`-d ${argv.d}`);
console.log(`-t ${argv.t}`);
console.log(`-dry ${argv.dry}`);
console.log(`-init ${argv.init}`);
console.log(`target: ${argv._}`);
console.log(``);
for (let i = 2; i < process.argv.length; i++){
let arg = process.argv[i];
if (arg.substring(0, 2) === '--'){
let flag = arg.substring(2);
argv[flag] = true;
} else if (arg[0] === '-'){
if (arg.length > 2 && arg[2] === '='){
let value = arg.substring(3);
argv[arg[1]] = value;
} else {
argv[arg[1]] = true;
}
} else {
argv.field = arg;
}
}
if (!argv.s) console.log(`Asset Assistant : v0.0.18`);
if (argv.d) console.log(argv);
if (argv.s) HasLog.setSilent();

@@ -50,3 +54,3 @@ if (argv.v) HasLog.setVerbose();

if (argv.init){
let initAssets = new InitAssets();
let initAssets = new InitAssets(argv.p);
initAssets.run();

@@ -58,6 +62,6 @@ initAssets.write();

if (argv.dry) task.setDry();
task.setFileset(argv._[0]);
task.setFieldName(argv.field);
if (argv.t) task.setTerminal();
task.run("./package.json");
task.run(argv.p, argv.field);
}

@@ -7,2 +7,13 @@ const mkdirp = require("mkdirp");

function catPath(... paths){
let rPath = "";
for (let path of paths){
rPath += path + "/";
}
rPath = rPath.substring(0, rPath.length - 1);
rPath = rPath.replace(/\/+/g, "/");
return rPath;
}
/**

@@ -21,3 +32,3 @@ * An object prepare then perform a file copy.

this.file = file;
this.src = src;
this.src = src;
this.dest = dest;

@@ -67,3 +78,3 @@ }

this.copyList = [];
this.sourceAttribute = "src";
this.settingsFieldName = "assets";
this.terminal = false;

@@ -74,4 +85,9 @@ this.rootPkg = null;

setFileset(sourceAttribute){
this.sourceAttribute = sourceAttribute;
/**
* The the package.json field name that will have the settings.
* @param {string} settingsFieldName
* @returns {undefined}
*/
setFieldName(settingsFieldName){
this.settingsFieldName = settingsFieldName;
}

@@ -100,16 +116,21 @@

run(packagePath, rootPath = "./", parentPath="./", parentUp = 0){
run(packagePath, packageField, parentPath="./",){
this.debugLog(`CopyAssets.run(${packagePath}, ${packageField}, ${parentPath})`);
this.packageField = packageField;
this.rootPkg = this.loadPackage(packagePath);
this.rootAssets = this.rootPkg[CopyAssets.ASSETS];
if (this.rootAssets[CopyAssets.UP] === undefined) this.rootAssets[CopyAssets.UP] = 1;
this.debugLog(`+- Building List (debug) -----------------------------+`);
this.build(packagePath, rootPath, parentPath, parentUp);
this.debugLog(`+- File List (debug) ---------------------------------+`);
if (this.rootPkg[packageField] === undefined){
this.warnLog("Package field '" + packageField + "' not found.");
return;
}
this.rootAssets = this.rootPkg[packageField];
this.build(packagePath, parentPath);
this.debugLog(`+- File List ---------------------------------+`);
this.copyList.forEach(ele=>this.debugLog(`| {file: "${ele.file}", src: "${ele.src}", dest: "${ele.dest}"}`));
if (!this.isDry()){
this.log(`+- Copying Files -------------------------------------+`);
this.copyList.forEach(ele=>ele.doCopy());
}
this.log(`+- Copying Files -------------------------------------+`);
this.copyList.forEach(ele=>ele.doCopy());
}

@@ -122,16 +143,22 @@

* @param {type} parentPath the root path the the parent used.
* @param {type} parentUp
* @returns {undefined}
*/
build(packagePath, rootPath = "./", parentPath="./", parentUp = 0) {
build(packagePath, parentPath) {
let pkg = this.loadPackage(packagePath);
this.traversedList.push(pkg.name);
let assets = pkg[this.packageField];
if (typeof assets !== "object"){
this.verboseLog("| Asset field not found, skipping package: " + pkg.name);
return;
}
let rootPath = catPath(parentPath, assets.root);
this.traversedList.push(pkg.name);
this.verboseLog(`+-----------------------------------------------------+`);
this.verboseLog(`| Traversing package '${pkg.name}' on field '${this.sourceAttribute}'`);
this.verboseLog(`| Traversing package '${pkg.name}' on field '${this.settingsFieldName}'`);
this.debugLog(`| package path : ${packagePath}`);
this.debugLog(`| root path : ${rootPath}`);
this.debugLog(`| parent path : ${parentPath}`);
this.debugLog(`| parent up : ${parentUp}`);
let assets = pkg[CopyAssets.ASSETS];
if (assets === undefined){

@@ -142,5 +169,5 @@ this.debugLog(`| * no assets parameter`);

let source = assets[this.sourceAttribute];
let source = assets[CopyAssets.SRC ];
if (source === undefined){
this.debugLog(`| * no source parameter`);
this.debugLog(`| * no source field: ${CopyAssets.SRC }`);
return;

@@ -150,4 +177,2 @@ }

let dest = this.rootAssets[CopyAssets.DEST];
let pathDepth = this.pathDepth(rootPath);
let up = parentUp + pathDepth;

@@ -158,8 +183,6 @@ if (dest === undefined){

this.debugLog(`| path depth : ${pathDepth}`);
if (source instanceof Array === false) throw new Error(`expected array value for parameter assets.${this.settingsFieldName}`);
if (source instanceof Array === false) throw new Error(`expected array value for parameter assets.${this.sourceAttribute}`);
for (let i in source) this.processSourceArrayElement(source[i], rootPath, dest, up);
if (!this.terminal) this.recurse(packagePath, parentPath, parentUp);
for (let i in source) this.processSourceArrayElement(source[i], rootPath, parentPath, dest);
if (!this.terminal) this.recurse(packagePath, parentPath);
}

@@ -189,3 +212,3 @@

processSourceArrayElement(element, rootPath, dest, up){
processSourceArrayElement(element, rootPath, parentPath, dest){
let sourceGlob = "";

@@ -196,30 +219,13 @@ let flat = false;

this.debugLog(`| - source: element string`);
up = up + this.rootAssets[CopyAssets.UP];
sourceGlob = `${rootPath}/${element}`;
} else if (typeof element === "object"){
this.debugLog(`| - source: element object`);
if (element[CopyAssets.SRC] === undefined){
throw new Error(`Source key undefined in object parameter: ${CopyAssets.SRC}`);
}
sourceGlob = `${rootPath}/${element[CopyAssets.SRC]}`;
flat = true;
if (element[CopyAssets.DEST] !== undefined){
dest = element[CopyAssets.DEST];
this.debugLog(`| dest-raw: ${dest}`);
dest = this.templateLiteral(dest);
this.debugLog(`| dest-processed: ${dest}`);
}
else if (element[CopyAssets.UP] !== undefined){
up = up + element[CopyAssets.UP];
}
sourceGlob = catPath(rootPath, element);
}
let copyArray = this.globToPathArray(sourceGlob, dest, up, flat);
let copyArray = this.globToPathArray(sourceGlob, rootPath, dest, flat);
copyArray.forEach(ele=>this.copyList.push(ele));
}
recurse(packagePath, parentPath, parentUp){
recurse(packagePath, parentPath){
let pkg = this.loadPackage(packagePath);
let dependencies = pkg[CopyAssets.DEPENDENCIES];
for (let dependencyName in dependencies){

@@ -232,8 +238,10 @@ let dependencyValue = dependencies[dependencyName];

this.debugLog(`| * Including unique package file: ${dependencyName}`);
let truePath = `${parentPath}/node_modules/${dependencyName}/`;
this.build(`${truePath}/package.json`, truePath, parentPath, parentUp);
let truePath = catPath(parentPath, "node_modules", dependencyName);
let pkgPath = catPath(truePath, "package.json");
this.build(pkgPath, truePath);
} else {
this.debugLog(`| * Including unique package module: ${dependencyName}`);
let truePath = `${parentPath}/node_modules/${dependencyName}/`;
this.build(`${truePath}/package.json`, truePath, truePath, parentUp);
let truePath = catPath(parentPath, "node_modules", dependencyName);
let pkgPath = catPath(truePath, "package.json");
this.build(pkgPath, truePath);
}

@@ -255,4 +263,4 @@ }

*/
globToPathArray(globpath, dest, up, flat = false) {
this.debugLog(`| - seeking globpaths in: ${globpath}, path up = ${up}`);
globToPathArray(globpath, rootPath, dest) {
this.debugLog(`| - seeking globpaths in: ${globpath}`);
if (globpath.charAt(0) === "/"){

@@ -270,22 +278,12 @@ this.warnLog(`absolute path found in source: ${globpath}`);

this.debugLog(`| - processing ${filename}`);
/* remove the filename from the path */
let pathArray = filename.split("/");
let file = pathArray.pop();
let src = pathArray.join("/") + "/";
let copyObj = new CopyObject(file, src);
copyObj.logger = this;
if (flat) {
copyObj.dest = dest + "/";
} else if (up > 0) {
pathArray = pathArray.slice(up);
if (pathArray.length > 0) {
copyObj.dest = dest + "/" + pathArray.join("/") + "/";
} else {
copyObj.dest = dest + "/";
}
} else {
copyObj.dest = dest + "/" + pathArray.join("/") + "/";
}
copyObj.dest = dest + src.substring(rootPath.length);
array.push(copyObj);
this.debugLog(`| {file : ${copyObj.file}, src : ${copyObj.src}, dest : ${copyObj.dest}}`);
}

@@ -325,3 +323,3 @@

if (!this.isDry() && !fs.existsSync(copyObj.dest)) {
this.verboseLog(`| - creating directory ${copyObj.dest}`)
this.verboseLog(`| - creating directory ${copyObj.dest}`);
mkdirp.sync(copyObj.dest);

@@ -410,4 +408,3 @@ }

this.debugLog(`Running task 'dependencies' with field = ${field}`);
if (this.package.dependencies === undefined)
return;
if (this.package.dependencies === undefined) return;

@@ -449,8 +446,5 @@ for (let pkg in this.package.dependencies) {

CopyAssets.ASSETS = "assets";
CopyAssets.DEST = "dest";
CopyAssets.UP = "up";
CopyAssets.FLAT = "flat";
CopyAssets.DEPENDENCIES = "dependencies";
CopyAssets.SRC = "src";
module.exports = CopyAssets;
const fs = require("fs");
class InitAssets {
constructor() {
let filename = "package.json";
constructor(filename) {
this.filename = filename;
if (!fs.existsSync(filename)) {

@@ -15,8 +15,8 @@ let err = `file not found ${filename}`;

run(source = "src", destination = "public_html"){
this.__addAssets(source, destination);
run(root = "src", destination = "public_html"){
this.__addAssets(root, destination);
this.__addScripts(destination);
}
__addScripts(destination){
__addScripts(){
let scripts = {};

@@ -33,10 +33,10 @@

__addAssets(source, destination){
__addAssets(root, destination){
if (this.package.assets !== undefined) return;
this.assets = {
localsrc: [],
src: [
`${source}/assets/**/*`
`/assets/**/*`
],
root: `${root}`,
dest: destination

@@ -49,3 +49,3 @@ };

write(){
fs.writeFileSync("package.json", JSON.stringify(this.package, null, 4));
fs.writeFileSync(this.filename, JSON.stringify(this.package, null, 4));
}

@@ -52,0 +52,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