Skip to content
This repository was archived by the owner on Apr 26, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions npm/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const PATTERN_NAME = new RegExp("^[a-zA-Z0-9_-]+$");
const PATTERN_ARTIFACT_ID = new RegExp("^[a-zA-Z0-9-_.]*$");
const CONFIG_FILE = "config.js";

const logId = require('../package.json').name + " : config";

Config.prototype.isValid = function () {
let value = this.appName;
if (!value || !PATTERN_NAME.test(value) || (value.length > 50)) return false;
Expand Down Expand Up @@ -159,7 +161,6 @@ function Config(defaults) {
this.processProject = function (paths) {
for (let i = 0; i < paths.length; i++) {
let file = fspath.resolve(paths[i], CONFIG_FILE);
logger.writeToLog('Processing config file ' + file + ' with config', this);
if (fs.existsSync(file)) {
this.configFiles.push(file);
}
Expand Down Expand Up @@ -187,8 +188,8 @@ function Config(defaults) {
}
}
} catch (err) {
console.error('Error reading ' + this.configFiles[i] + ' : ' + err);
console.error('code : ' + output);
logger.writeToLog(`${logId} : Error reading ` + this.configFiles[i] + ' : ' + err);
logger.writeToLog(`${logId} : code : ` + output);
throw err;
}
}
Expand Down
7 changes: 3 additions & 4 deletions npm/lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const extend = require('extend');
const Config = require("./config");
const Handlebars = require('./helpers').handlebars;

const logId = require('../package.json').name + " : context";

function Context(id, config) {
this.id = id;
Expand Down Expand Up @@ -54,17 +55,15 @@ function Context(id, config) {
if(!this.paths.length) {
return; //not being written by us
}
this.logger.writeToLog("Destination path", generator.destinationRoot());
this.logger.writeToLog("Processor", this.processor);
this.logger.writeToLog(`${logId} : Destination path`, generator.destinationRoot());
return this.processor.scan(this.conf, (relativePath, template) => {
let outFile = generator.destinationPath(relativePath);
this.logger.writeToLog("CB : writing to", outFile);
try {
let compiledTemplate = Handlebars.compile(template);
let output = compiledTemplate(this.conf);
generator.fs.write(outFile, output);
} catch (err) {
this.logger.writeToLog("Template error : " + relativePath, err.message);
this.logger.writeToLog(`${logId} : Template error : ` + relativePath, err.message);
}
}, this.paths);
}
Expand Down
8 changes: 4 additions & 4 deletions npm/lib/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const fspath = require('path');
const Handlebars = require('./helpers').handlebars;
const logger = require('./log');

const logId = require('../package.json').name + " : control";

//determines if the passed relative path is a control file or not
const CONTROL_FILE = "control.js";
//determines if the passed relative path is a config file or not
Expand Down Expand Up @@ -68,7 +70,6 @@ Control.prototype.processProject = function() {

//it does, so parse it in and run it through Handlebars
let template = fs.readFileSync(file, 'utf8');
logger.writeToLog("Config data for controlBlock " + file, this.config);
let compiledTemplate = Handlebars.compile(template);
let output = compiledTemplate(this.config);
try {
Expand Down Expand Up @@ -96,11 +97,10 @@ Control.prototype.processProject = function() {
}
}
} catch (err) {
console.log("Error : " + this.path + ":" + output);
logger.writeToLog("Control block error : template", template);
logger.writeToLog(`${logId} : Control block error : template`, template);
throw err;
}
logger.writeToLog("Control data", this.controlBlock);
logger.writeToLog(`${logId} : Control data`, this.controlBlock);
}

//controls whether or not a file should be included in a generation
Expand Down
12 changes: 7 additions & 5 deletions npm/lib/fsprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const fspath = require('path');
const Control = require('./control');
const logger = require('./log');

const logId = require('../package.json').name + " : fsprocessor";

let id = 0;

//recursively walk the file tree starting from the specified root
Expand All @@ -33,7 +35,7 @@ const dirwalk = function (root, tracker, resolver) {
if (err) {
//TODO : appscan for Java does not like you putting too much info in the error messages, need to check for JS
console.error("There was an error reading the template directory");
logger.writeToLog("Folder error", err);
logger.writeToLog(`${logId} : Folder error`, err);
resolver.reject(err);
return;
}
Expand All @@ -51,7 +53,7 @@ const dirwalk = function (root, tracker, resolver) {
//console.log("Found file " + file + " : " + relativePath);
if (err) {
console.error("Error reading file ");
logger.writeToLog("File error", err);
logger.writeToLog(`${logId} : File error`, err);
resolver.reject(err);
return;
}
Expand Down Expand Up @@ -139,12 +141,12 @@ const startWalk = function (config, cb, paths) {
const getContentsSync = function (value) {
let file = fspath.resolve(value);
if (!fs.existsSync(file)) {
logger.writeToLog("Error : specified file does not exist", file);
logger.writeToLog(`${logId} : Error : specified file does not exist`, file);
throw "Error : specified file does not exist";
}
let stats = fs.statSync(file);
if (stats.isDirectory()) {
logger.writeToLog("Error : specified path is a directory", file);
logger.writeToLog(`${logId} : Error : specified path is a directory`, file);
throw "Error : specified path is a directory";
}
try {
Expand All @@ -157,7 +159,7 @@ const getContentsSync = function (value) {
}
} catch (err) {
/* istanbul ignore next */ //file error reading checked in other tests
logger.writeToLog("Error : reading : " + file, err);
logger.writeToLog(`${logId} : Error : reading : ` + file, err);
/* istanbul ignore next */
throw err;
}
Expand Down