Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/beta' into beta-to-main
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW committed Nov 24, 2022
2 parents 68a418a + c076f6c commit d6d2f3e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
13 changes: 13 additions & 0 deletions demos/parse-server-migration/.ebextensions/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
option_settings:
aws:elasticbeanstalk:application:environment:
MORALIS_API_KEY: 'replace_me'
MASTER_KEY: 'replace_me'
APPLICATION_ID: 'replace_me'
SERVER_URL: 'http://myappname.elasticbeanstalk.com/server'
DATABASE_URI: 'mongodb://localhost:27017'
REDIS_CONNECTION_STRING: 'redis://127.0.0.1:6379'
RATE_LIMIT_TTL: 30
RATE_LIMIT_AUTHENTICATED: 50
RATE_LIMIT_ANONYMOUS: 20
USE_STREAMS: false
STREAMS_WEBHOOK_URL: '/streams-webhook'
7 changes: 7 additions & 0 deletions demos/parse-server-migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ Make sure to set the `DATABASE_URI` in your `.env` file
For rate-limiting, we are using a redis instance. In order for this to work, you will need to setup redis instance. For more information you can see https://redis.io/docs/getting-started/

For local development you will need to install redis on your local machine, and start the service. Make sure to set the `REDIS_CONNECTION_STRING` in your `.env` file

## Remote deployment

### AWS Elastic Beanstalk

Follow the steps in the documentation:
https://docs.moralis.io/docs/deploy-to-production#aws-elastic-beanstalk
2 changes: 1 addition & 1 deletion packages/client/firebaseApiUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Moralis",
"version": "2.7.4",
"license": "MIT",
"private": false,
"private": true,
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/firebaseEvmApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Moralis",
"version": "2.7.4",
"license": "MIT",
"private": false,
"private": true,
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/firebaseSolApi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Moralis",
"version": "2.7.4",
"license": "MIT",
"private": false,
"private": true,
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
Expand Down
50 changes: 45 additions & 5 deletions scripts/buildDemoDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs');
const path = require('path');
const fse = require('fs-extra');
const archiver = require('archiver');
const util = require('util');
const asyncExec = util.promisify(require('child_process').exec);

// Url to hosted github pages
const HOSTED_PAGES = 'https://moralisweb3.github.io/Moralis-JS-SDK';
Expand All @@ -26,11 +28,17 @@ const OUT_DIR_DOCS = 'docs';
// Reference to the folder names in the output folder
const DEMOS_DIR = 'demos';
const CODE_DIR = 'code';
const CODE_WITH_BUILD_DIR = 'code-build';

const demoFolderPath = path.join(__dirname, '..', DIR_DEMO);
const outputCodePath = path.join(__dirname, '..', OUT_DIR_CODE, DEMOS_DIR);
const outputDocsPath = path.join(__dirname, '..', OUT_DIR_DOCS);

// List of demos that require to upload a full build (node_modules and build artefacts) as well
const fullBuild = ['parse-server-migration'];

const isFullBuild = (demoFolder) => fullBuild.includes(demoFolder);

const getAllFilesFromFolder = async (folderName) =>
require('glob-fs')({ dotfiles: true }).readdirSync(`demos/${folderName}/**/*`);

Expand Down Expand Up @@ -63,6 +71,12 @@ const copyDemoToDocs = async (name, filePath) => {

await fse.copySync(srcPath, outPath);

if (isFullBuild(name)) {
const fullBuildOutPath = path.join(outputCodePath, name, CODE_WITH_BUILD_DIR, subPath);

await fse.copySync(srcPath, fullBuildOutPath);
}

return subPath;
};

Expand All @@ -82,6 +96,20 @@ const copyAllDemosToDocs = async (demoFolders) => {
return info;
};

/**
* Install and build for the demos that need a full build as well
*/
const createFullBuilds = async (demoFolders) => {
await Promise.all(
demoFolders.filter(isFullBuild).map(async (name) => {
const pathToDemo = path.join(outputCodePath, name, CODE_WITH_BUILD_DIR);

await asyncExec('yarn install', { cwd: pathToDemo });
await asyncExec('yarn build', { cwd: pathToDemo });
}),
);
};

/**
* Get all README content from the demos and store it in an object for lookup
*/
Expand Down Expand Up @@ -115,12 +143,14 @@ const getGithubUrl = (name) => `${GITHUB_DEMO_PATH}/${name}`;
const getDownloadName = (name) => `${name}.zip`;
const getDownloadPath = (name) => `${HOSTED_PAGES}/${DEMOS_DIR}/${name}/${getDownloadName(name)}`;
const getCodePath = (name) => `${HOSTED_PAGES}/${DEMOS_DIR}/${name}/${CODE_DIR}`;
const getFullBuildCodePath = (name) => `${HOSTED_PAGES}/${DEMOS_DIR}/${name}/${CODE_WITH_BUILD_DIR}`;
const getFullbuildDownloadName = (name) => `${name}-build.zip`;

/**
* Creates a .zip file for a demo project
*/
const createAchive = (folder) => {
const output = fs.createWriteStream(path.join(outputCodePath, folder, getDownloadName(folder)));
const createAchive = (folder, fileName, codePath) => {
const output = fs.createWriteStream(path.join(outputCodePath, folder, fileName));
const archive = archiver('zip', {
zlib: { level: COMPRESSION_LEVEL },
});
Expand Down Expand Up @@ -150,16 +180,24 @@ const createAchive = (folder) => {

archive.pipe(output);

archive.directory(path.join(outputCodePath, folder, CODE_DIR), false);
archive.directory(path.join(outputCodePath, folder, codePath), false);

archive.finalize();
};

/**
* Create archives for all demo projects
*/
const createAllAchives = (demoFolders) => {
return Promise.all(demoFolders.map((folder) => createAchive(folder)));
const createAllAchives = async (demoFolders) => {
// Create archive for all demos
await Promise.all(demoFolders.map((folder) => createAchive(folder, getDownloadName(folder), CODE_DIR)));

// Create archives for full build demos
await Promise.all(
demoFolders
.filter(isFullBuild)
.map((folder) => createAchive(folder, getFullbuildDownloadName(folder), CODE_WITH_BUILD_DIR)),
);
};

/**
Expand All @@ -170,6 +208,7 @@ const createInfo = (name) => ({
github: getGithubUrl(name),
download: getDownloadPath(name),
code: getCodePath(name),
...(isFullBuild(name) ? { fullBuildCode: getFullBuildCodePath(name) } : {}),
});

/**
Expand Down Expand Up @@ -260,6 +299,7 @@ const run = async () => {

await ensureAllCleanOutputDir(demoFolders);
await copyAllDemosToDocs(demoFolders);
await createFullBuilds(demoFolders);
await createAllAchives(demoFolders);
const readmeData = await getAllReadmeData(demoFolders);
const demosData = createDemoData(demoFolders);
Expand Down

0 comments on commit d6d2f3e

Please sign in to comment.