Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[core] Re-enable parts of the rules code

  • Loading branch information...
commit 0d0998e7973dbd41e1e978a6931b014c03fdf791 1 parent b513f69
@andreyvit andreyvit authored
View
11 node_modules/livereload-core/lib/projects/project-actions.iced
@@ -0,0 +1,11 @@
+CompilationAction = require '../rules/compilation-action'
+
+
+module.exports =
+class Project_Actions
+ schema:
+ availableActions: { type: Array, computed: yes }
+
+ 'compute availableActions': ->
+ for compiler in @session.pluginManager?.allCompilers or []
+ new CompilationAction(compiler)
View
12 node_modules/livereload-core/lib/projects/project.iced
@@ -7,7 +7,6 @@ fsmonitor = require 'fsmonitor'
CompilerOptions = require './compileropts'
FileOptions = require './fileopts'
-CompilationAction = require '../rules/compilation-action'
Run = require '../runs/run'
RuleSet = require '../rules/ruleset'
@@ -80,6 +79,7 @@ class Project extends R.Model
compilableFilesFilter: { computed: yes }
_mixins: [
+ [@, [require('./project-actions')]]
[require('../rules/rule').FileToFileRule, [Rule_Project]]
]
@@ -108,11 +108,7 @@ class Project extends R.Model
@handleChange @vfs, @fullPath, change.addedFiles.concat(change.modifiedFiles)
@tree = @watcher.tree
- # actions =
- # for compiler in @session.pluginManager?.allCompilers or []
- # new CompilationAction(compiler)
- actions = []
- @ruleSet = @universe.create(RuleSet, { actions, project: this })
+ @ruleSet = @universe.create(RuleSet, { project: this })
await @watcher.on 'complete', defer()
debug "Tree scan complete for #{@fullPath}"
@@ -129,6 +125,10 @@ class Project extends R.Model
@session._removeProject(this)
+ 'automatically set ruleSet.availableActions': ->
+ @ruleSet.availableActions = @availableActions
+
+
_hostnameForUrl: (url) ->
try
components = Url.parse(url)
View
25 node_modules/livereload-core/lib/rules/ruleset.iced
@@ -11,9 +11,19 @@ class RuleSet extends R.Model
schema:
project: { type: Object }
rules: { type: Array }
-
- initialize: ({ @actions }) ->
- @rules = @createDefaultRules()
+ availableActions: { type: Array }
+
+ # 'automatically create default rules': ->
+ # for action in @availableActions
+ # if !@rules.some((rule) -> rule.action is action)
+ # if infos = action.createDefaultRules()
+ # modified = no
+ # for info in infos
+ # rule = @createRule(action, info)
+ # @rules.push rule
+ # modified = yes
+ # if modified
+ # @_changed('rules')
setMemento: (memento) ->
@rules =
@@ -31,15 +41,6 @@ class RuleSet extends R.Model
addRule: (action, info) ->
@rules.push @createRule(action, info)
- createDefaultRules: ->
- rules = []
- for action in @actions
- if infos = action.createDefaultRules()
- for info in infos
- rule = @createRule(action, info)
- rules.push rule
- rules
-
_getRuleClassForAction: (action) ->
TypeToRuleClass[action.type] or throw new Error "Invalid 'type' of action #{action.constructor.name}: #{JSON.stringify(action.type)}"
View
8 node_modules/livereload-core/test/ruleset_test.iced
@@ -15,20 +15,20 @@ describe "RuleSet", ->
it "should be creatable", ->
universe = new R.Universe()
- ruleSet = universe.create(RuleSet, actions: [new MockAction()])
+ ruleSet = universe.create(RuleSet, availableActions: [new MockAction()])
deepEqual ruleSet.rules, []
it "should export a memento", ->
universe = new R.Universe()
action = new MockAction()
- ruleSet = universe.create(RuleSet, actions: [action])
+ ruleSet = universe.create(RuleSet, availableActions: [action])
ruleSet.addRule action, { src: '*.less', dst: '*.css' }
deepEqual ruleSet.memento(), [{ action: "mock-A", src: "*.less", dst: "*.css" }]
it "should import a memento", ->
universe = new R.Universe()
action = new MockAction()
- ruleSet = universe.create(RuleSet, actions: [action])
+ ruleSet = universe.create(RuleSet, availableActions: [action])
ruleSet.setMemento [{ action: "mock-A", src: "*.less", dst: "*.css" }]
equal ruleSet.rules.length, 1
equal ruleSet.rules[0].sourceSpec, '*.less'
@@ -38,7 +38,7 @@ describe "RuleSet", ->
universe = new R.Universe()
compiler = { id: 'more', name: 'More', extensions: ['more'], destinationExt: 'css' }
action = new CompilationAction(compiler)
- ruleSet = universe.create(RuleSet, actions: [action])
+ ruleSet = universe.create(RuleSet, availableActions: [action])
equal ruleSet.rules.length, 1
equal ruleSet.rules[0].sourceSpec, '**/*.more'
equal ruleSet.rules[0].destSpec, '**/*.css'
Please sign in to comment.
Something went wrong with that request. Please try again.