-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GG-173 Automate latest releases on home page (#1253)
* set up script * save * update script * fix * remove console logs * clean up * remove console.log * update release versions * fix 404 page for long links * update logic
- Loading branch information
1 parent
c906076
commit 9540f3c
Showing
9 changed files
with
120 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const url = require('url'); | ||
const { iterateOverFiles, getLatestVersion, formatDate } = require('./home/helper'); | ||
const { releases } = require('../releases'); | ||
|
||
function getNewReleases() { | ||
const jsonDirectory = path.join(process.cwd()); | ||
const docsPath = `${jsonDirectory}/docs`; | ||
const basePath = `${url.pathToFileURL(jsonDirectory).toString()}/docs`; | ||
const data = []; | ||
|
||
iterateOverFiles([docsPath], basePath, data, getLatestVersion); | ||
|
||
try { | ||
data.forEach( | ||
(item) => | ||
(releases[item.platform] = { version: item.version, date: formatDate(item.date) }) | ||
); | ||
} catch (e) { | ||
console.log('Error in updating object', e); | ||
} | ||
|
||
try { | ||
fs.writeFileSync( | ||
'releases.js', | ||
`exports.releases = releases = ${JSON.stringify(releases)}`, | ||
'utf-8' | ||
); | ||
} catch (e) { | ||
console.log('Error in logging data', e); | ||
} | ||
} | ||
|
||
module.exports = { getNewReleases }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
|
||
const { getPlatform, getHeadings } = require('../algolia/helper'); | ||
|
||
exports.iterateOverFiles = function iterateOverFiles( | ||
folderPaths, | ||
basePath, | ||
data, | ||
getLatestVersion | ||
) { | ||
folderPaths.map((folderPath) => { | ||
const contents = fs.readdirSync(folderPath); | ||
const subFolders = contents.filter((content) => | ||
fs.lstatSync(path.resolve(folderPath, content)).isDirectory() | ||
); | ||
const subFolderPaths = subFolders.map((subFolder) => path.resolve(folderPath, subFolder)); | ||
|
||
if (subFolderPaths.length) | ||
iterateOverFiles(subFolderPaths, basePath, data, getLatestVersion); | ||
|
||
contents.forEach((content) => { | ||
if (content.includes('release-notes')) { | ||
const objArray = getLatestVersion(content, folderPath, basePath); | ||
data.push(objArray); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
exports.formatDate = function formatDate(string) { | ||
return new Date(string).toLocaleDateString('en-us', { | ||
year: 'numeric', | ||
month: 'long', | ||
day: '2-digit' | ||
}); | ||
}; | ||
|
||
exports.getLatestVersion = function getLatestVersion(content, folderPath, basePath) { | ||
let link = url.pathToFileURL(path.resolve(folderPath, content)).toString().split(basePath)[1]; | ||
const fileContent = fs.readFileSync(path.resolve(folderPath, content)).toString(); | ||
const platform = getPlatform(link); | ||
const headers = getHeadings(fileContent); | ||
return { | ||
platform: platform === 'JavaScript' ? 'Web' : platform, | ||
version: | ||
platform === 'JavaScript' | ||
? headers[1] | ||
: platform === 'Server-side' | ||
? headers[0] | ||
: headers[0].split('-')[0].split(' ')[0], | ||
date: | ||
platform === 'JavaScript' | ||
? headers[1] | ||
: platform === 'Server-side' | ||
? headers[0] | ||
: headers[0].split(' - ')[1] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,8 @@ | ||
const PLATFORM_WEB = 'Web'; | ||
const PLATFORM_SERVER = 'Server'; | ||
const PLATFORM_IOS = 'iOS'; | ||
const PLATFORM_ANDROID = 'Android'; | ||
const PLATFORM_REACT_NATIVE = 'React Native'; | ||
const PLATFORM_FLUTTER = 'Flutter'; | ||
|
||
|
||
export const releases = [ | ||
{ | ||
platform: PLATFORM_ANDROID, | ||
version: 'v2.5.7', | ||
date: 'January 20, 2023' | ||
}, | ||
{ | ||
platform: PLATFORM_IOS, | ||
version: '0.6.1', | ||
date: 'January 19, 2023' | ||
}, | ||
{ | ||
platform: PLATFORM_REACT_NATIVE, | ||
version: '1.1.1', | ||
date: 'December 22, 2022' | ||
}, | ||
{ | ||
platform: PLATFORM_WEB, | ||
version: '2023-02-03', | ||
date: 'February 02, 2023' | ||
}, | ||
{ | ||
platform: PLATFORM_FLUTTER, | ||
version: '1.3.0', | ||
date: 'February 01, 2023' | ||
}, | ||
{ | ||
platform: PLATFORM_SERVER, | ||
version: '2023-01-23', | ||
date: 'January 23, 2023' | ||
} | ||
]; | ||
exports.releases = releases = { | ||
Android: { version: 'v2.5.7', date: 'January 20, 2023' }, | ||
iOS: { version: '0.6.3', date: 'February 07, 2023' }, | ||
'React Native': { version: '1.1.1', date: 'December 22, 2022' }, | ||
Web: { version: '2023-02-03', date: 'February 02, 2023' }, | ||
Flutter: { version: '1.3.0', date: 'February 01, 2023' }, | ||
'Server-side': { version: '2023-01-31', date: 'January 31, 2023' } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getNewReleases } = require('./lib/getNewReleases'); | ||
|
||
getNewReleases(); |
9540f3c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
100ms-docs – ./
100ms-docs-git-main-100mslive.vercel.app
100ms-docs.vercel.app
docs.100ms.live
100ms-docs-100mslive.vercel.app