deploy: WIP refactor classes -> functional

This commit is contained in:
Brian Mann
2017-06-22 16:27:25 -04:00
parent 60cfee379b
commit 28cd6f927a
4 changed files with 273 additions and 28 deletions
+2 -6
View File
@@ -91,9 +91,7 @@ module.exports = {
}]
}]
deployNewVersion: (version) ->
return Promise.resolve(version) if version
deployNewVersion: ->
fs.readJsonAsync("./package.json")
.then (json) =>
prompt(@getQuestions(json.version))
@@ -130,9 +128,7 @@ module.exports = {
prompt(@getReleases(versions))
.get("release")
whichPlatform: (platform) ->
return Promise.resolve(platform) if platform
whichPlatform: ->
prompt(@getPlatformQuestion())
.get("platform")
+81
View File
@@ -0,0 +1,81 @@
fs = require("fs-extra")
path = require("path")
chalk = require("chalk")
Promise = require("bluebird")
packages = require("./util/packages")
fs = Promise.promisifyAll(fs)
log = (msg, platform) ->
console.log(chalk.yellow(msg), chalk.bgWhite(chalk.black(platform)))
module.exports = (platform, version) ->
distDir = (args...) ->
path.resolve("dist", platform, args...)
cleanupPlatform = ->
log("#cleanupPlatform", platform)
cleanup = =>
fs.removeAsync(distDir())
cleanup()
.catch(cleanup)
buildPackages = ->
log("#buildPackages", platform)
packages.runAllBuild()
copyPackages = ->
log("#copyPackages", platform)
packages.copyAllToDist(distDir())
prunePackages = ->
log("#prunePackages", platform)
packages.pruneAll(distDir("packages", "*"))
createRootPackage = ->
log("#createRootPackage", platform, version)
fs.outputJsonAsync(distDir("package.json"), {
name: "cypress"
productName: "Cypress",
version: version
main: "index.js"
scripts: {}
env: "production"
})
.then =>
str = "require('./packages/server')"
fs.outputFileAsync(distDir("index.js"), str)
symlinkPackages = ->
log("#symlinkPackages", platform)
packages.symlinkAll(distDir)
Promise
.bind(@)
.then(cleanupPlatform)
.then(buildPackages)
.then(copyPackages)
.then(prunePackages)
.then(createRootPackage)
.then(symlinkPackages)
# .then(@convertCoffeeToJs)
# .then(@obfuscate)
# .then(@cleanupSrc)
# .then(@npmInstall)
# .then(@npmInstall)
# .then(@elBuilder)
# .then(@runSmokeTest)
# .then(@runProjectTest)
# .then(@runFailingProjectTest)
# .then(@cleanupCy)
# .then(@codeSign) ## codesign after running smoke tests due to changing .cy
# .then(@verifyAppCanOpen)
# .return(@)
+45 -22
View File
@@ -10,6 +10,7 @@ zip = require("./zip")
ask = require("./ask")
bump = require("./bump")
meta = require("./meta")
build = require("./build")
upload = require("./upload")
Base = require("./base")
Linux = require("./linux")
@@ -21,9 +22,27 @@ success = (str) ->
fail = (str) ->
console.log chalk.bgRed(" " + chalk.black(str) + " ")
## hack for server modifying cwd
## hack for @packages/server modifying cwd
process.chdir(cwd)
askWhichPlatform = (platform) ->
## if we already have a platform
## just resolve with that
if platform
return Promise.resolve(platform)
## else go ask for it!
ask.whichPlatform()
askWhichVersion = (version) ->
## if we already have a version
## just resolve with that
if version
return Promise.resolve(version)
## else go ask for it!
ask.deployNewVersion()
deploy = {
zip: zip
ask: ask
@@ -33,27 +52,27 @@ deploy = {
Darwin: Darwin
Linux: Linux
getPlatform: (platform, options) ->
platform ?= os.platform()
Platform = @[platform.slice(0, 1).toUpperCase() + platform.slice(1)]
throw new Error("Platform: '#{platform}' not found") if not Platform
options ?= @parseOptions(process.argv.slice(2))
(new Platform(platform, options))
# getPlatform: (platform, options) ->
# platform ?= os.platform()
#
# Platform = @[platform.slice(0, 1).toUpperCase() + platform.slice(1)]
#
# throw new Error("Platform: '#{platform}' not found") if not Platform
#
# options ?= @parseOptions(process.argv.slice(2))
#
# (new Platform(platform, options))
parseOptions: (argv) ->
opts = minimist(argv)
opts.runTests = false if opts["skip-tests"]
opts
build: (platform) ->
## read off the argv
options = @parseOptions(process.argv)
@getPlatform(platform?.osName, options).build()
# build: (platform) ->
# ## read off the argv
# options = @parseOptions(process.argv)
#
# @getPlatform(platform?.osName, options).build()
bump: ->
ask.whichBumpTask()
@@ -88,13 +107,17 @@ deploy = {
## read off the argv
options = @parseOptions(process.argv)
ask.whichPlatform(options.platform)
.then (o) =>
ask.deployNewVersion(options.version)
.then (version) =>
options.version = version
askWhichPlatform(options.platform)
.then (platform) ->
askWhichVersion(options.version)
.then (version) ->
# options.version = version
@getPlatform(o, options).deploy()
build(platform, version)
# .return([platform, version])
# .spread (platform, version) ->
# @getPlatform(plat, options).deploy()
# .then (platform) =>
# zip.ditto(platform)
# .then =>
+145
View File
@@ -0,0 +1,145 @@
_ = require("lodash")
fs = require("fs-extra")
cp = require("child_process")
path = require("path")
glob = require("glob")
Promise = require("bluebird")
fs = Promise.promisifyAll(fs)
glob = Promise.promisify(glob)
DEFAULT_PATHS = "node_modules package.json".split(" ")
pathToPackageJson = (pkg) ->
path.join(pkg, "package.json")
runAllBuild = ->
new Promise (resolve, reject) ->
reject = _.once(reject)
## build all the packages except for
## cli and docs
cp.spawn("npm", ["run", "all", "build", "--", "--skip-packages", "cli,docs"], { stdio: "inherit" })
.on "error", reject
.on "exit", (code) ->
if code is 0
resolve()
else
reject(new Error("'npm run build' failed with exit code: #{code}"))
copyAllToDist = (distDir) ->
copyRelativePathToDist = (relative) ->
dest = path.join(distDir, relative)
console.log(relative, "->", dest)
fs.copyAsync(relative, dest)
copyPackage = (pkg) ->
## copies the package to dist
## including the default paths
## and any specified in package.json files
fs.readJsonAsync(pathToPackageJson(pkg))
.then (json) ->
## grab all the files
## and default included paths
## and convert to relative paths
DEFAULT_PATHS
.concat(json.files or [])
.map (file) ->
path.join(pkg, file)
.map(copyRelativePathToDist, {concurrency: 1})
## fs-extra concurrency tests (copyPackage / copyRelativePathToDist)
## 1/1 41688
## 1/5 42218
## 1/10 42566
## 2/1 45041
## 2/2 43589
## 3/3 51399
## cp -R concurrency tests
## 1/1 65811
started = new Date()
fs.ensureDirAsync(distDir)
.then ->
glob("./packages/*")
.map(copyPackage, {concurrency: 1})
.then ->
console.log("Finished Copying", new Date() - started)
.delay(10000)
pruneAll = (pathToPackages) ->
## 1,060,495,784 bytes (1.54 GB on disk) for 179,156 items
## 313,416,512 bytes (376.6 MB on disk) for 23,576 items
retryGlobbing = ->
glob(pathToPackages)
.catch {code: "EMFILE"}, ->
## wait 1 second then retry
Promise
.delay(1000)
.then(retryGlobbing)
prune = (pkg) ->
console.log("pruning", pkg)
new Promise (resolve, reject) ->
reject = _.once(reject)
## ignore node_modules/.bin due to symlinking
cp.spawn("npm", ["prune", "--production", "--ignore", "node_modules/\.bin"], {
cwd: pkg
stdio: "inherit"
})
.on("error", reject)
.on("exit", (code) ->
if code is 0
resolve()
else
reject(new Error("'npm prune --production' on #{pkg} failed with exit code: #{code}"))
)
retryPrune = (pkg) ->
prune(pkg)
.catch {code: "EMFILE"}, ->
Promise
.delay(1000)
.then ->
retryPrune(pkg)
.catch (err) ->
console.log(err, err.code)
throw err
## prunes out all of the devDependencies
## from what was copied
retryGlobbing()
.map(retryPrune, {concurrency: 1})
symlinkAll = (distDir) ->
pathToPackages = path.join('node_modules', '@')
pathToDistPackages = distDir("packages", "*")
symlink = (pkg) ->
# console.log(pkg, dist)
## strip off the initial './'
## ./packages/foo -> node_modules/@packages/foo
dest = path.join(distDir(), "node_modules", "@packages", path.basename(pkg))
fs.ensureSymlinkAsync(pkg, dest)
glob(pathToDistPackages)
.map(symlink)
module.exports = {
runAllBuild
copyAllToDist
pruneAll
symlinkAll
}