Skip to content

Commit

Permalink
works and works with debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
JesterXL committed Oct 14, 2019
1 parent 7d5e38e commit f610e39
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
17 changes: 17 additions & 0 deletions bin/elm-library-installer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node
const log = console.log
const program = require('commander')
const { isBoolean } = require('lodash/fp')
const { installAllElm19Dependencies } = require('../src')

program
.version(require('../package.json').version, '-v, --version')
.description('Installs Elm libraries within corporate networks.')
.option('-i, --install', 'Reads your elm.json and installs all libraries to .elm in your user directory.')
.option('-v, --verbose', 'Shows debug information.')
.parse(process.argv)

if(program.install) {
installAllElm19Dependencies(program.verbose)
.catch(log)
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"commander": "^3.0.2",
"debug": "^4.1.1",
"lodash": "^4.17.15",
"request": "^2.88.0",
"request-promise": "^4.2.4"
},
"bin": {
"elm-library-installer": "./bin/elm-library-installer.js"
}
}
66 changes: 46 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const request = require('request-promise')
const { exec } = require('child_process')
const fs = require('fs')
const { getOr, get, map, toPairs, isString, isNil } = require('lodash/fp')
const debug = require('debug')('elm-library-installer')

const tap = label => (...args) =>
debug(`${label} %O`, args) ||
Promise.resolve.apply(Promise, args)

const getElmVersion = () =>
new Promise((success, failure) =>
Expand Down Expand Up @@ -79,11 +84,13 @@ const parseJSON = string => {

const downloadElmDependenciesToZIPFiles = targetPath => dependencies =>
makePathIfItDoesNotExist(targetPath)
.then(tap(`makePathIfItDoesNotExist: ${targetPath}`))
.then(
() =>
Promise.all(
map(
dependency =>
debug("dependency.url:", dependency.url) ||
request({
uri: dependency.url,
encoding: null
Expand All @@ -98,6 +105,7 @@ const downloadElmDependenciesToZIPFiles = targetPath => dependencies =>
binaries.map(
(value, index) => {
const dep = dependencies[index]
debug("makePathIfItDoesNotExist:", `${targetPath}/${dep.packagePath}`)
return makePathIfItDoesNotExist(`${targetPath}/${dep.packagePath}`)
}
)
Expand All @@ -108,6 +116,7 @@ const downloadElmDependenciesToZIPFiles = targetPath => dependencies =>
binaries.map(
(value, index) => {
const dep = dependencies[index]
debug("writeFile:", `${targetPath}/${dep.packagePath}/${dep.dependencyName}.zip`)
return writeFile(`${targetPath}/${dep.packagePath}/${dep.dependencyName}.zip`)(value)
}
)
Expand Down Expand Up @@ -190,7 +199,7 @@ const getElm19PackagePath = () =>
// [jwarden 10.13.2019] NOTE/WARNING/FIXME/TODO: This is Mac only.
const unzipAndDelete = path => zipFileName =>
new Promise((success, failure) =>
exec(`unzip ${path}/${zipFileName} -d ${path} && rm -f ${path}/${zipFileName}`, (error, stdout, stderr) =>
exec(`unzip -o ${path}/${zipFileName} -d ${path} && rm -f ${path}/${zipFileName}`, (error, stdout, stderr) =>
error
? failure(error)
: success(stdout.trim())
Expand Down Expand Up @@ -237,24 +246,41 @@ const getDirectories = source =>
)
)

getElm19PackagePath()
.then(
home =>
getElmDependencies('elm.json')
.then(downloadElmDependenciesToZIPFiles(home))
.then(
result => log("result:", result) || result
)
.then(
paths =>
Promise.all(
map(
({path, zipFileName }) =>
unzipAndDelete(path)(zipFileName),
paths
const installAllElm19Dependencies = verboseDebugging =>
require('debug').enable('elm-library-installer', verboseDebugging) ||
getElm19PackagePath()
.then(tap('getElm19PackagePath'))
.then(
home =>
getElmDependencies('elm.json')
.then(tap('getElmDependencies'))
.then(downloadElmDependenciesToZIPFiles(home))
// .then(
// result => log("result:", result) || result
// )
.then(
paths =>
Promise.all(
map(
({path, zipFileName }) =>
unzipAndDelete(path)(zipFileName),
paths
)
)
)
)
)
.then(
() =>
map(
get('path'),
paths
)
)
.then(
paths =>
verboseDebugging
? debug("paths: %O", paths)
: paths
)
)
)

module.exports = { installAllElm19Dependencies }
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

commander@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e"
integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==

core-util-is@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand All @@ -75,6 +80,13 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
dependencies:
ms "^2.1.1"

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
Expand Down Expand Up @@ -213,6 +225,11 @@ mime-types@^2.1.12, mime-types@~2.1.19:
dependencies:
mime-db "1.40.0"

ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

oauth-sign@~0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
Expand Down

0 comments on commit f610e39

Please sign in to comment.