server: save bundles separately per project, close #116

This commit is contained in:
Gleb Bahmutov
2017-06-01 11:28:34 -04:00
parent 98e804990c
commit 437b9b584c
3 changed files with 14 additions and 6 deletions
+4
View File
@@ -6,4 +6,8 @@
# use
# log = require('./log')
# log('working in %s', process.cwd())
# If you need a logger that might be very specific
# you can construct it yourself, just make sure
# to prefix label with "cypress:server:", for example
# log = require('debug')('cypress:server:bundle')
module.exports = require('debug')('cypress:server')
+5 -2
View File
@@ -11,9 +11,10 @@ presetReact = require("babel-preset-react")
presetLatest = require("babel-preset-latest")
stringStream = require("string-to-stream")
pluginAddModuleExports = require("babel-plugin-add-module-exports")
sanitize = require("sanitize-filename")
cjsxify = require("./cjsxify")
appData = require("./app_data")
{ toHashName } = require('./saved_state')
log = require('debug')('cypress:server:bundle')
fs = Promise.promisifyAll(fs)
@@ -25,7 +26,7 @@ module.exports = {
builtFiles = {}
outputPath: (projectName = "", filePath) ->
appData.path("bundles", sanitize(projectName), filePath)
appData.path(toHashName(projectName), "bundles", filePath)
build: (filePath, config) ->
if config.isHeadless and built = builtFiles[filePath]
@@ -59,6 +60,8 @@ module.exports = {
bundle = =>
new Promise (resolve, reject) =>
outputPath = @outputPath(config.projectName, filePath)
log "making bundle to #{outputPath}"
## TODO: only ensure directory when first run and not on updates?
fs.ensureDirAsync(path.dirname(outputPath))
.then =>
+5 -4
View File
@@ -1,11 +1,12 @@
log = require('../log')
fs = require('fs')
path = require('path')
{ basename, join } = require('path')
md5 = require('md5')
sanitize = require("sanitize-filename")
toHashName = (projectPath) ->
throw new Error("Missing project path") unless projectPath
name = path.basename(projectPath)
name = sanitize(basename(projectPath))
hash = md5(projectPath)
"#{name}-#{hash}"
@@ -15,14 +16,14 @@ formStatePath = (projectPath) ->
log('for project path %s', projectPath)
else
log('missing project path, looking for project here')
cypressJsonPath = path.join(process.cwd(), 'cypress.json')
cypressJsonPath = join(process.cwd(), 'cypress.json')
if fs.existsSync(cypressJsonPath)
log('found cypress file %s', cypressJsonPath)
projectPath = process.cwd()
statePath = "state.json"
if projectPath
statePath = path.join(toHashName(projectPath), statePath)
statePath = join(toHashName(projectPath), statePath)
return statePath