@@ -7,7 +7,7 @@ import simpleGit from "simple-git";
77
88const required = [
99 "MENDIX_MOBILE_DOCS_PR_GITHUB_PAT" ,
10- "NATIVE_TEMPLATE_VERSION_BUMP_TYPE " ,
10+ "STUDIO_PRO_MAJOR " ,
1111] ;
1212
1313const missing = required . filter ( ( k ) => ! process . env [ k ] ) ;
@@ -20,15 +20,12 @@ const __filename = fileURLToPath(import.meta.url);
2020const __dirname = path . dirname ( __filename ) ;
2121const DOCS_CLONE_PREFIX = "mendix-docs-" ;
2222
23- const NATIVE_TEMPLATE_VERSION_BUMP_TYPE =
24- process . env . NATIVE_TEMPLATE_VERSION_BUMP_TYPE ; // patch, minor, major
25-
2623const MENDIX_MOBILE_DOCS_PR_GITHUB_PAT =
2724 process . env . MENDIX_MOBILE_DOCS_PR_GITHUB_PAT ;
2825
29- const NATIVE_TEMPLATE_VERSION = determineVersionFromBumpType (
30- NATIVE_TEMPLATE_VERSION_BUMP_TYPE ,
31- ) ;
26+ const NATIVE_TEMPLATE_VERSION = readVersionFromPackageJson ( ) ;
27+ const NATIVE_TEMPLATE_MAJOR = NATIVE_TEMPLATE_VERSION . split ( "." ) [ 0 ] ;
28+ const STUDIO_PRO_MAJOR = process . env . STUDIO_PRO_MAJOR ;
3229
3330const GIT_AUTHOR_NAME = "MendixMobile" ;
3431const GIT_AUTHOR_EMAIL = "moo@mendix.com" ;
@@ -39,11 +36,8 @@ const DOCS_REPO_OWNER = "MendixMobile";
3936const DOCS_UPSTREAM_OWNER = "mendix" ;
4037const DOCS_BRANCH_NAME = `update-native-template-release-notes-v${ NATIVE_TEMPLATE_VERSION } ` ;
4138
42- const TARGET_FILE =
43- "content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-11-parent/nt-17-rn.md" ;
44- // Other options:
45- // - content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-11-parent/nt-15-rn.md
46- // - content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-11-parent/nt-16-rn.md
39+ const DOCS_PARENT_DIR = `content/en/docs/releasenotes/mobile/native-template/nt-studio-pro-${ STUDIO_PRO_MAJOR } -parent` ;
40+ const TARGET_FILE = `${ DOCS_PARENT_DIR } /nt-${ NATIVE_TEMPLATE_MAJOR } -rn.md` ;
4741
4842const octokit = new Octokit ( { auth : MENDIX_MOBILE_DOCS_PR_GITHUB_PAT } ) ;
4943
@@ -61,8 +55,31 @@ function extractUnreleasedChangelog() {
6155 return unreleasedContent ;
6256}
6357
58+ function buildFrontmatter ( ) {
59+ return `---\ntitle: "Native Template ${ NATIVE_TEMPLATE_MAJOR } "\nurl: /releasenotes/mobile/nt-${ NATIVE_TEMPLATE_MAJOR } -rn/\nweight: 1\ndescription: "Native Template ${ NATIVE_TEMPLATE_MAJOR } "\n---` ;
60+ }
61+
6462// Docs
6563function injectUnreleasedToDoc ( docPath , unreleasedContent ) {
64+ if ( ! fs . existsSync ( DOCS_PARENT_DIR ) ) {
65+ throw new Error (
66+ `Parent directory not found: ${ DOCS_PARENT_DIR } \nA new Studio Pro parent folder requires manual setup in the docs repo.` ,
67+ ) ;
68+ }
69+
70+ const date = new Date ( ) ;
71+ const formattedDate = date . toLocaleDateString ( "en-US" , {
72+ year : "numeric" ,
73+ month : "short" ,
74+ day : "numeric" ,
75+ } ) ;
76+ const releaseHeading = `## ${ NATIVE_TEMPLATE_VERSION } \n\n**Release date: ${ formattedDate } **` ;
77+
78+ if ( ! fs . existsSync ( docPath ) ) {
79+ console . log ( `${ docPath } not found — creating new file for Native Template ${ NATIVE_TEMPLATE_MAJOR } .` ) ;
80+ return `${ buildFrontmatter ( ) } \n\n${ releaseHeading } \n\n${ unreleasedContent } \n` ;
81+ }
82+
6683 const doc = fs . readFileSync ( docPath , "utf-8" ) ;
6784 const frontmatterMatch = doc . match ( / ^ - - - [ \s \S ] * ?- - - / ) ;
6885 if ( ! frontmatterMatch ) throw new Error ( "Frontmatter not found!" ) ;
@@ -79,15 +96,7 @@ function injectUnreleasedToDoc(docPath, unreleasedContent) {
7996 ? rest . slice ( firstReleaseHeadingIndex ) . trimStart ( )
8097 : rest . trimStart ( ) ;
8198
82- const date = new Date ( ) ;
83- const formattedDate = date . toLocaleDateString ( "en-US" , {
84- year : "numeric" ,
85- month : "short" ,
86- day : "numeric" ,
87- } ) ;
88- const title = `## ${ NATIVE_TEMPLATE_VERSION } \n\n**Release date: ${ formattedDate } **` ;
89-
90- return `${ frontmatter } \n\n${ beforeReleases } ${ title } \n\n${ unreleasedContent } \n\n${ releaseSections } ` ;
99+ return `${ frontmatter } \n\n${ beforeReleases } ${ releaseHeading } \n\n${ unreleasedContent } \n\n${ releaseSections } ` ;
91100}
92101
93102// This file exists only in the fork (MendixMobile/docs) and not in upstream (mendix/docs).
@@ -167,31 +176,12 @@ async function updateNTReleaseNotes(unreleasedContent) {
167176 }
168177}
169178
170- function determineVersionFromBumpType ( bumpType = "patch" ) {
179+ function readVersionFromPackageJson ( ) {
171180 const packageJsonPath = path . resolve (
172181 path . join ( __dirname , ".." , ".." , "package.json" ) ,
173182 ) ;
174183 const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , "utf-8" ) ) ;
175- const currentVersion = packageJson . version ;
176-
177- const [ major , minor , patch ] = currentVersion . split ( "." ) . map ( Number ) ;
178- let newVersion ;
179- switch ( bumpType ) {
180- case "major" :
181- newVersion = `${ major + 1 } .0.0` ;
182- break ;
183- case "minor" :
184- newVersion = `${ major } .${ minor + 1 } .0` ;
185- break ;
186- case "patch" :
187- newVersion = `${ major } .${ minor } .${ patch + 1 } ` ;
188- break ;
189- default :
190- throw new Error (
191- `Invalid bump type for docs release notes: ${ bumpType } . Expected one of: patch, minor, major.` ,
192- ) ;
193- }
194- return newVersion ;
184+ return packageJson . version ;
195185}
196186
197187( async ( ) => {
0 commit comments