-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new options: createLoaderWidget, loadingComponentFile, loadingC…
…omponentName. These new options are used to create suspense loading widget to load the main widget
- Loading branch information
Showing
11 changed files
with
131 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { ALEM_VM_FOLDER } = require("../constants"); | ||
const { process_file } = require("../parse"); | ||
const getMainWidgetName = require("./getMainWidgetName"); | ||
const { read_alem_config } = require("../config"); | ||
|
||
/** | ||
* Cria o Widget Suspense para servir como loading para o Widget principal | ||
* | ||
* @param {*} opts Opcoes da CLI | ||
*/ | ||
const createSuspenseWidget = (opts) => { | ||
const mainWidgetName = getMainWidgetName(); | ||
const config = read_alem_config(); | ||
// console.log(config); | ||
// console.log(opts); | ||
|
||
// Configurable: Cria somente se "createLoaderWidget" for true | ||
if (config.options.createLoaderWidget) { | ||
const account = | ||
opts.network === "mainnet" | ||
? config.mainnetAccount | ||
: config.testnetAccount; | ||
const mainWidgetSrc = `${account}/widget/${mainWidgetName}`; | ||
|
||
let loadingComponent = ""; | ||
let loadingComponentJSX = "<Loading />"; | ||
|
||
if ( | ||
config.options.loadingComponentFile && | ||
config.options.loadingComponentName | ||
) { | ||
const loadingComponentFilePath = path.join( | ||
".", | ||
config.options.loadingComponentFile, | ||
); | ||
loadingComponent = process_file(loadingComponentFilePath); | ||
loadingComponentJSX = `<${config.options.loadingComponentName} />`; | ||
} else { | ||
loadingComponent = process_file( | ||
path.join(__dirname, "../", ALEM_VM_FOLDER, "components/Loading.jsx"), | ||
); | ||
} | ||
|
||
let suspenseFile = process_file( | ||
path.join(__dirname, "../", ALEM_VM_FOLDER, "components/Suspense.jsx"), | ||
); | ||
|
||
// Suspense parts | ||
suspenseFile = suspenseFile | ||
.replace(":::MAIN_WIDGET_SOURCE:::", mainWidgetSrc) | ||
.replace(`":::LOADING_COMPONENT:::";`, loadingComponent) | ||
.replace(`":::LOADING_COMPONENT_JSX"`, loadingComponentJSX); | ||
|
||
fs.writeFileSync( | ||
path.join(`./build/src/${mainWidgetName}Loader.jsx`), | ||
suspenseFile, | ||
); | ||
} | ||
}; | ||
|
||
module.exports = createSuspenseWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { read_alem_config } = require("../config"); | ||
|
||
const getMainWidgetName = () => { | ||
const config = read_alem_config(); | ||
const mainWidgetName = config.isIndex | ||
? "Index" | ||
: config.name.replaceAll(" ", "-").toLowerCase(); | ||
|
||
return mainWidgetName; | ||
}; | ||
|
||
module.exports = getMainWidgetName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const Container = styled.div` | ||
display: flex; | ||
margin-top: 40%; | ||
justify-content: center; | ||
width: 100%; | ||
`; | ||
|
||
const Loading = () => ( | ||
<Container> | ||
<div className="spinner-border text-secondary" role="status" /> | ||
</Container> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
":::LOADING_COMPONENT:::"; | ||
|
||
return ( | ||
<Widget | ||
loading={":::LOADING_COMPONENT_JSX"} | ||
src=":::MAIN_WIDGET_SOURCE:::" | ||
props={props} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters