You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @returns {Promise<Object>} An object containing all user inputs.
34
34
*/
35
35
asyncfunctiongetUserInputs(){
36
-
console.log('\n--- Project Setup ---');
37
-
console.log('Let\'s personalize your new repository.');
38
-
console.log('Please provide the following information:');
39
-
40
-
constinputs={};
41
-
42
-
inputs.projectName=awaitaskQuestion('1. Enter the name for your new project (e.g., my-awesome-app): ');
43
-
inputs.projectDescription=awaitaskQuestion('2. Enter a short description for your project: ');
44
-
inputs.projectKeywords=awaitaskQuestion('3. Enter keywords for your project, separated by commas (e.g., javascript, web, utility): ');
45
-
inputs.authorName=awaitaskQuestion('4. Enter the author\'s name (e.g., John Doe or My Company Inc.): ');
46
-
inputs.contactEmail=awaitaskQuestion('5. Enter a contact email for your project (e.g., contact@yourproject.com): ');
47
-
48
-
constcurrentYear=newDate().getFullYear();
49
-
inputs.licenseYear=(awaitaskQuestion(`6. Enter the copyright year (default: ${currentYear}): `))||currentYear.toString();// Ensure string for replacement
50
-
51
-
inputs.githubUsername=awaitaskQuestion('7. Enter your GitHub username or organization name (e.g., octocat): ');
52
-
inputs.codecovToken=awaitaskQuestion('8. Enter your Codecov token (optional, leave blank if not using): ');
53
-
54
-
rl.close();// Close the readline interface after all questions are asked
55
-
returninputs;
36
+
console.log('\n--- Project Setup ---');
37
+
console.log("Let's personalize your new repository.");
38
+
console.log('Please provide the following information:');
39
+
40
+
constinputs={};
41
+
42
+
inputs.projectName=awaitaskQuestion(
43
+
'1. Enter the name for your new project (e.g., my-awesome-app): '
44
+
);
45
+
inputs.projectDescription=awaitaskQuestion(
46
+
'2. Enter a short description for your project: '
47
+
);
48
+
inputs.projectKeywords=awaitaskQuestion(
49
+
'3. Enter keywords for your project, separated by commas (e.g., javascript, web, utility): '
50
+
);
51
+
inputs.authorName=awaitaskQuestion(
52
+
"4. Enter the author's name (e.g., John Doe or My Company Inc.): "
53
+
);
54
+
inputs.contactEmail=awaitaskQuestion(
55
+
'5. Enter a contact email for your project (e.g., contact@yourproject.com): '
56
+
);
57
+
58
+
constcurrentYear=newDate().getFullYear();
59
+
inputs.licenseYear=
60
+
(awaitaskQuestion(
61
+
`6. Enter the copyright year (default: ${currentYear}): `
62
+
))||currentYear.toString();// Ensure string for replacement
63
+
64
+
inputs.githubUsername=awaitaskQuestion(
65
+
'7. Enter your GitHub username or organization name (e.g., octocat): '
66
+
);
67
+
inputs.codecovToken=awaitaskQuestion(
68
+
'8. Enter your Codecov token (optional, leave blank if not using): '
69
+
);
70
+
71
+
rl.close();// Close the readline interface after all questions are asked
72
+
returninputs;
56
73
}
57
74
58
75
/**
59
76
* Processes each file, replacing placeholders with user inputs.
60
77
* @param {Object} inputs An object containing all user inputs.
61
78
*/
62
79
asyncfunctionprocessFiles(inputs){
63
-
for(constfileoffilesToModify){
64
-
constfilePath=path.join(process.cwd(),file);// Assumes script is run from repo root
65
-
console.log(`\nProcessing ${file}...`);
66
-
67
-
try{
68
-
letcontent=fs.readFileSync(filePath,'utf8');
69
-
70
-
// --- Generic Replacements (order matters if placeholders overlap) ---
constnewPostTemplateSetupContent=`## Post-Template Setup\n\nAfter creating your repository from this template, you've successfully run this setup script to personalize your project. You're ready to start building!\n\n*(This section was updated by the setup script.)*`;
// Handle keywords array: convert comma-separated string to array
128
+
if(inputs.projectKeywords){
129
+
projectJson.keywords=inputs.projectKeywords
130
+
.split(',')
131
+
.map((kw)=>kw.trim())
132
+
.filter((kw)=>kw.length>0);
133
+
}else{
134
+
projectJson.keywords=[];// Set to empty array if no keywords provided
135
+
}
136
+
137
+
content=JSON.stringify(projectJson,null,2);// Pretty print JSON with 2 spaces
138
+
}
139
+
140
+
// --- Specific handling for README.md ---
141
+
if(file==='README.md'){
142
+
// Correct the LICENSE link from LICENSE.md to LICENSE
143
+
content=content.replace(
144
+
/\[LICENSE\]\(LICENSE\.md\)/g,
145
+
'[LICENSE](LICENSE)'
146
+
);
147
+
148
+
// Update the 'Post-Template Setup' section
149
+
// This regex captures the section content up to the next '##' heading or end of file
150
+
constpostTemplateSetupRegex=
151
+
/(##Post-TemplateSetup[\s\S]*?)(?=##|$)/;
152
+
constnewPostTemplateSetupContent=`## Post-Template Setup\n\nAfter creating your repository from this template, you've successfully run this setup script to personalize your project. You're ready to start building!\n\n*(This section was updated by the setup script.)*`;
153
+
154
+
if(content.match(postTemplateSetupRegex)){
155
+
content=content.replace(
156
+
postTemplateSetupRegex,
157
+
newPostTemplateSetupContent
158
+
);
159
+
}else{
160
+
// If the section isn't found (e.g., file was heavily modified), append it
161
+
console.warn(
162
+
'Warning: "Post-Template Setup" section not found in README.md. Appending new content.'
0 commit comments