2020-05-07 14:52:24 +02:00
|
|
|
const { resolve } = require("path")
|
|
|
|
const { cwd } = require("process")
|
2020-07-14 22:07:53 +02:00
|
|
|
const stream = require("stream")
|
|
|
|
const fetch = require("node-fetch")
|
|
|
|
const tar = require("tar-fs")
|
|
|
|
const zlib = require("zlib")
|
|
|
|
const { promisify } = require("util")
|
|
|
|
const streamPipeline = promisify(stream.pipeline)
|
2020-05-07 14:52:24 +02:00
|
|
|
|
2020-07-14 22:07:53 +02:00
|
|
|
exports.appPackageFolder = (config, appname) =>
|
2020-05-07 14:52:24 +02:00
|
|
|
resolve(cwd(), config.latestPackagesFolder, appname)
|
|
|
|
|
2020-07-14 22:07:53 +02:00
|
|
|
exports.downloadExtractComponentLibraries = async appFolder => {
|
2020-07-14 22:10:51 +02:00
|
|
|
const LIBRARIES = ["materialdesign-components", "standard-components"]
|
2020-07-14 22:07:53 +02:00
|
|
|
|
|
|
|
// Need to download tarballs directly from NPM as our users may not have node on their machine
|
|
|
|
for (let lib of LIBRARIES) {
|
|
|
|
// download tarball
|
|
|
|
// TODO: make sure the latest version is always downloaded
|
2020-07-14 22:10:51 +02:00
|
|
|
const registryUrl = `https://registry.npmjs.org/@budibase/${lib}/-/${lib}-0.1.2.tgz`
|
2020-07-14 22:07:53 +02:00
|
|
|
const response = await fetch(registryUrl)
|
2020-07-14 22:10:51 +02:00
|
|
|
if (!response.ok)
|
|
|
|
throw new Error(`unexpected response ${response.statusText}`)
|
2020-07-14 22:07:53 +02:00
|
|
|
|
|
|
|
await streamPipeline(
|
2020-07-14 22:10:51 +02:00
|
|
|
response.body,
|
2020-07-14 22:07:53 +02:00
|
|
|
zlib.Unzip(),
|
|
|
|
tar.extract(`${appFolder}/node_modules/@budibase/${lib}`)
|
|
|
|
)
|
|
|
|
}
|
2020-07-14 22:10:51 +02:00
|
|
|
}
|