-
Notifications
You must be signed in to change notification settings - Fork 33
More yeoman changes #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
367ec0f
09a6ffa
edc4abb
8b93ffa
9d81b26
750d29d
8722483
feb3f5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,15 @@ ComponentDefinition.loadIntoCache = function(cache, componentName, components, c | |
| cb(); | ||
| }); | ||
| } else { | ||
| debug('component configFile does not exist'); | ||
| steps.push(function(cb) { | ||
| var componentData = { | ||
| name: componentName, | ||
| configFile: path.join(componentName, 'config.json') | ||
| }; | ||
| debug('adding to cache component entry [%s]', componentData.configFile); | ||
| ComponentDefinition.addToCache(cache, componentName, componentData); | ||
| cb(); | ||
| }); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to modify the workspace entities, rename That way we won't have to create a dummy
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the only issue that we are generating an empty
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not generating any I also don't like that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's continue the discussion in #66. |
||
| } | ||
|
|
||
| if(componentModels) { | ||
|
|
@@ -147,12 +155,17 @@ ComponentDefinition.saveToFs = function(cache, componentDef, cb) { | |
|
|
||
| var debug = require('debug')('workspace:component:save:' + componentName); | ||
|
|
||
| var configFile = ComponentDefinition.getConfigFile(componentName, componentDef); | ||
| // remove extra data that shouldn't be persisted to the fs | ||
| delete componentDef.configFile; | ||
| configFile.data = componentDef; | ||
| var hasApp = ComponentDefinition.hasApp(componentDef); | ||
|
|
||
| if (hasApp) { | ||
| var configFile = ComponentDefinition.getConfigFile(componentName, componentDef); | ||
| // remove extra data that shouldn't be persisted to the fs | ||
| delete componentDef.configFile; | ||
| delete componentDef.name; | ||
| configFile.data = componentDef; | ||
|
|
||
| filesToSave.push(configFile); | ||
| filesToSave.push(configFile); | ||
| } | ||
|
|
||
| PackageDefinition.allFromCache(cache).forEach(function(package) { | ||
| if(package.componentName === componentName) { | ||
|
|
@@ -165,34 +178,41 @@ ComponentDefinition.saveToFs = function(cache, componentDef, cb) { | |
| } | ||
| }); | ||
|
|
||
| var dataSoureConfig = {}; | ||
| var dataSourcePath = path.join(componentName, 'datasources.json'); | ||
| var cachedDataSources = DataSourceDefinition.allFromCache(cache); | ||
|
|
||
| cachedDataSources.forEach(function(dataSourceDef) { | ||
| if(dataSourceDef.componentName === componentName) { | ||
| dataSourcePath = DataSourceDefinition.getPath(componentName, dataSourceDef); | ||
| dataSoureConfig[dataSourceDef.name] = dataSourceDef; | ||
| delete dataSourceDef.name; | ||
| } | ||
| }); | ||
|
|
||
| filesToSave.push(new ConfigFile({ | ||
| path: dataSourcePath, | ||
| data: dataSoureConfig | ||
| })); | ||
|
|
||
| var cachedComponentModels = ComponentModel.allFromCache(cache); | ||
| var componentModelsPath = path.join(componentName, ComponentModel.settings.defaultConfigFile); | ||
| var componentModelFile = new ConfigFile({path: componentModelsPath}); // models.json | ||
| var componentModelsConfig = componentModelFile.data = {}; | ||
| if (hasApp) { | ||
| var dataSoureConfig = {}; | ||
| var dataSourcePath = path.join(componentName, 'datasources.json'); | ||
| var cachedDataSources = DataSourceDefinition.allFromCache(cache); | ||
|
|
||
| cachedDataSources.forEach(function(dataSourceDef) { | ||
| if (dataSourceDef.componentName === componentName) { | ||
| dataSourcePath = DataSourceDefinition.getPath(componentName, dataSourceDef); | ||
| dataSoureConfig[dataSourceDef.name] = dataSourceDef; | ||
| // remove extra data that shouldn't be persisted to the fs | ||
| delete dataSourceDef.name; | ||
| delete dataSourceDef.componentName; | ||
| } | ||
| }); | ||
|
|
||
| cachedComponentModels.forEach(function(componentModel) { | ||
| componentModelsConfig[componentModel.name] = componentModel; | ||
| delete componentModel.name; | ||
| }); | ||
| filesToSave.push(new ConfigFile({ | ||
| path: dataSourcePath, | ||
| data: dataSoureConfig | ||
| })); | ||
|
|
||
| var cachedComponentModels = ComponentModel.allFromCache(cache); | ||
| var componentModelsPath = path.join(componentName, ComponentModel.settings.defaultConfigFile); | ||
| var componentModelFile = new ConfigFile({path: componentModelsPath}); // models.json | ||
| var componentModelsConfig = componentModelFile.data = {}; | ||
|
|
||
| cachedComponentModels.forEach(function(componentModel) { | ||
| if (componentModel.componentName !== componentName) return; | ||
| componentModelsConfig[componentModel.name] = componentModel; | ||
| // remove extra data that shouldn't be persisted to the fs | ||
| delete componentModel.name; | ||
| delete componentModel.componentName; | ||
| }); | ||
|
|
||
| filesToSave.push(componentModelFile); | ||
| filesToSave.push(componentModelFile); | ||
| } | ||
|
|
||
| var cachedModels = ModelDefinition.allFromCache(cache); | ||
|
|
||
|
|
@@ -216,3 +236,11 @@ ComponentDefinition.saveToFs = function(cache, componentDef, cb) { | |
| cb(); | ||
| }); | ||
| } | ||
|
|
||
| ComponentDefinition.hasApp = function(componentDef) { | ||
| // At the moment, the root component does not have `app.js`, | ||
| // all other components (rest, server) have their app.js | ||
| // In the future, we should read this from component, | ||
| // e.g. package.json > loopback-workspace > app: true|false | ||
| return componentDef.name !== '.'; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,9 @@ ConfigFile.prototype.load = function(cb) { | |
| function load(exists, cb) { | ||
| if(exists) { | ||
| fs.readJson(absolutePath, function(err, data) { | ||
| if (err && err.name === 'SyntaxError') { | ||
| err.message = 'Cannot parse ' + configFile.path + ': ' + err.message; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the error code to ensure it is a parser error. Otherwise the error might be confusing (eg. too many fds open, permissions, ENOENT, etc).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The isn't a good error code for JSON parsing errors AFAICT. Perhaps it is enough to change the message to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a check |
||
| } | ||
| cb(err, err ? undefined : data); | ||
| }); | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| var rest = require('../rest'); | ||
|
|
||
| // enable authentication | ||
| rest.enableAuth(); | ||
| module.exports = function enableAuthentication(rest) { | ||
| // enable authentication | ||
| rest.enableAuth(); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| module.exports = function mountLoopBackExplorer(server) { | ||
| var explorer; | ||
| try { | ||
| explorer = require('loopback-explorer'); | ||
| } catch(err) { | ||
| console.log( | ||
| 'Run `npm install loopback-explorer` to enable the LoopBack explorer' | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| var restApp = require('../../rest'); | ||
| var restApiRoot = server.get('restApiRoot'); | ||
|
|
||
| var explorerApp = explorer(restApp, { basePath: restApiRoot }); | ||
| server.use('/explorer', explorerApp); | ||
| server.once('started', function(baseUrl) { | ||
| // express 4.x (loopback 2.x) uses `mountpath` | ||
| // express 3.x (loopback 1.x) uses `route` | ||
| var explorerPath = explorerApp.mountpath || explorerApp.route; | ||
| console.log('Browse your REST API at %s%s', baseUrl, explorerPath); | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module.exports = function mountRestApi(server) { | ||
| var restApp = require('../../rest'); | ||
| var restApiRoot = server.get('restApiRoot'); | ||
| server.use(restApiRoot, restApp); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats up with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests were complaining about a possible leak when 11 listeners were registered.