Skip to content

Commit

Permalink
Merge pull request #65 from RallyApps/parent_dir_files
Browse files Browse the repository at this point in the history
Add support for files in parent directories
  • Loading branch information
krmorse committed Jan 16, 2017
2 parents aadbe1d + ae4a83f commit 25f7db6
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 22 deletions.
1 change: 1 addition & 0 deletions bin/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RallyAppBuilder = require("../lib/")

errorHandler = (error) ->
if error
console.error '\r\n' + (error[0] || error)
console.error '\r\nBuild aborted due to error.'
else
console.log 'Success'
Expand Down
22 changes: 15 additions & 7 deletions lib/config.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
_ = require('lodash')
fs = require('fs')
{join} = require('path')
pathUtils = require('path')

configFileName = "config.json"


_updateConfig = (config)->
config.server = config.server || "https://rally1.rallydev.com"
config

saveConfig = ({path, config}, callback)->
configPath = join(path, configFileName)
configPath = pathUtils.join(path, configFileName)
fs.writeFile(configPath, JSON.stringify(config, null, ' '), callback)

getConfig = (path, callback) ->
Expand All @@ -23,13 +22,22 @@ getConfig = (path, callback) ->
else
callback(error)

configPath = join(path, configFileName)
configPath = pathUtils.join(path, configFileName)
if !fs.existsSync(configPath)
throw new Error("#{configFileName} not found at path #{path}")
else
fs.readFile(configPath, "utf-8", convertToJson)



module.exports = {_updateConfig,getConfig,saveConfig}
getAppSourceRoot = (path, callback) ->
getConfig path, (err, config) ->
root = pathUtils.resolve path
localFiles = _.filter config.javascript, (jsFile) -> !jsFile.match /^.*\/\//
dirNames = localFiles.map (appFilePath) ->
pathUtils.dirname pathUtils.resolve pathUtils.join root, appFilePath
common = root
while(!_.every(dirNames, (dir) -> dir.indexOf(common) == 0))
common = pathUtils.resolve common, '..'
callback null, common

module.exports = {_updateConfig,getConfig,saveConfig,getAppSourceRoot}
_.defaults module.exports, {configFileName}
20 changes: 13 additions & 7 deletions lib/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ _ = require 'lodash'
app = express()
path = require 'path'

configModule = require('./config')

module.exports = (args) ->
args = _.defaults args,
port: 1337
app.use express.static process.cwd()
app.listen args.port
url = "http://localhost:#{args.port}/App-debug.html"
console.log "Launching #{url}..."
open(url)
appPath = args.path || process.cwd()
configModule.getAppSourceRoot appPath, (error, srcRoot) ->
pathToApp = path.relative srcRoot, appPath
pathToApp = '/' + pathToApp if pathToApp
args = _.defaults args,
port: 1337
app.use express.static srcRoot
app.listen args.port
url = "http://localhost:#{args.port}#{pathToApp}/App-debug.html"
console.log "Launching #{url}..."
open(url)
11 changes: 7 additions & 4 deletions lib/watch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ chokidar = require('chokidar')
build = require './build'
watcher = null
test = require './test'
config = require './config'

onChange = (args) ->
console.log('Rebuilding...\n');
Expand All @@ -15,9 +16,11 @@ onChange = (args) ->
watch = (args) ->
{templates, ci} = args
console.log('\nWatching for changes...')
watcher = chokidar.watch process.cwd(), { ignored: '**/*.html', usePolling: true, interval: 500 }
watcher.on 'change', (path) ->
console.log('\nChange detected:', path);
onChange {templates, ci}
appPath = args.path || process.cwd()
config.getAppSourceRoot appPath, (error, srcRoot) ->
watcher = chokidar.watch srcRoot, { ignored: '**/*.html', usePolling: true, interval: 500 }
watcher.on 'change', (path) ->
console.log('\nChange detected:', path);
onChange {templates, ci}

module.exports = watch
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Kyle Morse <[email protected]>",
"name": "rally-app-builder",
"description": "A node module that assists in the building of Rally Apps",
"version": "1.3.5",
"version": "1.4.1",
"homepage": "https://github.com/rallyapps/rally-app-builder",
"repository": {
"type": "git",
Expand Down
17 changes: 15 additions & 2 deletions test/config.test.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
assert = require 'assert'
config = require '../lib/config'
path = require 'path'

describe('Config', ()->
describe 'Config', ()->
describe('Updates Config', ()->
testConfig = {
"name": "CardboardCustomCard",
Expand All @@ -27,4 +28,16 @@ describe('Config', ()->
assert(updatedConfig.server == "https://rally1.rallydev.com")
)

)
describe '#getAppSourceRoot', () ->

it 'handles basic case', (done) ->
sdk2TestDirectory = path.join(__dirname, 'fixtures', 'sdk2')
config.getAppSourceRoot sdk2TestDirectory, (err, srcRoot) ->
assert srcRoot == sdk2TestDirectory
done()

it 'handles complicated case', (done) ->
sd2WithParentFiles = path.join(__dirname, 'fixtures', 'sdk2WithParentPaths', 'b', 'c')
config.getAppSourceRoot sd2WithParentFiles, (err, srcRoot) ->
assert srcRoot == path.resolve path.join __dirname, 'fixtures', 'sdk2WithParentPaths'
done()
2 changes: 1 addition & 1 deletion test/fixtures/sdk2/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"ferentchak/teamboard",
"rallyapps/ninjas"
]
}
}
2 changes: 2 additions & 0 deletions test/fixtures/sdk2WithParentPaths/a/File1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ext.define('File1', {});

2 changes: 2 additions & 0 deletions test/fixtures/sdk2WithParentPaths/b/File2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ext.define('File2', {});

9 changes: 9 additions & 0 deletions test/fixtures/sdk2WithParentPaths/b/c/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
//Write app code here

//API Docs: https://help.rallydev.com/apps/2.1/doc/
}
});
3 changes: 3 additions & 0 deletions test/fixtures/sdk2WithParentPaths/b/c/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.app {
/* Add app styles here */
}
15 changes: 15 additions & 0 deletions test/fixtures/sdk2WithParentPaths/b/c/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Test",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "2.1",
"javascript": [
"App.js",
"../File2.js",
"../../a/File1.js",
"https://code.jquery.com/jquery-3.1.1.min.js"
],
"css": [
"app.css"
]
}

0 comments on commit 25f7db6

Please sign in to comment.