Skip to content

Commit

Permalink
Split boostrap scripts between creation and publication
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulLeCam committed Oct 8, 2021
1 parent 6c29498 commit fa35125
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 199 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Example Web app using [Glaze libraries](https://developers.ceramic.network/tools

1. Install dependencies using `yarn install`
1. Start a local Ceramic node using `yarn ceramic`
1. Run the bootstrap script using `yarn bootstrap`
1. Publish the model to your Ceramic node with `yarn publish-model`

## Scripts

Expand All @@ -21,6 +21,12 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

Builds the app for production to the `build` folder.

### `yarn create-model`

Runs the `create-model.mjs` script.
This is only needed to make changes to the model used by the app.
A hex-encoded 32-byte `SEED` environment variable must be present to create a key DID for the model when running the script.

## License

Apache-2.0 OR MIT
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"private": true,
"homepage": "https://ceramicstudio.github.io/glaze-demo-app",
"scripts": {
"bootstrap": "node --experimental-json-modules ./bootstrap.mjs",
"ceramic": "ceramic daemon",
"create-model": "node --experimental-json-modules ./scripts/create-model.mjs",
"publish-model": "node --experimental-json-modules ./scripts/publish-model.mjs",
"start": "webpack serve --mode development",
"build": "del build && cp -r public build && webpack --mode production",
"predeploy": "npm run build",
"predeploy": "yarn build",
"deploy": "gh-pages -d build"
},
"dependencies": {
"@ceramicnetwork/http-client": "^1.2.1",
"@ceramicnetwork/stream-tile": "^1.3.0",
"@ceramicnetwork/http-client": "^1.3.0",
"@ceramicnetwork/stream-tile": "^1.3.1",
"@glazed/datamodel": "^0.1.2",
"@glazed/did-datastore": "^0.1.4",
"@material-ui/core": "^4.11.3",
Expand All @@ -27,22 +28,22 @@
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@ceramicnetwork/cli": "^1.3.1",
"@ceramicnetwork/common": "^1.4.0",
"@ceramicnetwork/cli": "^1.4.0",
"@ceramicnetwork/common": "^1.5.0",
"@glazed/devtools": "^0.1.3",
"@types/node": "^16.9.0",
"@types/react": "^17.0.20",
"@types/node": "^16.10.3",
"@types/react": "^17.0.27",
"@types/react-dom": "^17.0.2",
"css-loader": "^6.2.0",
"css-loader": "^6.3.0",
"del-cli": "^4.0.1",
"esbuild-loader": "^2.15.1",
"gh-pages": "^3.1.0",
"html-webpack-plugin": "^5.3.2",
"stream-browserify": "^3.0.0",
"style-loader": "^3.2.1",
"typescript": "^4.4.2",
"webpack": "^5.52.0",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.1.1"
"style-loader": "^3.3.0",
"typescript": "^4.4.3",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "^4.3.1"
}
}
13 changes: 9 additions & 4 deletions bootstrap.mjs → scripts/create-model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Ed25519Provider } from 'key-did-provider-ed25519'
import { getResolver } from 'key-did-resolver'
import { fromString } from 'uint8arrays'

if (!process.env.SEED) {
throw new Error('Missing SEED environment variable')
}

// The seed must be provided as an environment variable
const seed = fromString(process.env.SEED, 'base16')
// Create and authenticate the DID
Expand Down Expand Up @@ -85,7 +89,8 @@ await manager.createTile(
)

// Write model to JSON file
const model = await manager.toPublished()
await writeFile('./src/model.json', JSON.stringify(model))

console.log('Model written to src/model.json file:', model)
await writeFile(
new URL('model.json', import.meta.url),
JSON.stringify(manager.toJSON()),
)
console.log('Encoded model written to scripts/model.json file')
1 change: 1 addition & 0 deletions scripts/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"schemas":{"kjzl6cwe1jw1490hmhhj0l5lsz821dr4vxie4316cmtnl11kzoji004qy2no7di":{"alias":"Note","commits":[{"jws":{"payload":"AXESIMEmnG5lE1iERPbAx-_QZCfLBFu9kLLnlfhdyDwUsrhk","signatures":[{"signature":"T37BCu9clWSW9xP2--47s0yOM2L9S9QkBqHF-rmNMghJSatpe1NKA_Qxa7tbUqm8pj-DI6D635uEtSkG9GRvBw","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3IxWWFQWEZ3d1p4R0VpM0FDVDJwUzZMcFJxa3VwWDlqMmpoOUpnN1FSQTYyI3o2TWtyMVlhUFhGd3daeEdFaTNBQ1QycFM2THBScWt1cFg5ajJqaDlKZzdRUkE2MiJ9"}],"link":"bafyreigbe2og4zitlccej5way7x5azbhzmcfxpmqwltzl6c5za6bjmvymq"},"linkedBlock":"omRkYXRhpGR0eXBlZm9iamVjdGV0aXRsZWROb3RlZyRzY2hlbWF4J2h0dHA6Ly9qc29uLXNjaGVtYS5vcmcvZHJhZnQtMDcvc2NoZW1hI2pwcm9wZXJ0aWVzomRkYXRlpGR0eXBlZnN0cmluZ2V0aXRsZWRkYXRlZmZvcm1hdGlkYXRlLXRpbWVpbWF4TGVuZ3RoGB5kdGV4dKNkdHlwZWZzdHJpbmdldGl0bGVkdGV4dGltYXhMZW5ndGgZD6BmaGVhZGVyomZ1bmlxdWVwMXZBMzhTRjd0VVkyVkNoS2tjb250cm9sbGVyc4F4OGRpZDprZXk6ejZNa3IxWWFQWEZ3d1p4R0VpM0FDVDJwUzZMcFJxa3VwWDlqMmpoOUpnN1FSQTYy"}],"dependencies":{},"version":"k3y52l7qbv1fry83hbwcn86fv22hahtsyr2asd1kd5uavpjf99qio00xrmawc4g00"},"kjzl6cwe1jw14bmed6ow7dwwiprz12durjg9f9a62n607j31paj4ecaidqhfdqf":{"alias":"Notes","commits":[{"jws":{"payload":"AXESIIBRWUbSGbgsBOvKarqUosu9tfjq_FpGEcVoXxJtes98","signatures":[{"signature":"VW0kpicwQYNJHS7tzW8WmYBnIIRG8UbeddTlkIAUMVLVXU75CBxDn0118C4Pk6VJHCdQFk9fdUhSh_3QEJMuCA","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3IxWWFQWEZ3d1p4R0VpM0FDVDJwUzZMcFJxa3VwWDlqMmpoOUpnN1FSQTYyI3o2TWtyMVlhUFhGd3daeEdFaTNBQ1QycFM2THBScWt1cFg5ajJqaDlKZzdRUkE2MiJ9"}],"link":"bafyreieakfmunuqzxawaj26knk5jjiwlxw27r2x4ljdbdrlil4jg26wppq"},"linkedBlock":"omRkYXRhpGR0eXBlZm9iamVjdGV0aXRsZWlOb3Rlc0xpc3RnJHNjaGVtYXgnaHR0cDovL2pzb24tc2NoZW1hLm9yZy9kcmFmdC0wNy9zY2hlbWEjanByb3BlcnRpZXOhZW5vdGVzo2R0eXBlZWFycmF5ZWl0ZW1zo2R0eXBlZm9iamVjdGV0aXRsZWhOb3RlSXRlbWpwcm9wZXJ0aWVzomJpZKRkdHlwZWZzdHJpbmdncGF0dGVybngcXmNlcmFtaWM6Ly8uKyhcP3ZlcnNpb249LispP2gkY29tbWVudHhVY2lwODg6cmVmOmNlcmFtaWM6Ly9rM3k1Mmw3cWJ2MWZyeTgzaGJ3Y244NmZ2MjJoYWh0c3lyMmFzZDFrZDV1YXZwamY5OXFpbzAweHJtYXdjNGcwMGltYXhMZW5ndGgYlmV0aXRsZaNkdHlwZWZzdHJpbmdldGl0bGVldGl0bGVpbWF4TGVuZ3RoGGRldGl0bGVlbm90ZXNmaGVhZGVyomZ1bmlxdWVwMmVGWWxVSVViT0V1ZHBPaGtjb250cm9sbGVyc4F4OGRpZDprZXk6ejZNa3IxWWFQWEZ3d1p4R0VpM0FDVDJwUzZMcFJxa3VwWDlqMmpoOUpnN1FSQTYy"}],"dependencies":{"notes.id":["kjzl6cwe1jw1490hmhhj0l5lsz821dr4vxie4316cmtnl11kzoji004qy2no7di"]},"version":"k3y52l7qbv1fryqna5rl10ixz93ax3kyirubn0i0b6sqphjpo3uvz9zeqpobxdnuo"}},"definitions":{"kjzl6cwe1jw147aa287o28wvfe02c8v8g74hf1qip18orcww7qfe0xzupr7z4kc":{"alias":"notes","commits":[{"jws":{"payload":"AXESIKoasDAU_KF0Tlh1lRplCC9gvez3HCfec-HUdazdhxhA","signatures":[{"signature":"kpaUtI6pxoo6aQ-2M63rVuWiJ5aNRvWQ9R6rnKbgd0j0fmH2fUmIaFbhVI_wFSYaukztS8Qj-dFdM75c8ak9Bw","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3IxWWFQWEZ3d1p4R0VpM0FDVDJwUzZMcFJxa3VwWDlqMmpoOUpnN1FSQTYyI3o2TWtyMVlhUFhGd3daeEdFaTNBQ1QycFM2THBScWt1cFg5ajJqaDlKZzdRUkE2MiJ9"}],"link":"bafyreifkdkydafh4uf2e4wdvsungkcbpmc66z5y4e7phhyouowwn3byyia"},"linkedBlock":"omRkYXRho2RuYW1lZW5vdGVzZnNjaGVtYXhLY2VyYW1pYzovL2szeTUybDdxYnYxZnJ5cW5hNXJsMTBpeHo5M2F4M2t5aXJ1Ym4waTBiNnNxcGhqcG8zdXZ6OXplcXBvYnhkbnVva2Rlc2NyaXB0aW9ucVNpbXBsZSB0ZXh0IG5vdGVzZmhlYWRlcqNmc2NoZW1heEtjZXJhbWljOi8vazN5NTJsN3FidjFmcnkxZnA0czBud2RhcmgwdmFodXNhcnBwb3NnZXZ5MHBlbWl5a3ltZDJvcmQ2c3d0aGFyY3dmdW5pcXVlcDdFaFVrTzJwQUJuV0wzUU5rY29udHJvbGxlcnOBeDhkaWQ6a2V5Ono2TWtyMVlhUFhGd3daeEdFaTNBQ1QycFM2THBScWt1cFg5ajJqaDlKZzdRUkE2Mg=="}],"schema":"kjzl6cwe1jw14bmed6ow7dwwiprz12durjg9f9a62n607j31paj4ecaidqhfdqf","version":"k3y52l7qbv1frxvt3juej3zdrhfkgn32436nvv0cky0ts2jtx2zxfqpqyf5kpsglc"}},"tiles":{"kjzl6cwe1jw14b9lk9cc8w0xhpu9ywc28rwp2kqtce2kp2y7ek5ozrxzaxkclgm":{"alias":"placeholderNote","commits":[{"jws":{"payload":"AXESIOaqzpSABACBne_uED6aYbqPaU1ltRYgtb4opErIW7My","signatures":[{"signature":"bO9x7TQTLjyBuOYT9htUcQ6uPypybeefPlal1v3WknnmhEf_fgD8SmshkWEMUiBfDN_EKve2XK7wTBzoEDEkAw","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa3IxWWFQWEZ3d1p4R0VpM0FDVDJwUzZMcFJxa3VwWDlqMmpoOUpnN1FSQTYyI3o2TWtyMVlhUFhGd3daeEdFaTNBQ1QycFM2THBScWt1cFg5ajJqaDlKZzdRUkE2MiJ9"}],"link":"bafyreihgvlhjjaaeacaz337oca7juyn2r5uu2znvcyqllpriurfmqw5tgi"},"linkedBlock":"omRkYXRhoWR0ZXh0eC5UaGlzIGlzIGEgcGxhY2Vob2xkZXIgZm9yIHRoZSBub3RlIGNvbnRlbnRzLi4uZmhlYWRlcqNmc2NoZW1heEtjZXJhbWljOi8vazN5NTJsN3FidjFmcnk4M2hid2NuODZmdjIyaGFodHN5cjJhc2Qxa2Q1dWF2cGpmOTlxaW8wMHhybWF3YzRnMDBmdW5pcXVlcEo4NmdqRlpyUzNIY2NDMlJrY29udHJvbGxlcnOBeDhkaWQ6a2V5Ono2TWtyMVlhUFhGd3daeEdFaTNBQ1QycFM2THBScWt1cFg5ajJqaDlKZzdRUkE2Mg=="}],"schema":"kjzl6cwe1jw1490hmhhj0l5lsz821dr4vxie4316cmtnl11kzoji004qy2no7di","version":"k3y52l7qbv1fryo49c2fr37qm5zraw5xryegiabioo42b6cz8njchqepn1qopkm4g"}}}
19 changes: 19 additions & 0 deletions scripts/publish-model.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { readFile, writeFile } from 'node:fs/promises'
import { CeramicClient } from '@ceramicnetwork/http-client'
import { ModelManager } from '@glazed/devtools'

// Connect to the local Ceramic node
const ceramic = new CeramicClient('http://localhost:7007')

// Load and create a manager for the model
const bytes = await readFile(new URL('model.json', import.meta.url))
const manager = ModelManager.fromJSON(ceramic, JSON.parse(bytes.toString()))

// Write model to JSON file
const model = await manager.toPublished()
await writeFile(
new URL('../src/model.json', import.meta.url),
JSON.stringify(model),
)

console.log('Model written to src/model.json file:', model)
2 changes: 1 addition & 1 deletion src/model.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"definitions":{"notes":"kjzl6cwe1jw149m2c3i8hfwrpkd9ra5mbwx07chjnquvlce6kjvpjpuofmgkzhh"},"schemas":{"Note":"ceramic://k3y52l7qbv1fryduaidzltlses3t3ceq9qwhicaz7f40nthnegrnx62lrv71mfs3k","Notes":"ceramic://k3y52l7qbv1fry2ljyjbhwqecjudaeiuxclbvbd8ow896rxud6xsgi8h3r6b4uhhc"},"tiles":{"placeholderNote":"kjzl6cwe1jw148ui9wvuw7u056jon3kkmlk9iqxahndlhkdqtsfyhhoi9s9ol7l"}}
{"definitions":{"notes":"kjzl6cwe1jw147aa287o28wvfe02c8v8g74hf1qip18orcww7qfe0xzupr7z4kc"},"schemas":{"Note":"ceramic://k3y52l7qbv1fry83hbwcn86fv22hahtsyr2asd1kd5uavpjf99qio00xrmawc4g00","Notes":"ceramic://k3y52l7qbv1fryqna5rl10ixz93ax3kyirubn0i0b6sqphjpo3uvz9zeqpobxdnuo"},"tiles":{"placeholderNote":"kjzl6cwe1jw14b9lk9cc8w0xhpu9ywc28rwp2kqtce2kp2y7ek5ozrxzaxkclgm"}}
Loading

0 comments on commit fa35125

Please sign in to comment.