Socket
Socket
Sign inDemoInstall

alloy

Package Overview
Dependencies
Maintainers
4
Versions
269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alloy - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

121

Alloy/commands/compile/index.js

@@ -18,2 +18,3 @@ var path = require('path'),

viewRegex = new RegExp('\\.' + CONST.FILE_EXT.VIEW + '$'),
controllerRegex = new RegExp('\\.' + CONST.FILE_EXT.CONTROLLER + '$'),
modelRegex = new RegExp('\\.' + CONST.FILE_EXT.MODEL + '$'),

@@ -109,3 +110,3 @@ compileConfig = {};

// include all necessary widgets
// TODO: include widgets automatically
// TODO: include appropriate widgets automatically

@@ -116,7 +117,16 @@ // Process all views, including all those belonging to widgets

_.each(viewCollection, function(collection) {
// generate runtime controllers from views
_.each(wrench.readdirSyncRecursive(path.join(collection.dir,CONST.DIR.VIEW)), function(view) {
if (viewRegex.test(view)) {
parseView(view, collection.dir, collection.manifest);
parseAlloyComponent(view, collection.dir, collection.manifest);
}
});
// generate runtime controllers from any controller code that has no
// corresponding view markup
_.each(wrench.readdirSyncRecursive(path.join(collection.dir,CONST.DIR.CONTROLLER)), function(controller) {
if (controllerRegex.test(controller)) {
parseAlloyComponent(controller, collection.dir, collection.manifest,true);
}
});
});

@@ -161,10 +171,11 @@

///////////////////////////////////////
function parseView(view,dir,manifest) {
logger.debug('Now parsing view ' + view + '...');
function parseAlloyComponent(view,dir,manifest,noView) {
var parseType = noView ? 'controller' : 'view';
logger.debug('Now parsing ' + parseType + ' ' + view + '...');
// validate parameters
if (!view) { U.die('Undefined view passed to parseView()'); }
if (!dir) { U.die('Failed to parse view "' + view + '", no directory given'); }
if (!view) { U.die('Undefined ' + parseType + ' passed to parseAlloyComponent()'); }
if (!dir) { U.die('Failed to parse ' + parseType + ' "' + view + '", no directory given'); }
var basename = path.basename(view, '.'+CONST.FILE_EXT.VIEW);
var basename = path.basename(view, '.' + CONST.FILE_EXT[parseType.toUpperCase()]);
dirname = path.dirname(view),

@@ -177,2 +188,3 @@ viewName = basename,

},
widgetDir = dirname ? path.join(CONST.DIR.COMPONENT,dirname) : CONST.DIR.COMPONENT,
state = { parent: {} },

@@ -191,53 +203,64 @@ files = {};

// validate view
if (!path.existsSync(files.VIEW)) {
logger.warn('No ' + CONST.FILE_EXT.VIEW + ' view file found for view ' + files.VIEW);
// skip if we've already processed this component
var testExistsFile = manifest ? path.join(compileConfig.dir.resourcesAlloy, CONST.DIR.WIDGET, manifest.id, widgetDir, viewName + '.js') : files.COMPONENT;
if (path.existsSync(testExistsFile) && noView) {
return;
}
// Load the style and update the state
try {
state.styles = CU.loadAndSortStyle(files.STYLE);
} catch (e) {
U.die([
e.stack,
'Error processing style at "' + files.STYLE + '"'
]);
}
// we are processing a view, not just a controller
if (!noView) {
// validate view
if (!path.existsSync(files.VIEW)) {
logger.warn('No ' + CONST.FILE_EXT.VIEW + ' view file found for view ' + files.VIEW);
return;
}
// read and parse the view file
var xml = fs.readFileSync(files.VIEW,'utf8');
var doc = new DOMParser().parseFromString(xml);
var docRoot = doc.documentElement;
// Load the style and update the state
try {
state.styles = CU.loadAndSortStyle(files.STYLE);
} catch (e) {
U.die([
e.stack,
'Error processing style at "' + files.STYLE + '"'
]);
}
// Make sure the markup has a top-level <Alloy> tag
if (docRoot.nodeName !== CONST.ROOT_NODE) {
U.die([
'Invalid view file "' + view + '".',
'All view markup must have a top-level <Alloy> tag'
]);
}
// make sure we have a Window, TabGroup, or SplitWindow
var rootChildren = U.XML.getElementsFromNodes(docRoot.childNodes);
if (viewName === 'index') {
var found = _.find(rootChildren, function(node) {
var ns = node.getAttribute('ns') || CONST.NAMESPACE_DEFAULT;
return node.nodeName === 'Window' ||
node.nodeName === 'SplitWindow' ||
node.nodeName === 'TabGroup';
});
if (!found) {
// read and parse the view file
var xml = fs.readFileSync(files.VIEW,'utf8');
var doc = new DOMParser().parseFromString(xml);
var docRoot = doc.documentElement;
// Make sure the markup has a top-level <Alloy> tag
if (docRoot.nodeName !== CONST.ROOT_NODE) {
U.die([
'Compile failed. index.xml must have a top-level container element.',
'Valid elements: [ Window, TabGroup, SplitWindow]'
'Invalid view file "' + view + '".',
'All view markup must have a top-level <Alloy> tag'
]);
}
// make sure we have a Window, TabGroup, or SplitWindow
var rootChildren = U.XML.getElementsFromNodes(docRoot.childNodes);
if (viewName === 'index') {
var found = _.find(rootChildren, function(node) {
var ns = node.getAttribute('ns') || CONST.NAMESPACE_DEFAULT;
return node.nodeName === 'Window' ||
node.nodeName === 'SplitWindow' ||
node.nodeName === 'TabGroup';
});
if (!found) {
U.die([
'Compile failed. index.xml must have a top-level container element.',
'Valid elements: [ Window, TabGroup, SplitWindow]'
]);
}
}
// Generate each node in the view
_.each(rootChildren, function(node, i) {
var defaultId = i === 0 ? viewName : undefined;
template.viewCode += CU.generateNode(node, state, defaultId, true);
});
}
// Generate each node in the view
_.each(rootChildren, function(node, i) {
var defaultId = i === 0 ? viewName : undefined;
template.viewCode += CU.generateNode(node, state, defaultId, true);
});
// process the controller code
var cCode = CU.loadController(files.CONTROLLER);

@@ -261,3 +284,3 @@ template.parentController = (cCode.parentControllerName != '') ? cCode.parentControllerName : "'BaseController'";

if (manifest) {
var widgetDir = dirname ? path.join(CONST.DIR.COMPONENT,dirname) : CONST.DIR.COMPONENT;
wrench.mkdirSyncRecursive(path.join(compileConfig.dir.resourcesAlloy, CONST.DIR.WIDGET, manifest.id, widgetDir), 0777);

@@ -264,0 +287,0 @@ CU.copyWidgetResources(

@@ -16,3 +16,3 @@ {

],
"version": "0.2.2",
"version": "0.2.3",
"author": "Appcelerator, Inc. <info@appcelerator.com>",

@@ -19,0 +19,0 @@ "maintainers": [

Sorry, the diff of this file is not supported yet

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