lowdefy 3.23.0-alpha.0 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/build/build.js +39 -0
- package/dist/commands/build/getServer.js +42 -0
- package/dist/commands/build/installServer.js +43 -0
- package/dist/commands/build/runLowdefyBuild.js +41 -0
- package/dist/commands/build/runNextBuild.js +36 -0
- package/dist/commands/dev/buildWatcher.js +48 -0
- package/dist/commands/dev/dev.js +80 -0
- package/dist/commands/dev/envWatcher.js +32 -0
- package/dist/commands/dev/getBuild.js +37 -0
- package/dist/commands/dev/getExpress.js +71 -0
- package/dist/commands/dev/getGraphQL.js +39 -0
- package/dist/commands/dev/prepare.js +27 -0
- package/dist/commands/dev/versionWatcher.js +36 -0
- package/dist/commands/init/init.js +42 -0
- package/dist/commands/init/lowdefyFile.js +67 -0
- package/dist/index.js +57 -2
- package/dist/utils/BatchChanges.js +48 -0
- package/dist/utils/checkForUpdatedVersions.js +53 -0
- package/dist/utils/errorHandler.js +50 -0
- package/dist/utils/fetchNpmTarball.js +56 -0
- package/dist/utils/findOpenPort.js +58 -0
- package/dist/utils/getCliJson.js +35 -0
- package/dist/utils/getDirectories.js +30 -0
- package/dist/utils/getLowdefyYaml.js +55 -0
- package/dist/utils/getOptions.js +23 -0
- package/dist/utils/getPackageManager.js +54 -0
- package/dist/utils/getSendTelemetry.js +45 -0
- package/dist/utils/print.js +73 -0
- package/dist/utils/runCommand.js +42 -0
- package/dist/utils/spawnProcess.js +49 -0
- package/dist/utils/startUp.js +48 -0
- package/package.json +21 -43
- package/dist/shell/185.59f79d0f067f50c8b219.js +0 -1
- package/dist/shell/246.b57dcf8b9c7a314f7bb9.js +0 -2
- package/dist/shell/246.b57dcf8b9c7a314f7bb9.js.LICENSE.txt +0 -8
- package/dist/shell/454.a5de9976bd8feff1520a.js +0 -2
- package/dist/shell/454.a5de9976bd8feff1520a.js.LICENSE.txt +0 -14
- package/dist/shell/612.5e25cda0219ebab6ddae.js +0 -1
- package/dist/shell/625.859c7a1f9e198e3ae56f.js +0 -1
- package/dist/shell/706.055a587fb77f64a5299e.js +0 -2
- package/dist/shell/706.055a587fb77f64a5299e.js.LICENSE.txt +0 -8
- package/dist/shell/909.623901103ad312dc3ad4.js +0 -2
- package/dist/shell/909.623901103ad312dc3ad4.js.LICENSE.txt +0 -45
- package/dist/shell/922.8370fab8ada1985a0f4f.js +0 -2
- package/dist/shell/922.8370fab8ada1985a0f4f.js.LICENSE.txt +0 -14
- package/dist/shell/index.html +0 -58
- package/dist/shell/main.a0212229781d28e55f9b.js +0 -1
- package/dist/shell/public/apple-touch-icon.png +0 -0
- package/dist/shell/public/icon-32.png +0 -0
- package/dist/shell/public/icon-512.png +0 -0
- package/dist/shell/public/icon.svg +0 -17
- package/dist/shell/public/logo-dark-theme.png +0 -0
- package/dist/shell/public/logo-light-theme.png +0 -0
- package/dist/shell/public/logo-square-dark-theme.png +0 -0
- package/dist/shell/public/logo-square-light-theme.png +0 -0
- package/dist/shell/public/manifest.webmanifest +0 -16
- package/dist/shell/runtime.73a008a77ccc03d87d76.js +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ export default (({ version })=>`
|
|
16
|
+
lowdefy: ${version}
|
|
17
|
+
name: Lowdefy starter
|
|
18
|
+
|
|
19
|
+
pages:
|
|
20
|
+
- id: welcome
|
|
21
|
+
type: PageHeaderMenu
|
|
22
|
+
properties:
|
|
23
|
+
title: Welcome
|
|
24
|
+
areas:
|
|
25
|
+
content:
|
|
26
|
+
justify: center
|
|
27
|
+
blocks:
|
|
28
|
+
- id: content_card
|
|
29
|
+
type: Card
|
|
30
|
+
style:
|
|
31
|
+
maxWidth: 800
|
|
32
|
+
blocks:
|
|
33
|
+
- id: content
|
|
34
|
+
type: Result
|
|
35
|
+
properties:
|
|
36
|
+
title: Welcome to your Lowdefy app
|
|
37
|
+
subTitle: We are excited to see what you are going to build
|
|
38
|
+
icon:
|
|
39
|
+
name: HeartTwoTone
|
|
40
|
+
color: '#f00'
|
|
41
|
+
areas:
|
|
42
|
+
extra:
|
|
43
|
+
blocks:
|
|
44
|
+
- id: docs_button
|
|
45
|
+
type: Button
|
|
46
|
+
properties:
|
|
47
|
+
size: large
|
|
48
|
+
title: Let's build something
|
|
49
|
+
color: '#1890ff'
|
|
50
|
+
events:
|
|
51
|
+
onClick:
|
|
52
|
+
- id: link_to_docs
|
|
53
|
+
type: Link
|
|
54
|
+
params:
|
|
55
|
+
url: https://docs.lowdefy.com
|
|
56
|
+
newTab: true
|
|
57
|
+
footer:
|
|
58
|
+
blocks:
|
|
59
|
+
- id: footer
|
|
60
|
+
type: Paragraph
|
|
61
|
+
properties:
|
|
62
|
+
type: secondary
|
|
63
|
+
content: |
|
|
64
|
+
Made by a Lowdefy 🤖
|
|
65
|
+
|
|
66
|
+
`
|
|
67
|
+
);
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
(()=>{"use strict";var e={153:(e,t,o)=>{o.r(t);const r=require("commander");var n=o.n(r);const i=JSON.parse('{"name":"lowdefy","version":"3.23.0-alpha.0","license":"Apache-2.0","description":"Lowdefy CLI","homepage":"https://lowdefy.com","keywords":["lowdefy","cli"],"bugs":{"url":"https://github.com/lowdefy/lowdefy/issues"},"contributors":[{"name":"Sam Tolmay","url":"https://github.com/SamTolmay"},{"name":"Gerrie van Wyk","url":"https://github.com/Gervwyk"}],"repository":{"type":"git","url":"https://github.com/lowdefy/lowdefy.git"},"bin":"dist/index.js","files":["dist/*"],"main":"dist/index.js","scripts":{"build":"yarn webpack","clean":"rm -rf dist && rm -rf .lowdefy","cli":"yarn node ./dist/index.js","cli:build":"yarn build && yarn node ./dist/index.js","prepare":"yarn build","test":"FORCE_COLOR=3 jest --coverage","webpack":"webpack --config webpack.config.js"},"dependencies":{"@lowdefy/helpers":"3.23.0-alpha.0","@lowdefy/node-utils":"3.23.0-alpha.0","apollo-server-express":"2.25.0","axios":"0.21.4","chalk":"4.1.1","chokidar":"3.5.1","commander":"7.2.0","decompress":"4.2.1","decompress-targz":"4.1.1","dotenv":"10.0.0","express":"4.17.1","fs-extra":"10.0.0","graphql":"15.5.0","js-yaml":"4.1.0","mssql":"7.1.0","mysql":"2.18.1","opener":"1.5.2","ora":"5.4.0","pg":"8.6.0","reload":"3.1.1","saslprep":"1.0.3","sqlite3":"5.0.2","uuid":"8.3.2"},"devDependencies":{"@babel/cli":"7.14.3","@babel/core":"7.14.3","@babel/preset-env":"7.14.4","@babel/preset-react":"7.13.13","@lowdefy/block-tools":"3.23.0-alpha.0","babel-jest":"26.6.3","babel-loader":"8.2.2","clean-webpack-plugin":"3.0.0","copy-webpack-plugin":"9.0.0","css-loader":"5.2.6","html-webpack-plugin":"5.3.1","jest":"26.6.3","react":"17.0.2","react-dom":"17.0.2","style-loader":"2.0.0","webpack":"5.38.1","webpack-cli":"4.7.0"},"publishConfig":{"access":"public"}}'),a=require("path");var s=o.n(a);const c=require("fs-extra");var l=o.n(c);const d=require("fs");var p=o.n(d);const u=require("axios");var y=o.n(u);const f=require("decompress");var w=o.n(f);const h=require("decompress-targz");var m=o.n(h);const g=async function({packageName:e,version:t,directory:o}){const r=`https://registry.npmjs.org/${e}`;let n,i;try{n=await y().get(r)}catch(t){if(t.response&&404===t.response.status)throw new Error(`Package "${e}" could not be found at ${r}.`);throw t}if(!n||!n.data)throw new Error(`Package "${e}" could not be found at ${r}.`);if(!n.data.versions[t])throw new Error(`Invalid version. "${e}" does not have version "${t}".`);try{i=await y().get(n.data.versions[t].dist.tarball,{responseType:"arraybuffer"})}catch(o){if(o.response&&404===o.response.status)throw new Error(`Package "${e}" tarball could not be found at ${n.data.versions[t].dist.tarball}.`);throw o}if(!i||!i.data)throw new Error(`Package "${e}" tarball could not be found at ${n.data.versions[t].dist.tarball}.`);await w()(i.data,o,{plugins:[m()()]})},v=async function({module:e,packageName:t,version:r,context:n}){const i=r.replace(/[-.]/g,"_"),a=s().resolve(n.cacheDirectory,`scripts/${e}/${i}`);return p().existsSync(s().resolve(a,"package/dist/remoteEntry.js"))||(n.print.spin(`Fetching ${t}@${r} to cache.`),await g({packageName:t,version:r,directory:a}),n.print.log(`Fetched ${t}@${r} to cache.`)),async function({directory:e,module:t,remoteEntry:r="remoteEntry.js"}){return(await(async e=>(o.S.default&&await o.I("default"),new Promise((t=>{const r=require(e);new Promise((e=>{o.S.default?e(r.init(o.S.default)):e()})).then((()=>{t(r)}))}))))(s().resolve(`${e}/${r}`))).get(t).then((e=>e()))}({directory:s().resolve(a,"package/dist"),module:`./${e}`})},b=require("child_process"),x=require("@lowdefy/node-utils"),D=require("opener");var k=o.n(D);const _=require("chokidar");var S=o.n(_);const L=class{constructor({fn:e,context:t,minDelay:o}){this.fn=e,this.context=t,this.delay=o||500,this.minDelay=o||500,this._call=this._call.bind(this)}newChange(){this.delay=this.minDelay,this._startTimer()}_startTimer(){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(this._call,this.delay)}async _call(){try{await this.fn()}catch(e){this.context.print.error(e.message,{timestamp:!0}),this.delay*=2,this.context.print.warn(`Retrying in ${this.delay/1e3}s.`,{timestamp:!0}),this._startTimer()}}},$=require("express");var C=o.n($);const P=require("reload");var j=o.n(P);const q=require("@lowdefy/helpers"),T=require("net");var F=o.n(T);const O=async function({context:e,gqlServer:t}){const o=async(t,o)=>{let r=await(0,x.readFile)(s().resolve(__dirname,"shell/index.html")),n=await(0,x.readFile)(s().resolve(e.outputDirectory,"app.json"));n=JSON.parse(n),r=r.replace("\x3c!-- __LOWDEFY_APP_HEAD_HTML__ --\x3e",(0,q.get)(n,"html.appendHead",{default:""})),r=r.replace("\x3c!-- __LOWDEFY_APP_BODY_HTML__ --\x3e",(0,q.get)(n,"html.appendBody",{default:""})),o.send(r)},r=C()();r.set("port",parseInt(e.options.port)),t.applyMiddleware({app:r,path:"/api/graphql"});const n=await async function(){return new Promise(((e,t)=>{const o=F().createServer();o.on("error",t),o.listen(0,(()=>{const{port:t}=o.address();o.on("close",e.bind(null,t)),o.close()}))}))}(),i=await j()(r,{route:"/api/dev/reload.js",port:n});return r.get("/",o),r.use("/public",C().static(s().resolve(process.cwd(),"public"))),r.use(C().static(s().resolve(__dirname,"shell"))),r.use("/api/dev/rendererRemoteEntryUrl",((t,o)=>{let r;r=e.options.blocksServerUrl?`${e.options.blocksServerUrl}/renderer/remoteEntry.js`:`https://blocks-cdn.lowdefy.com/v${e.lowdefyVersion}/renderer/remoteEntry.js`,o.json(r)})),r.use(o),{expressApp:r,reloadFn:i.reload}},E=require("apollo-server-express"),N=require("dotenv");var I=o.n(N);const V=require("js-yaml");var A=o.n(V);const R=async function({baseDirectory:e,command:t}){let o,r=await(0,x.readFile)(s().resolve(e,"lowdefy.yaml"));if(r||(r=await(0,x.readFile)(s().resolve(e,"lowdefy.yml"))),!r){if(!["init","clean-cache"].includes(t))throw new Error(`Could not find "lowdefy.yaml" file in specified base directory ${e}.`);return{cliConfig:{}}}try{o=A().load(r)}catch(e){throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${e.message}.`)}if(!o.lowdefy)throw new Error('No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.');if(!q.type.isString(o.lowdefy)||!o.lowdefy.match(/\d+\.\d+\.\d+(-\w+\.\d+)?/))throw new Error(`Version number specified in "lowdefy.yaml" file is not valid. Received ${JSON.stringify(o.lowdefy)}.`);return{lowdefyVersion:o.lowdefy,cliConfig:(0,q.get)(o,"cli",{default:{}})}},{version:M}=i,U=`\nlowdefy: ${M}\nname: Lowdefy starter\n\npages:\n - id: welcome\n type: PageHeaderMenu\n properties:\n title: Welcome\n areas:\n content:\n justify: center\n blocks:\n - id: content_card\n type: Card\n style:\n maxWidth: 800\n blocks:\n - id: content\n type: Result\n properties:\n title: Welcome to your Lowdefy app\n subTitle: We are excited to see what you are going to build\n icon:\n name: HeartTwoTone\n color: '#f00'\n areas:\n extra:\n blocks:\n - id: docs_button\n type: Button\n properties:\n size: large\n title: Let's build something\n color: '#1890ff'\n events:\n onClick:\n - id: link_to_docs\n type: Link\n params:\n url: https://docs.lowdefy.com\n newTab: true\n footer:\n blocks:\n - id: footer\n type: Paragraph\n properties:\n type: secondary\n content: |\n Made by a Lowdefy 🤖\n\n`,B=require("ora");var H=o.n(B);const Y=require("chalk");var J=o.n(Y);let W;const z=function(){return W||("true"===process.env.CI?(W=function(){const{error:e,info:t,log:o,warn:r}=console;return{type:"basic",error:e,info:t,log:o,spin:o,succeed:o,warn:r}}(),W):(W=function(){const e=H()({spinner:"random",prefixText:()=>J().dim(function(){const e=new Date(Date.now()),t=e.getHours(),o=e.getMinutes(),r=e.getSeconds();return`${t>9?"":"0"}${t}:${o>9?"":"0"}${o}:${r>9?"":"0"}${r}`}()),color:"blue"});return{type:"ora",error:t=>e.fail(J().red(t)),info:t=>e.info(J().blue(t)),log:t=>e.start(t).stopAndPersist({symbol:"∙"}),spin:t=>e.start(t),succeed:t=>e.succeed(J().green(t)),warn:t=>e.warn(J().yellow(t))}}(),W))},{version:G}=i,K=require("uuid"),{version:Q}=i,X=async function({context:e,options:t={},command:o}){e.command=o.name(),e.cliVersion=Q,e.commandLineOptions=t,e.print=z(),e.baseDirectory=s().resolve(t.baseDirectory||process.cwd());const{cliConfig:r,lowdefyVersion:n}=await R(e);e.cliConfig=r,e.lowdefyVersion=n;const{appId:i}=await async function({baseDirectory:e}){const t=s().resolve(e,"./.lowdefy/cli.json"),o=await(0,x.readFile)(t);if(!o){const e=(0,K.v4)();return await(0,x.writeFile)({filePath:t,content:JSON.stringify({appId:e},null,2)}),{appId:e}}return JSON.parse(o)}(e);e.appId=i,e.options=function({commandLineOptions:e,cliConfig:t}){return{...t,...e}}(e);const{cacheDirectory:a,outputDirectory:c}=function({baseDirectory:e,options:t}){const o=s().resolve(e,"./.lowdefy/.cache");let r;return r=t.outputDirectory?s().resolve(t.outputDirectory):s().resolve(e,"./.lowdefy/build"),{cacheDirectory:o,outputDirectory:r}}(e);return e.cacheDirectory=a,e.outputDirectory=c,await async function({cliVersion:e,lowdefyVersion:t,print:o}){try{const r=(await y().get("https://registry.npmjs.org/lowdefy")).data["dist-tags"].latest;e!==r&&o.warn(`\n-------------------------------------------------------------\n You are using an outdated Lowdefy CLI.\n Please update to version ${r}.\n To always use the latest version, run 'npx lowdefy@latest'.\n-------------------------------------------------------------`),t&&t!==r&&o.warn(`\n-------------------------------------------------------------\n Your app is using an outdated Lowdefy version, ${t}.\n Please update your app to version ${r}.\n View the changelog here:\n https://github.com/lowdefy/lowdefy/blob/main/CHANGELOG.md\n-------------------------------------------------------------`)}catch(e){o.warn("Failed to check for latest Lowdefy version.")}}(e),e.sendTelemetry=function({appId:e,cliVersion:t,command:o,lowdefyVersion:r,options:n}){return n.disableTelemetry?()=>{}:async function({data:n={}}={}){try{await y().request({method:"post",url:"https://api.lowdefy.net/telemetry/cli",headers:{"User-Agent":`Lowdefy CLI v${t}`},data:{...n,app_id:e,cli_version:t,command:o,lowdefy_version:r}})}catch(e){}}}(e),q.type.isNone(n)?e.print.log(`Running 'lowdefy ${e.command}'.`):e.print.log(`Running 'lowdefy ${e.command}'. Lowdefy app version ${n}.`),e},Z=function(e){return async function(t,o){const r={};try{return await X({context:r,options:t,command:o}),await e({context:r})}catch(e){await async function({context:e,error:t}){z().error(t.message),e.disableTelemetry||await async function({error:e,context:t={}}){try{await y().request({method:"post",url:"https://api.lowdefy.net/errors",headers:{"User-Agent":`Lowdefy CLI v${G}`},data:{source:"cli",cliVersion:G,command:t.command,lowdefyVersion:t.lowdefyVersion,message:e.message,name:e.name,stack:e.stack}})}catch(e){}}({context:e,error:t})}({context:r,error:e})}}},{description:ee,version:te}=i;n().name("lowdefy").description(ee).version(te,"-v, --version"),n().command("build").description("Build a Lowdefy deployment.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--blocks-server-url <blocks-server-url>","The URL from where Lowdefy blocks will be served.").option("--disable-telemetry","Disable telemetry.").option("--output-directory <output-directory>",'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy/build".').option("--ref-resolver <ref-resolver-function-path>","Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.").action(Z((async function({context:e}){const{default:t}=await v({module:"build",packageName:"@lowdefy/build",version:e.lowdefyVersion,context:e});e.print.log(`Cleaning block meta cache at "${s().resolve(e.cacheDirectory,"./meta")}".`),await l().emptyDir(s().resolve(e.cacheDirectory,"./meta")),e.print.info("Starting build."),await t({blocksServerUrl:e.options.blocksServerUrl,cacheDirectory:e.cacheDirectory,configDirectory:e.baseDirectory,logger:e.print,outputDirectory:e.outputDirectory,refResolver:e.options.refResolver}),await e.sendTelemetry(),e.print.log(`Build artifacts saved at ${e.outputDirectory}.`),e.print.succeed("Build successful.")}))),n().command("build-netlify").description("Build a Lowdefy deployment to deploy in netlify.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--blocks-server-url <blocks-server-url>","The URL from where Lowdefy blocks will be served.").option("--disable-telemetry","Disable telemetry.").option("--ref-resolver <ref-resolver-function-path>","Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.").action(Z((async function({context:e}){e.netlifyDir=s().resolve(e.baseDirectory,"./.lowdefy/netlify"),e.print.info("Starting build.");const t=await async function({context:e}){e.print.log("Fetching Lowdefy build script.");const{default:t}=await v({module:"build",packageName:"@lowdefy/build",version:e.lowdefyVersion,context:e});return e.print.log("Fetched Lowdefy build script."),t}({context:e});await async function({context:e,buildScript:t}){e.print.log("Starting Lowdefy build.");const o=s().resolve(e.netlifyDir,"./package/dist/functions/graphql/build");await t({blocksServerUrl:e.options.blocksServerUrl,cacheDirectory:e.cacheDirectory,configDirectory:e.baseDirectory,logger:e.print,outputDirectory:o,refResolver:e.options.refResolver}),e.print.log(`Build artifacts saved at ${o}.`)}({context:e,buildScript:t}),e.print.info("Installing Lowdefy server."),await async function({context:e}){e.print.log("Fetching Lowdefy Netlify server."),await g({packageName:"@lowdefy/server-netlify",version:e.lowdefyVersion,directory:e.netlifyDir}),e.print.log("Fetched Lowdefy Netlify server.")}({context:e}),await async function({context:e}){await l().copy(s().resolve(e.netlifyDir,"package/package.json"),s().resolve("./package.json")),await l().remove(s().resolve("./package-lock.json")),await l().remove(s().resolve("./package-lock.json")),await l().emptyDir(s().resolve("./node_modules")),e.print.log("npm install production.");let t=(0,b.spawnSync)("npm",["install","--production","--legacy-peer-deps"]);(function({context:e,processOutput:t,message:o}){if(1===t.status)throw e.print.error(t.stderr.toString("utf8")),new Error(o)})({context:e,processOutput:t,message:"Failed to npm install Netlify server."}),e.print.log("npm install successful."),e.print.log(t.stdout.toString("utf8"))}({context:e}),e.print.log("Moving artifacts."),await async function({context:e}){await l().copy(s().resolve(e.netlifyDir,"package/dist/shell"),s().resolve("./.lowdefy/publish")),e.print.log('Netlify publish artifacts moved to "./lowdefy/publish".')}({context:e}),await async function({context:e}){await l().copy(s().resolve(e.netlifyDir,"package/dist/functions"),s().resolve("./.lowdefy/functions")),e.print.log('Netlify functions artifacts moved to "./lowdefy/functions".')}({context:e}),await async function({context:e}){e.print.log("Moving public assets."),await l().ensureDir(s().resolve("./public")),await l().copy(s().resolve("./public"),s().resolve("./.lowdefy/publish/public")),e.print.log('Public assets moved to "./lowdefy/publish/public".')}({context:e}),e.print.log("Build artifacts."),await async function({context:e}){e.print.log("Starting Lowdefy index.html build.");let t=await(0,x.readFile)(s().resolve("./.lowdefy/functions/graphql/build/app.json"));t=JSON.parse(t);const o=s().resolve("./.lowdefy/publish/index.html");let r=await(0,x.readFile)(o);r=r.replace("\x3c!-- __LOWDEFY_APP_HEAD_HTML__ --\x3e",t.html.appendHead),r=r.replace("\x3c!-- __LOWDEFY_APP_BODY_HTML__ --\x3e",t.html.appendBody),await(0,x.writeFile)({filePath:o,content:r}),e.print.log("Lowdefy index.html build complete.")}({context:e}),await e.sendTelemetry({data:{netlify:"true"===process.env.NETLIFY}}),e.print.succeed("Netlify build completed successfully.")}))),n().command("clean-cache").description("Clean cached scripts and block meta descriptions.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--disable-telemetry","Disable telemetry.").action(Z((async function({context:e}){e.print.log(`Cleaning cache at "${e.cacheDirectory}".`),await l().emptyDir(e.cacheDirectory),await e.sendTelemetry(),e.print.succeed("Cache cleaned.")}))),n().command("dev").description("Start a Lowdefy development server.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--blocks-server-url <blocks-server-url>","The URL from where Lowdefy blocks will be served.").option("--disable-telemetry","Disable telemetry.").option("--port <port>","Change the port the server is hosted at. Default is 3000.").option("--ref-resolver <ref-resolver-function-path>","Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.").option("--watch <paths...>","A list of paths to files or directories that should be watched for changes.").option("--watch-ignore <paths...>","A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.").action(Z((async function({context:e}){await async function({context:e}){I().config({silent:!0}),e.options.port||(e.options.port=3e3),e.print.log(`Cleaning block meta cache at "${s().resolve(e.cacheDirectory,"./meta")}".`),await l().emptyDir(s().resolve(e.cacheDirectory,"./meta"))}({context:e});const t=async function({context:e}){const t=await async function({context:e}){const{default:t}=await v({module:"build",packageName:"@lowdefy/build",version:e.lowdefyVersion,context:e});return async function(){e.print.log("Building configuration."),await t({blocksServerUrl:e.options.blocksServerUrl,cacheDirectory:e.cacheDirectory,configDirectory:e.baseDirectory,logger:e.print,outputDirectory:e.outputDirectory,refResolver:e.options.refResolver}),e.print.succeed("Built successfully.")}}({context:e});try{await t()}catch(e){}return t}({context:e}),o=async function({context:e}){const t=await async function({context:e}){const{typeDefs:t,resolvers:o,createContext:r}=await v({module:"graphql",packageName:"@lowdefy/graphql-federated",version:e.lowdefyVersion,context:e}),n=r({CONFIGURATION_BASE_PATH:e.outputDirectory,development:!0,logger:console,getSecrets:(0,x.createGetSecretsFromEnv)()});return new E.ApolloServer({typeDefs:t,resolvers:o,context:n})}({context:e});return O({context:e,gqlServer:t})}({context:e}),[r,{expressApp:n,reloadFn:i}]=await Promise.all([t,o]);(function({build:e,context:t,reloadFn:o}){const{watch:r=[],watchIgnore:n=[]}=t.options,i=r.map((e=>s().resolve(e))),a=new L({fn:async()=>{await e(),o()},context:t}),c=S().watch([".",...i],{ignored:[/(^|[/\\])\../,...n],persistent:!0,ignoreInitial:!0});c.on("add",(()=>a.newChange())),c.on("change",(()=>a.newChange())),c.on("unlink",(()=>a.newChange()))})({build:r,context:e,reloadFn:i}),function({context:e}){const t=new L({fn:async()=>{e.print.warn(".env file changed. You should restart your development server."),process.exit()},context:e});S().watch("./.env",{persistent:!0}).on("change",(()=>t.newChange()))}({context:e}),function({context:e}){const t=new L({fn:async()=>{const{lowdefyVersion:t}=await R(e);t!==e.lowdefyVersion&&(e.print.warn("Lowdefy version changed. You should restart your development server."),process.exit())},context:e});S().watch("./lowdefy.yaml",{persistent:!0}).on("change",(()=>t.newChange()))}({context:e}),e.print.log("Starting Lowdefy development server.");const a=n.get("port");n.listen(a,(function(){e.print.info(`Development server listening on port ${a}`)})),k()(`http://localhost:${a}`),await e.sendTelemetry({data:{type:"startup"}})}))),n().command("init").description("Initialize a Lowdefy project.").usage("[options]").action(Z((async function({context:e}){const t=s().resolve("./lowdefy.yaml");if(l().existsSync(t))throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');e.print.log("Initializing Lowdefy project"),await(0,x.writeFile)({filePath:t,content:U}),e.print.log("Created 'lowdefy.yaml'."),await(0,x.writeFile)({filePath:s().resolve("./.gitignore"),content:".lowdefy/**\n.env"}),e.print.log("Created '.gitignore'."),await e.sendTelemetry(),e.print.succeed("Project initialized.")}))),n().parse(process.argv)}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.exports}o.m=e,o.c=t,o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{o.S={};var e={},t={};o.I=(r,n)=>{n||(n=[]);var i=t[r];if(i||(i=t[r]={}),!(n.indexOf(i)>=0)){if(n.push(i),e[r])return e[r];o.o(o.S,r)||(o.S[r]={}),o.S[r];var a=[];return e[r]=a.length?Promise.all(a).then((()=>e[r]=1)):1}}})();var r=o(153),n=exports;for(var i in r)n[i]=r[i];r.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})();
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { readFile } from '@lowdefy/node-utils';
|
|
16
|
+
import program from 'commander';
|
|
17
|
+
import build from './commands/build/build.js';
|
|
18
|
+
// import dev from './commands/dev/dev.js';
|
|
19
|
+
import init from './commands/init/init.js';
|
|
20
|
+
import runCommand from './utils/runCommand.js';
|
|
21
|
+
const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url).pathname));
|
|
22
|
+
const { description , version } = packageJson;
|
|
23
|
+
program.name('lowdefy').description(description).version(version, '-v, --version');
|
|
24
|
+
program.command('build').description('Build a Lowdefy deployment.').usage(`[options]`).option('--base-directory <base-directory>', 'Change base directory. Default is the current working directory.').option('--blocks-server-url <blocks-server-url>', 'The URL from where Lowdefy blocks will be served.').option('--disable-telemetry', 'Disable telemetry.').option('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy/build".').option('--package-manager <package-manager>', 'The package manager to user. Options are "npm" or "yarn".').option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.').action(runCommand({
|
|
25
|
+
cliVersion: version
|
|
26
|
+
})(build));
|
|
27
|
+
// program
|
|
28
|
+
// .command('dev')
|
|
29
|
+
// .description('Start a Lowdefy development server.')
|
|
30
|
+
// .usage(`[options]`)
|
|
31
|
+
// .option(
|
|
32
|
+
// '--base-directory <base-directory>',
|
|
33
|
+
// 'Change base directory. Default is the current working directory.'
|
|
34
|
+
// )
|
|
35
|
+
// .option(
|
|
36
|
+
// '--blocks-server-url <blocks-server-url>',
|
|
37
|
+
// 'The URL from where Lowdefy blocks will be served.'
|
|
38
|
+
// )
|
|
39
|
+
// .option('--disable-telemetry', 'Disable telemetry.')
|
|
40
|
+
// .option('--port <port>', 'Change the port the server is hosted at. Default is 3000.')
|
|
41
|
+
// .option(
|
|
42
|
+
// '--ref-resolver <ref-resolver-function-path>',
|
|
43
|
+
// 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.'
|
|
44
|
+
// )
|
|
45
|
+
// .option(
|
|
46
|
+
// '--watch <paths...>',
|
|
47
|
+
// 'A list of paths to files or directories that should be watched for changes.'
|
|
48
|
+
// )
|
|
49
|
+
// .option(
|
|
50
|
+
// '--watch-ignore <paths...>',
|
|
51
|
+
// 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.'
|
|
52
|
+
// )
|
|
53
|
+
// .action(runCommand({ cliVersion: version })(dev));
|
|
54
|
+
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
55
|
+
cliVersion: version
|
|
56
|
+
})(init));
|
|
57
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ let BatchChanges = class BatchChanges {
|
|
16
|
+
newChange() {
|
|
17
|
+
this.delay = this.minDelay;
|
|
18
|
+
this._startTimer();
|
|
19
|
+
}
|
|
20
|
+
_startTimer() {
|
|
21
|
+
if (this.timer) {
|
|
22
|
+
clearTimeout(this.timer);
|
|
23
|
+
}
|
|
24
|
+
this.timer = setTimeout(this._call, this.delay);
|
|
25
|
+
}
|
|
26
|
+
async _call() {
|
|
27
|
+
try {
|
|
28
|
+
await this.fn();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
this.context.print.error(error.message, {
|
|
31
|
+
timestamp: true
|
|
32
|
+
});
|
|
33
|
+
this.delay *= 2;
|
|
34
|
+
this.context.print.warn(`Retrying in ${this.delay / 1000}s.`, {
|
|
35
|
+
timestamp: true
|
|
36
|
+
});
|
|
37
|
+
this._startTimer();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
constructor({ fn , context , minDelay }){
|
|
41
|
+
this.fn = fn;
|
|
42
|
+
this.context = context;
|
|
43
|
+
this.delay = minDelay || 500;
|
|
44
|
+
this.minDelay = minDelay || 500;
|
|
45
|
+
this._call = this._call.bind(this);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
export default BatchChanges;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import axios from 'axios';
|
|
16
|
+
async function checkForUpdatedVersions({ cliVersion , lowdefyVersion , print }) {
|
|
17
|
+
if (isExperimentalVersion(cliVersion) || isExperimentalVersion(lowdefyVersion)) {
|
|
18
|
+
print.warn(`
|
|
19
|
+
---------------------------------------------------
|
|
20
|
+
You are using an experimental version of Lowdefy.
|
|
21
|
+
Features may change at any time.
|
|
22
|
+
---------------------------------------------------`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const registryUrl = 'https://registry.npmjs.org/lowdefy';
|
|
26
|
+
try {
|
|
27
|
+
const packageInfo = await axios.get(registryUrl);
|
|
28
|
+
const latestVersion = packageInfo.data['dist-tags'].latest;
|
|
29
|
+
if (cliVersion !== latestVersion) {
|
|
30
|
+
print.warn(`
|
|
31
|
+
-------------------------------------------------------------
|
|
32
|
+
You are not using the latest version of the Lowdefy CLI.
|
|
33
|
+
Please update to version ${latestVersion}.
|
|
34
|
+
To always use the latest version, run 'npx lowdefy@latest'.
|
|
35
|
+
-------------------------------------------------------------`);
|
|
36
|
+
}
|
|
37
|
+
if (lowdefyVersion && lowdefyVersion !== latestVersion) {
|
|
38
|
+
print.warn(`
|
|
39
|
+
-------------------------------------------------------------
|
|
40
|
+
Your app is not using the latest Lowdefy version, ${lowdefyVersion}.
|
|
41
|
+
Please update your app to version ${latestVersion}.
|
|
42
|
+
View the changelog here:
|
|
43
|
+
https://github.com/lowdefy/lowdefy/blob/main/CHANGELOG.md
|
|
44
|
+
-------------------------------------------------------------`);
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
print.warn('Failed to check for latest Lowdefy version.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function isExperimentalVersion(version) {
|
|
51
|
+
return version.includes('alpha') || version.includes('beta') || version.includes('rc');
|
|
52
|
+
}
|
|
53
|
+
export default checkForUpdatedVersions;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import axios from 'axios';
|
|
16
|
+
import createPrint from './print.js';
|
|
17
|
+
async function logError({ error , context ={
|
|
18
|
+
} }) {
|
|
19
|
+
try {
|
|
20
|
+
await axios.request({
|
|
21
|
+
method: 'post',
|
|
22
|
+
url: 'https://api.lowdefy.net/errors',
|
|
23
|
+
headers: {
|
|
24
|
+
'User-Agent': `Lowdefy CLI v${context.cliVersion}`
|
|
25
|
+
},
|
|
26
|
+
data: {
|
|
27
|
+
source: 'cli',
|
|
28
|
+
cliVersion: context.cliVersion,
|
|
29
|
+
command: context.command,
|
|
30
|
+
lowdefyVersion: context.lowdefyVersion,
|
|
31
|
+
message: error.message,
|
|
32
|
+
name: error.name,
|
|
33
|
+
stack: error.stack
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
} catch (error1) {
|
|
37
|
+
// pass
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function errorHandler({ context , error }) {
|
|
41
|
+
const print = createPrint();
|
|
42
|
+
print.error(error.message);
|
|
43
|
+
if (!context.disableTelemetry) {
|
|
44
|
+
await logError({
|
|
45
|
+
context,
|
|
46
|
+
error
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export default errorHandler;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import axios from 'axios';
|
|
16
|
+
import decompress from 'decompress';
|
|
17
|
+
import decompressTargz from 'decompress-targz';
|
|
18
|
+
async function fetchNpmTarball({ packageName , version , directory }) {
|
|
19
|
+
const registryUrl = `https://registry.npmjs.org/${packageName}`;
|
|
20
|
+
let packageInfo;
|
|
21
|
+
try {
|
|
22
|
+
packageInfo = await axios.get(registryUrl);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.response && error.response.status === 404) {
|
|
25
|
+
throw new Error(`Package "${packageName}" could not be found at ${registryUrl}.`);
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
if (!packageInfo || !packageInfo.data) {
|
|
30
|
+
throw new Error(`Package "${packageName}" could not be found at ${registryUrl}.`);
|
|
31
|
+
}
|
|
32
|
+
if (!packageInfo.data.versions[version]) {
|
|
33
|
+
throw new Error(`Invalid version. "${packageName}" does not have version "${version}".`);
|
|
34
|
+
}
|
|
35
|
+
let tarball;
|
|
36
|
+
try {
|
|
37
|
+
tarball = await axios.get(packageInfo.data.versions[version].dist.tarball, {
|
|
38
|
+
responseType: 'arraybuffer'
|
|
39
|
+
});
|
|
40
|
+
} catch (error1) {
|
|
41
|
+
if (error1.response && error1.response.status === 404) {
|
|
42
|
+
throw new Error(`Package "${packageName}" tarball could not be found at ${packageInfo.data.versions[version].dist.tarball}.`);
|
|
43
|
+
}
|
|
44
|
+
throw error1;
|
|
45
|
+
}
|
|
46
|
+
if (!tarball || !tarball.data) {
|
|
47
|
+
throw new Error(`Package "${packageName}" tarball could not be found at ${packageInfo.data.versions[version].dist.tarball}.`);
|
|
48
|
+
}
|
|
49
|
+
await decompress(tarball.data, directory, {
|
|
50
|
+
plugins: [
|
|
51
|
+
decompressTargz()
|
|
52
|
+
],
|
|
53
|
+
strip: 1
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export default fetchNpmTarball;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Based on: https://github.com/testiumjs/find-open-port
|
|
16
|
+
/*
|
|
17
|
+
* Copyright (c) 2015, Groupon, Inc.
|
|
18
|
+
* All rights reserved.
|
|
19
|
+
*
|
|
20
|
+
* Redistribution and use in source and binary forms, with or without
|
|
21
|
+
* modification, are permitted provided that the following conditions
|
|
22
|
+
* are met:
|
|
23
|
+
*
|
|
24
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
25
|
+
* this list of conditions and the following disclaimer.
|
|
26
|
+
*
|
|
27
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
28
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
29
|
+
* documentation and/or other materials provided with the distribution.
|
|
30
|
+
*
|
|
31
|
+
* Neither the name of GROUPON nor the names of its contributors may be
|
|
32
|
+
* used to endorse or promote products derived from this software without
|
|
33
|
+
* specific prior written permission.
|
|
34
|
+
*
|
|
35
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
36
|
+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
37
|
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
38
|
+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
39
|
+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
40
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
41
|
+
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
42
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
43
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
44
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
45
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
46
|
+
*/ import net from 'net';
|
|
47
|
+
async function findPort() {
|
|
48
|
+
return new Promise((resolve, reject)=>{
|
|
49
|
+
const server = net.createServer();
|
|
50
|
+
server.on('error', reject);
|
|
51
|
+
server.listen(0, ()=>{
|
|
52
|
+
const { port } = server.address();
|
|
53
|
+
server.on('close', resolve.bind(null, port));
|
|
54
|
+
server.close();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export default findPort;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import path from 'path';
|
|
16
|
+
import { readFile, writeFile } from '@lowdefy/node-utils';
|
|
17
|
+
import { v4 as uuid } from 'uuid';
|
|
18
|
+
async function getCliJson({ baseDirectory }) {
|
|
19
|
+
const filePath = path.resolve(baseDirectory, './.lowdefy/cli.json');
|
|
20
|
+
const cliJson = await readFile(filePath);
|
|
21
|
+
if (!cliJson) {
|
|
22
|
+
const appId = uuid();
|
|
23
|
+
await writeFile({
|
|
24
|
+
filePath,
|
|
25
|
+
content: JSON.stringify({
|
|
26
|
+
appId
|
|
27
|
+
}, null, 2)
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
appId
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return JSON.parse(cliJson);
|
|
34
|
+
}
|
|
35
|
+
export default getCliJson;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import path from 'path';
|
|
16
|
+
function getDirectories({ baseDirectory , options }) {
|
|
17
|
+
let dotLowdefy;
|
|
18
|
+
if (options.outputDirectory) {
|
|
19
|
+
dotLowdefy = path.resolve(options.outputDirectory);
|
|
20
|
+
} else {
|
|
21
|
+
dotLowdefy = path.resolve(baseDirectory, '.lowdefy');
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
base: baseDirectory,
|
|
25
|
+
build: path.join(dotLowdefy, 'server', 'build'),
|
|
26
|
+
dotLowdefy,
|
|
27
|
+
server: path.join(dotLowdefy, 'server')
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export default getDirectories;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import path from 'path';
|
|
16
|
+
import { get, type } from '@lowdefy/helpers';
|
|
17
|
+
import { readFile } from '@lowdefy/node-utils';
|
|
18
|
+
import YAML from 'js-yaml';
|
|
19
|
+
async function getLowdefyYaml({ baseDirectory , command }) {
|
|
20
|
+
let lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yaml'));
|
|
21
|
+
if (!lowdefyYaml) {
|
|
22
|
+
lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yml'));
|
|
23
|
+
}
|
|
24
|
+
if (!lowdefyYaml) {
|
|
25
|
+
if (![
|
|
26
|
+
'init'
|
|
27
|
+
].includes(command)) {
|
|
28
|
+
throw new Error(`Could not find "lowdefy.yaml" file in specified base directory ${baseDirectory}.`);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
cliConfig: {
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
let lowdefy;
|
|
36
|
+
try {
|
|
37
|
+
lowdefy = YAML.load(lowdefyYaml);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${error.message}.`);
|
|
40
|
+
}
|
|
41
|
+
if (!lowdefy.lowdefy) {
|
|
42
|
+
throw new Error(`No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.`);
|
|
43
|
+
}
|
|
44
|
+
if (!type.isString(lowdefy.lowdefy)) {
|
|
45
|
+
throw new Error(`Version number specified in "lowdefy.yaml" file should be a string. Received ${JSON.stringify(lowdefy.lowdefy)}.`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
lowdefyVersion: lowdefy.lowdefy,
|
|
49
|
+
cliConfig: get(lowdefy, 'cli', {
|
|
50
|
+
default: {
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export default getLowdefyYaml;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ function getOptions({ commandLineOptions , cliConfig }) {
|
|
16
|
+
// commandLineOptions take precedence over config in lowdefy.yaml
|
|
17
|
+
const options = {
|
|
18
|
+
...cliConfig,
|
|
19
|
+
...commandLineOptions
|
|
20
|
+
};
|
|
21
|
+
return options;
|
|
22
|
+
}
|
|
23
|
+
export default getOptions;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Source https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/should-use-yarn.ts
|
|
16
|
+
/*
|
|
17
|
+
The MIT License (MIT)
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2021 Vercel, Inc.
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|
|
38
|
+
*/ import { execSync } from 'child_process';
|
|
39
|
+
function getPackageManager({ options }) {
|
|
40
|
+
if (options.packageManager) return options.packageManager;
|
|
41
|
+
try {
|
|
42
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
43
|
+
if (userAgent && userAgent.startsWith('yarn')) {
|
|
44
|
+
return 'yarn';
|
|
45
|
+
}
|
|
46
|
+
execSync('yarnpkg --version', {
|
|
47
|
+
stdio: 'ignore'
|
|
48
|
+
});
|
|
49
|
+
return 'yarn';
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return 'npm';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export default getPackageManager;
|