Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b5186a

Browse files
committed
Add 'ls' command to list available project templates
Features:- List all templates from NetCoreTemplates and NetFrameworkTemplates- List templates from a specific organization: npx create-net ls <org>- Display templates in 2-column format: name and description- Fetch data from GitHub API with proper error handling- Sort repositories by last updated- Bold section headers and formatted outputCommand usage: npx create-net ls # List all default templates npx create-net ls NetFrameworkTemplates # List specific org templatesImplementation:- Add fetchJSON() function to retrieve data from GitHub API- Add listTemplates() function with optional organization parameter- Update help text to include ls command- Handle both 'ls' and 'list' commands- Graceful error handling for network issuesDocumentation:- Update README with ls command examples- Add Commands section to README- Show usage examples for both listing and creating
1 parenteb471d5 commit8b5186a

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

‎README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ Create .NET and other projects from NetCoreTemplates GitHub repositories.
44

55
##Usage
66

7+
```bash
8+
npx create-net<repo|ls> [ProjectName]
9+
```
10+
11+
###Commands
12+
13+
**List available templates:**
14+
```bash
15+
npx create-net ls [org]
16+
```
17+
18+
**Create a project:**
719
```bash
820
npx create-net<repo> [ProjectName]
921
```
@@ -12,6 +24,20 @@ If `ProjectName` is not specified, the script will use the current directory nam
1224

1325
###Examples
1426

27+
**List all available templates:**
28+
29+
```bash
30+
npx create-net ls
31+
```
32+
33+
Shows all templates from NetCoreTemplates and NetFrameworkTemplates organizations.
34+
35+
**List templates from a specific organization:**
36+
37+
```bash
38+
npx create-net ls NetFrameworkTemplates
39+
```
40+
1541
**Create a project in a new directory:**
1642

1743
```bash

‎bin/create-net.js‎

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,30 @@ const AdmZip = require('adm-zip');
1010
constargs=process.argv.slice(2);
1111

1212
if(args.length<1){
13-
console.error('Usage: npx create-net <repo> [ProjectName]');
13+
console.error('Usage: npx create-net <repo|ls> [ProjectName]');
14+
console.error('');
15+
console.error('Commands:');
16+
console.error(' ls [org] List available project templates');
17+
console.error(' <repo> [name] Create a project from a template');
1418
console.error('');
1519
console.error('If ProjectName is not specified, uses current directory name and extracts into current directory.');
1620
console.error('');
1721
console.error('Examples:');
22+
console.error(' npx create-net ls');
23+
console.error(' npx create-net ls NetFrameworkTemplates');
1824
console.error(' npx create-net nextjs MyProject');
1925
console.error(' npx create-net NetFrameworkTemplates/web-netfx MyProject');
2026
console.error(' npx create-net nextjs (uses current directory name)');
2127
process.exit(1);
2228
}
2329

30+
// Handle ls command to list available templates
31+
if(args[0]==='ls'||args[0]==='list'){
32+
consttargetOrg=args[1];// Optional organization/user name
33+
listTemplates(targetOrg);
34+
return;
35+
}
36+
2437
constrepo=args[0];
2538
letprojectName=args[1];
2639
letextractToCurrentDir=false;
@@ -71,6 +84,98 @@ if (extractToCurrentDir) {
7184
}
7285
}
7386

87+
// Function to fetch JSON from GitHub API
88+
functionfetchJSON(url){
89+
returnnewPromise((resolve,reject)=>{
90+
https.get(url,{
91+
headers:{
92+
'User-Agent':'create-net'
93+
}
94+
},(response)=>{
95+
letdata='';
96+
97+
// Handle redirects
98+
if(response.statusCode===301||response.statusCode===302){
99+
returnfetchJSON(response.headers.location).then(resolve).catch(reject);
100+
}
101+
102+
if(response.statusCode!==200){
103+
returnreject(newError(`HTTP${response.statusCode}:${response.statusMessage}`));
104+
}
105+
106+
response.on('data',chunk=>data+=chunk);
107+
response.on('end',()=>{
108+
try{
109+
resolve(JSON.parse(data));
110+
}catch(err){
111+
reject(err);
112+
}
113+
});
114+
}).on('error',reject);
115+
});
116+
}
117+
118+
// Function to list available templates
119+
asyncfunctionlistTemplates(targetOrg){
120+
console.log('Fetching available project templates...\n');
121+
122+
letorganizations;
123+
124+
if(targetOrg){
125+
// List templates from specific organization
126+
organizations=[{name:targetOrg,title:`${targetOrg} Templates`}];
127+
}else{
128+
// List templates from default organizations
129+
organizations=[
130+
{name:'NetCoreTemplates',title:'.NET Core Templates'},
131+
{name:'NetFrameworkTemplates',title:'.NET Framework Templates'}
132+
];
133+
}
134+
135+
try{
136+
for(constorgoforganizations){
137+
console.log(`\x1b[1m${org.title}\x1b[0m`);
138+
console.log('─'.repeat(80));
139+
140+
try{
141+
constrepos=awaitfetchJSON(`https://api.github.com/orgs/${org.name}/repos?per_page=100&sort=updated`);
142+
143+
if(!repos||repos.length===0){
144+
console.log(' No templates found');
145+
}else{
146+
// Find the longest repo name for padding
147+
constmaxNameLength=Math.max(...repos.map(r=>r.name.length));
148+
constpadding=Math.max(maxNameLength+2,25);
149+
150+
repos.forEach(repo=>{
151+
constname=repo.name.padEnd(padding);
152+
constdescription=repo.description||'No description available';
153+
console.log(`${name}${description}`);
154+
});
155+
}
156+
}catch(err){
157+
console.log(` Error fetching templates:${err.message}`);
158+
}
159+
160+
console.log('');
161+
}
162+
163+
console.log('\x1b[1mUsage:\x1b[0m');
164+
console.log(' npx create-net <repo> [ProjectName]');
165+
console.log(' npx create-net <org>/<repo> [ProjectName]');
166+
console.log(' npx create-net ls [org]');
167+
console.log('\n\x1b[1mExamples:\x1b[0m');
168+
console.log(' npx create-net ls # List all templates');
169+
console.log(' npx create-net ls NetFrameworkTemplates # List specific org templates');
170+
console.log(' npx create-net nextjs MyProject # Create from NetCoreTemplates');
171+
console.log(' npx create-net NetFrameworkTemplates/web-netfx MyApp # Create from specific org');
172+
173+
}catch(err){
174+
console.error('Error listing templates:',err.message);
175+
process.exit(1);
176+
}
177+
}
178+
74179
// Function to download file from URL
75180
functiondownloadFile(url,destination){
76181
returnnewPromise((resolve,reject)=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp