Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
snowteamer committed Sep 9, 2023
2 parents 7035686 + 8c805aa commit 98d28d4
Show file tree
Hide file tree
Showing 53 changed files with 44,849 additions and 239 deletions.
28 changes: 19 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const chalk = require('chalk')
const crypto = require('crypto')
const { exec, fork } = require('child_process')
const execP = util.promisify(exec)
const { copyFile, readFile } = require('fs/promises')
const { copyFile, readFile, writeFile } = require('fs/promises')
const fs = require('fs')
const path = require('path')
const { resolve } = path
Expand Down Expand Up @@ -118,12 +118,12 @@ module.exports = (grunt) => {
}
}

async function deployAndUpdateMainSrc (manifestDir) {
async function deployAndUpdateMainSrc (manifestDir, dest) {
if (development) {
grunt.log.writeln(chalk.underline("Running 'chel deploy'"))
const { stdout } = await execWithErrMsg(`./node_modules/.bin/chel deploy ./data ${manifestDir}/*.manifest.json`, 'error deploying contracts')
grunt.log.writeln(chalk.underline(`Running 'chel deploy' to ${dest}`))
const { stdout } = await execWithErrMsg(`./node_modules/.bin/chel deploy ${dest} ${manifestDir}/*.manifest.json`, 'error deploying contracts')
console.log(stdout)
const r = /contracts\/([^.]+)\.(?:x|[\d.]+)\.manifest.*data\/(.*)/g
const r = /contracts\/([^.]+)\.(?:x|[\d.]+)\.manifest.*\/(.*)/g
const manifests = Object.fromEntries(Array.from(stdout.replace(/\\/g, '/').matchAll(r), x => [`gi.contracts/${x[1]}`, x[2]]))
fs.writeFileSync(manifestJSON,
JSON.stringify({ manifests }, null, 2) + '\n',
Expand All @@ -136,9 +136,9 @@ module.exports = (grunt) => {
}
}

async function genManifestsAndDeploy (dir, version) {
async function genManifestsAndDeploy (dir, version, dest = './data') {
await generateManifests(dir, version)
await deployAndUpdateMainSrc(dir)
await deployAndUpdateMainSrc(dir, dest)
}

// Used by both the alias plugin and the Vue plugin.
Expand Down Expand Up @@ -183,6 +183,15 @@ module.exports = (grunt) => {
tunnel: grunt.option('tunnel') && `gi${crypto.randomBytes(2).toString('hex')}`
}

const databaseOptionBags = {
fs: {
dest: './data/'
},
sqlite: {
dest: './data/groupincome.db'
}
}

// https://esbuild.github.io/api/
const esbuildOptionBags = {
// Native options that are shared between our esbuild tasks.
Expand Down Expand Up @@ -477,7 +486,7 @@ module.exports = (grunt) => {
// it's possible for the UI to get updated without the contracts getting updated,
// so we keep their version numbers separate.
packageJSON.contractsVersion = version
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2) + '\n', 'utf8')
writeFile('package.json', JSON.stringify(packageJSON, null, 2) + '\n', 'utf8')
console.log(chalk.green('updated package.json "contractsVersion" to:'), version)
done()
})
Expand Down Expand Up @@ -604,7 +613,8 @@ module.exports = (grunt) => {
} else if (filePath.startsWith(contractsDir)) {
await buildContracts.run({ fileEventName, filePath })
await buildContractsSlim.run({ fileEventName, filePath })
await genManifestsAndDeploy(distContracts, packageJSON.contractsVersion)
const dest = databaseOptionBags[process.env.GI_PERSIST]?.dest ?? process.env.API_URL
await genManifestsAndDeploy(distContracts, packageJSON.contractsVersion, dest)
// genManifestsAndDeploy modifies manifests.json, which means we need
// to regenerate the main bundle since it imports that file
await buildMain.run({ fileEventName, filePath })
Expand Down
Loading

0 comments on commit 98d28d4

Please sign in to comment.