refactor: mobile components (#1113)

* fix(mobile): freeze web-server assets to zips for mobile 3.23.3

Mobile 3.23.3 fetches components zips from the web-server cdn. This however causes upgraded cdn versions to fail when downloading from older mobile versions. This commit instead fetches versioned zips from an external cdn based on the static version of the app requesting the asset.

Since web-server is no longer needed as a cdn, we will temporarily freeze its zip assets to those that would be requested by Mobile 3.23.3, and commit them to source control so they remain unchanged.

web-server/public/components/assets will remain as-is (dynamically copied during build time of server), and not commited to source control. This cdn directory is only used by the web app.

* chore: disable commitlint length rule

* chore: clear git cache

* refactor: use package name from package file
This commit is contained in:
Mo 2022-06-17 16:12:12 -05:00 committed by GitHub
parent 8b7b70eae7
commit 12a2369d17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 128 additions and 18 deletions

View file

@ -1,3 +1,6 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [0],
},
}

View file

@ -15,11 +15,6 @@ const __dirname = path.dirname(__filename)
console.log('Beginning packaging procedure...')
const specificFeatureIdentifier = process.argv[2]
if (specificFeatureIdentifier) {
console.log('Processing only', specificFeatureIdentifier)
}
const SourceFilesPath = path.join(__dirname, '../src/packages')
const DistDir = path.join(__dirname, '../dist')
const TmpDir = path.join(__dirname, '../tmp')
@ -108,7 +103,7 @@ const computeChecksum = async (zipPath, version) => {
}
}
const zipAndChecksumFeature = async (feature) => {
const packageFeature = async ({ feature, noZip }) => {
console.log('Processing feature', feature.identifier, '...')
const assetsLocation = `${path.join(AssetsDir, feature.identifier)}`
@ -118,6 +113,11 @@ const zipAndChecksumFeature = async (feature) => {
return
}
if (noZip) {
console.log('Input arg noZip detected; not zipping asset.')
return
}
const zipAssetsTmpLocation = `${path.join(TmpDir, feature.identifier)}`
const zipAssetsSuccess = await copyComponentAssets(feature, zipAssetsTmpLocation)
if (!zipAssetsSuccess) {
@ -138,9 +138,10 @@ const zipAndChecksumFeature = async (feature) => {
}
await (async () => {
const featuresToProcess = specificFeatureIdentifier
? [GetFeatures().find((feature) => feature.identifier === specificFeatureIdentifier)]
: GetFeatures().concat(GetDeprecatedFeatures())
const args = process.argv[2]
const noZip = args.includes('--no-zip')
const featuresToProcess = GetFeatures().concat(GetDeprecatedFeatures())
let index = 0
for (const feature of featuresToProcess) {
@ -149,7 +150,7 @@ await (async () => {
}
if (['SN|Component', 'SN|Theme'].includes(feature.content_type)) {
await zipAndChecksumFeature(feature)
await packageFeature({ feature, noZip })
} else {
console.log('Feature is not component, not packaging', feature.identifier)
}

View file

@ -121,8 +121,8 @@
"preset": "react-native"
},
"componentsCdn": {
"dev": "https://app-dev.standardnotes.com/components/zips",
"prod": "https://app.standardnotes.com/components/zips"
"dev": "https://cdn.jsdelivr.net/gh/standardnotes/app@",
"prod": "https://cdn.jsdelivr.net/gh/standardnotes/app@"
},
"detox": {
"configurations": {

View file

@ -18,7 +18,7 @@ import { Base64 } from 'js-base64'
import RNFS, { DocumentDirectoryPath } from 'react-native-fs'
import StaticServer from 'react-native-static-server'
import { unzip } from 'react-native-zip-archive'
import { componentsCdn } from '../../package.json'
import { componentsCdn, version, name } from '../../package.json'
import { MobileThemeContent } from '../Style/MobileTheme'
import { IsDev } from './Utils'
@ -74,12 +74,21 @@ export class ComponentManager extends SNComponentManager {
void this.staticServer!.stop()
}
private cdnUrlForFeature(identifier: FeatureIdentifier): string {
const cdn = IsDev ? componentsCdn.dev : componentsCdn.prod
const appVersion = version
const mobilePackageName = name
const tagPath = `${mobilePackageName}@${appVersion}`.replaceAll('@', '%40')
const url = `${cdn}${tagPath}/packages/components/dist/zips/${identifier}.zip`
this.log('Getting zip from cdn url', url)
return url
}
private downloadUrlForComponent(component: SNComponent): string | undefined {
const identifier = component.identifier
const nativeFeature = this.nativeFeatureForIdentifier(identifier)
if (nativeFeature) {
const cdn = IsDev ? componentsCdn.dev : componentsCdn.prod
return `${cdn}/${identifier}.zip`
return this.cdnUrlForFeature(identifier)
} else {
return component.package_info?.download_url
}

View file

@ -4,7 +4,7 @@ tmp
config/cap.yml
app/assets/templates/generated/
public/assets
public/components
public/components/assets
public/robots.txt
public/uploads/*
packages/!web-server/public/uploads/.keep

View file

@ -11,8 +11,8 @@
"scripts": {
"start": "bundle exec rails s -b 0.0.0.0",
"start:no-binding": "bundle exec rails s",
"build:components": "cp -r ../../node_modules/@standardnotes/components-meta/dist/. public/components/",
"build": "bundle install && yarn build:components && bundle exec rails assets:precompile"
"copy:components": "cp -r ../../node_modules/@standardnotes/components-meta/dist/assets/. public/components/assets/",
"build": "bundle install && yarn copy:components && bundle exec rails assets:precompile"
},
"dependencies": {
"@standardnotes/components-meta": "workspace:*",

View file

@ -0,0 +1,97 @@
{
"org.standardnotes.theme-midnight": {
"version": "1.2.9-alpha.3",
"base64": "a5bdee326f69be2ed11c773be2da575e5451a1981bc87829b55b947c99c1d2c5",
"binary": "3b80a51ed8d060915e29019af9bc43b5c9a96d617df1348f2e67cbe2539f34c3"
},
"org.standardnotes.theme-futura": {
"version": "1.2.10-alpha.3",
"base64": "5a7beae2dbd971b558a7bc53a98e2efeea8d0fee1c37bc6082130eb035d1f0ee",
"binary": "c0f2267f7b2f75dd336af396f880f8220720d47ecf576b23d5f4ac0b4b427e75"
},
"org.standardnotes.theme-solarized-dark": {
"version": "1.2.8-alpha.3",
"base64": "0b8aeaf0bf41d5530743e9248388624a48168bd31475588a07cfc92541860fce",
"binary": "85a2cd7e0c38e7faa2a63775270b8fefa2c3ba5b1fd2b1bb9fd46fe2fbef263f"
},
"org.standardnotes.theme-autobiography": {
"version": "1.0.5-alpha.3",
"base64": "3c0a97b950b7b85dde816145ab551f0d542d64d0da70cec8794057fec1c8da18",
"binary": "f223eacdb17e5fa47e9a62c967202d194bac9dac0af42a57dbd14b4a2ef43089"
},
"org.standardnotes.theme-focus": {
"version": "1.2.10-alpha.3",
"base64": "0aa2fe041fc09dd74d3273c95887e098f26664a6ee8498da8ee9e136614eddec",
"binary": "cee7887eeb42043016ab63376071ae0721befed20f8933683230d222053721c5"
},
"org.standardnotes.theme-titanium": {
"version": "1.2.9-alpha.3",
"base64": "d9a0c6eb1b994a14afb8592794b9fce171f08d066d35c13e13182aed26403bfb",
"binary": "279cdd97605cd3bd34f5d3c71e4a68dbc83e2f8dfb005a320dee66dbd8def80b"
},
"org.standardnotes.theme-dynamic": {
"version": "1.0.5-alpha.3",
"base64": "3f400aa35c5e48ddbbefbda1ee5840747e25aa6912c8a7cd0f4ebc9ef3e03b19",
"binary": "faa237e40b44151252bf4b74b4869a842f037806e4de80c01a37ebaf8445487e"
},
"org.standardnotes.code-editor": {
"version": "1.3.13-alpha.3",
"base64": "f15a3ed82da5790af1e216d92e751f563c507e3ce1728652937f6c39e066ec98",
"binary": "f7707318ddf98c37881521db0de24206efbddae32553432baf723bf98bf7384a"
},
"org.standardnotes.bold-editor": {
"version": "1.3.6-alpha.3",
"base64": "6596d3b4b1778bf05b900e5d8eb7793d01b9cefdcd08fa6a552c30225129c1df",
"binary": "1835c346e3abdef4a79ff8d0f5acc457b530ac226c0c0dda4322ce476dd741ad"
},
"org.standardnotes.plus-editor": {
"version": "1.6.2-alpha.3",
"base64": "41517c9fdd3b99b0eb358089f10d3c3979751111c15f439998697a7be20f2a0c",
"binary": "404863d7f1f3adf7c7ae9980bbf2f92484d5d77dca662ff4fc85fc58406bcccf"
},
"org.standardnotes.simple-markdown-editor": {
"version": "1.4.3-alpha.3",
"base64": "095cd6210b347befaf63244d3144d2c93e123f7523afee0564b816c8932ee714",
"binary": "403373dff8b9f950d9b83a45d44e764d37de98ac3baf4b9919a33bd7e9ab7d3f"
},
"org.standardnotes.advanced-markdown-editor": {
"version": "1.5.1-alpha.3",
"base64": "7e8a29a1ad98370edcfd5533e24ee2bd77c2c6be58f1942911e07285392b59b8",
"binary": "f8b47517f196e86958047258b15122e77bc61cf5ce9fcd15a42786f740d14cf6"
},
"org.standardnotes.minimal-markdown-editor": {
"version": "1.3.10-alpha.3",
"base64": "aca049de350d405cd8d2f003c7cca2ffe930f5a6b6d9047709aaf0f2d67766e4",
"binary": "801405a6a6e264524f20d8c7ef7168c4e7fc401e89fc4d9cc6cced698413564a"
},
"org.standardnotes.fancy-markdown-editor": {
"version": "1.3.7-alpha.3",
"base64": "09517fd2681c6873648563c8bbc1e07ce2d13e55f355d34b40e121f5cf8cb418",
"binary": "8704039865c2069892cacc0a0ca94df87ace74b19095f962209e8eb33fec2899"
},
"org.standardnotes.markdown-visual-editor": {
"version": "1.0.8-alpha.3",
"base64": "5c3737ad276e08c6cdca929e2e31b45a26c40c589c1199e93df898702e7ffc68",
"binary": "338e4a66f1905660eb084cf7ece6cfa6a6ad0ac9fe8efbf1a880f69e5b0cfddc"
},
"org.standardnotes.simple-task-editor": {
"version": "1.3.11-alpha.3",
"base64": "173b6137e27f034db7392dcc092b4972ae05b0357f87ea67ac1e4943868b53f0",
"binary": "d4d62982e167b1858979dbf31fbfc40d8949c29fc8d46fad04166c32f133fe17"
},
"org.standardnotes.token-vault": {
"version": "2.0.11-alpha.3",
"base64": "f223911282c1411d5dc1cbd2bd81b779ae6b41c414414eeed4bf880d69db1b50",
"binary": "61bbf7e155d08ff56ce1dc925d5c54d5681e40addf9ea13459caf2da910a248f"
},
"org.standardnotes.standard-sheets": {
"version": "1.4.5-alpha.3",
"base64": "3d945883bae018bc5a589b9269f289d3eb1abc6a267414e4538860c955c8fc9b",
"binary": "a078fcbdb25414f4e86c8ef5e1246845a78f3d1082362c1a75fe6102c0e2a625"
},
"org.standardnotes.advanced-checklist": {
"version": "0.0.2-alpha.3",
"base64": "2b6a6100e9378b5f790006ce40ece6153c769e2982dfd4ee32f861625229fb69",
"binary": "93e6e24e0f1a33328724ab222fd99e4a23cf824d93dcc6e654d27d1e988baf92"
}
}