Skip to content

Commit ad9ed2d

Browse files
committed
prebuild: fix prepare_data
1 parent 800242f commit ad9ed2d

1 file changed

Lines changed: 23 additions & 43 deletions

File tree

prepare_data.js

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { XMLHttpRequest } from 'xmlhttprequest'
55
const lime_repo = './lime-packages/'
66
const lime_pkgs_path = './lime-packages/packages/'
77
const profile_repo = './network-profiles/'
8+
const feed_repo = "https://feed.libremesh.org/"
89
let lime_feed = {}
910
let profiles_feed = {}
1011

@@ -18,15 +19,15 @@ openwrt.stable_branch = openwrt.stable_version?.substr(0,5)
1819
openwrt.oldstable_branch = openwrt.oldstable_version?.substr(0,5)
1920

2021
lime_feed = {
21-
main: await (await fetch('https://feed.libremesh.org/master/openwrt-main/x86_64/index.json')).json(),
22-
stable: await (await fetch('https://feed.libremesh.org/master/openwrt-'+openwrt.stable_branch+'/x86_64/index.json')).json(),
23-
oldstable: await (await fetch('https://feed.libremesh.org/master/openwrt-'+openwrt.oldstable_branch+'/x86_64/index.json')).json()
22+
main: await (await fetch(feed_repo+'master/openwrt-main/x86_64/index.json')).json(),
23+
stable: await (await fetch(feed_repo+'master/openwrt-'+openwrt.stable_branch+'/x86_64/index.json')).json(),
24+
oldstable: await (await fetch(feed_repo+'master/openwrt-'+openwrt.oldstable_branch+'/x86_64/index.json')).json()
2425
}
2526

2627
profiles_feed = {
27-
main: await (await fetch('https://feed.libremesh.org/profiles/openwrt-main/x86_64/index.json')).json(),
28-
stable: await (await fetch('https://feed.libremesh.org/profiles/openwrt-'+openwrt.stable_branch+'/x86_64/index.json')).json(),
29-
oldstable: await (await fetch('https://feed.libremesh.org/profiles/openwrt-'+openwrt.oldstable_branch+'/x86_64/index.json')).json()
28+
main: await (await fetch(feed_repo+'profiles/openwrt-main/x86_64/index.json')).json(),
29+
stable: await (await fetch(feed_repo+'profiles/openwrt-'+openwrt.stable_branch+'/x86_64/index.json')).json(),
30+
oldstable: await (await fetch(feed_repo+'profiles/openwrt-'+openwrt.oldstable_branch+'/x86_64/index.json')).json()
3031
}
3132

3233
async function copyFiles(from_dir, to_dir, from_file, to_file) {
@@ -86,6 +87,15 @@ async function generateIndexMd(indexMd_dir, pkg, _descr, _readme, _makefile, _ex
8687
fs.writeFileSync(indexMd_dir+pkg+'/index.md', file)
8788
}
8889

90+
function generateBuildInfo(feed, pa, path) {
91+
['main', 'stable', 'oldstable'].forEach(branch => {
92+
Object.entries(feed[branch].packages).find(p => {
93+
if (p[0] === pa) {
94+
fs.writeFileSync('./docs/'+path+'/'+pa+'/.built_'+branch, p[1])
95+
}
96+
})
97+
})
98+
}
8999

90100
async function setupPackages() {
91101
console.log('Copying lime-packages')
@@ -99,16 +109,17 @@ async function setupPackages() {
99109
const from_dir = lime_pkgs_path+pa+'/'
100110
const to_dir = './docs/packages/'+pa+'/'
101111

102-
const makefile_path = to_dir+'/Makefile'
103-
const makefileExist = fs.existsSync(makefile_path)
104112
let readme = ''
105113
let description = ''
106114
let makefile = ''
107115

108116
await copyFiles(from_dir, to_dir, 'Makefile')
109117

110-
if (['lime-app', 'shared-state-async'].includes(pa)) {
118+
const makefile_path = to_dir+'/Makefile'
119+
const makefileExist = fs.existsSync(makefile_path)
111120

121+
if (['lime-app', 'shared-state-async'].includes(pa)) {
122+
// skip packages with external url
112123
} else {
113124
await copyFiles(from_dir, to_dir, 'README.md')
114125
await copyFiles(from_dir, to_dir, 'README', 'README.md')
@@ -158,25 +169,10 @@ async function setupPackages() {
158169
generateIndexMd('./docs/packages/', pa, description, readme, makefile)
159170
}
160171

161-
Object.entries(lime_feed.main.packages).find(p => {
162-
if (p[0] === pa) {
163-
fs.writeFileSync('./docs/packages/'+pa+'/.built_main', p[1])
164-
}
165-
})
166-
Object.entries(lime_feed.stable.packages).find(p => {
167-
if (p[0] === pa) {
168-
fs.writeFileSync('./docs/packages/'+pa+'/.built_stable', p[1])
169-
}
170-
})
171-
Object.entries(lime_feed.oldstable.packages).find(p => {
172-
if (p[0] === pa) {
173-
fs.writeFileSync('./docs/packages/'+pa+'/.built_oldstable', p[1])
174-
}
175-
})
172+
generateBuildInfo(lime_feed, pa, 'packages')
176173
})
177174
}
178175

179-
180176
function setupProfiles() {
181177
console.log('Copying network-profiles communities and packages')
182178
// let profiles = []
@@ -206,7 +202,7 @@ function setupProfiles() {
206202
readme = fs.readFileSync(readme_path, { encoding: 'utf-8', flag: 'r'}) || ''
207203
if (readme !== '') {
208204
readme = readme.replace(/^# .*/, '')
209-
generateIndexMd('./docs/profiles/communities/', c, '', readme, '')
205+
generateIndexMd('./docs/profiles/communities/', c, '', readme)
210206
}
211207
}
212208

@@ -272,23 +268,7 @@ function setupProfiles() {
272268
}
273269
generateIndexMd('./docs/profiles/packages/', profile_name, description, readme, makefile, extra)
274270
}
275-
276-
Object.entries(profiles_feed.main.packages).find(p => {
277-
if (p[0] === profile_name) {
278-
fs.writeFileSync(to_dir+'.built_main', p[1])
279-
}
280-
})
281-
Object.entries(profiles_feed.stable.packages).find(p => {
282-
if (p[0] === profile_name) {
283-
fs.writeFileSync(to_dir+'.built_stable', p[1])
284-
}
285-
})
286-
Object.entries(profiles_feed.oldstable.packages).find(p => {
287-
if (p[0] === profile_name) {
288-
fs.writeFileSync(to_dir+'.built_oldstable', p[1])
289-
}
290-
})
291-
271+
generateBuildInfo(profiles_feed, profile_name, 'profiles/packages')
292272
})
293273
})
294274
// console.log(profiles_list)

0 commit comments

Comments
 (0)