netcore-blueprint 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BlueprintTemplate/Host.API/Extensions/DatabaseExtensions.cs +1 -1
- package/BlueprintTemplate/Host.API/Extensions/ModuleExtension.cs +34 -0
- package/BlueprintTemplate/Host.API/Extensions/ServiceCollectionExtensions.cs +2 -20
- package/BlueprintTemplate/Host.API/Extensions/ThirdPartyExtensions.cs +1 -5
- package/BlueprintTemplate/Host.API/Program.cs +1 -2
- package/BlueprintTemplate/ItemModule.API/ItemModule.API.csproj +1 -0
- package/BlueprintTemplate/ItemModule.API/ItemModule.cs +24 -0
- package/BlueprintTemplate/ItemModule.Core/ItemCoreDependencyInjection.cs +19 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/{ItemDependencyInjection.cs → ItemInfraDependencyInjection.cs} +4 -10
- package/BlueprintTemplate/ItemModule.Infrastructure/Services/MySQLItemInfra.cs +1 -1
- package/BlueprintTemplate/README.md +13 -7
- package/BlueprintTemplate/Shared.Core/Interfaces/Modules/IModule.cs +14 -0
- package/BlueprintTemplate/Shared.Core/Shared.Core.csproj +1 -0
- package/BlueprintTemplate/Shared.Infrastructure/{DbInitializer.cs → Database/DbInitializer.cs} +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/{MyDbContext.cs → Database/MyDbContext.cs} +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/20260131121133_SeedInitialData.Designer.cs +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/MyDbContextModelSnapshot.cs +1 -1
- package/BlueprintTemplate/Shared.Infrastructure/Services/MySQL/MySQLItemInfra.cs +1 -0
- package/BlueprintTemplate/User.API/UserModule.API.csproj +1 -0
- package/BlueprintTemplate/User.API/UserModule.cs +24 -0
- package/BlueprintTemplate/User.Core/UserCoreDependencyInjection.cs +16 -0
- package/BlueprintTemplate/User.Infrastructure/Services/MySQLUserInfra.cs +1 -1
- package/BlueprintTemplate/User.Infrastructure/{UserDependencyInjection.cs → UserInfraDependencyInjection.cs} +2 -5
- package/bin/create-app.js +49 -0
- package/bin/create-module.js +54 -0
- package/package.json +3 -2
- package/create.js +0 -75
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
using Shared.Core.Interfaces.Modules;
|
|
2
|
+
|
|
3
|
+
namespace Host.API.Extensions
|
|
4
|
+
{
|
|
5
|
+
public static class ModuleExtensions
|
|
6
|
+
{
|
|
7
|
+
public static IServiceCollection AddModules(
|
|
8
|
+
this IServiceCollection services,
|
|
9
|
+
IConfiguration config)
|
|
10
|
+
{
|
|
11
|
+
var modules = AppDomain.CurrentDomain
|
|
12
|
+
.GetAssemblies()
|
|
13
|
+
.SelectMany(a => a.GetTypes())
|
|
14
|
+
.Where(t => typeof(IModule).IsAssignableFrom(t)
|
|
15
|
+
&& !t.IsInterface
|
|
16
|
+
&& !t.IsAbstract)
|
|
17
|
+
.Select(t => (IModule)Activator.CreateInstance(t)!);
|
|
18
|
+
|
|
19
|
+
foreach (var module in modules)
|
|
20
|
+
{
|
|
21
|
+
// Enable/disable via config (optional V1)
|
|
22
|
+
module.Register(services, config);
|
|
23
|
+
|
|
24
|
+
services.AddControllers()
|
|
25
|
+
.AddApplicationPart(module.ApiAssembly);
|
|
26
|
+
|
|
27
|
+
services.AddAutoMapper(cfg => { }, module.MappingAssembly);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return services;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
using
|
|
2
|
-
using ItemModule.Infrastructure;
|
|
3
|
-
using Shared.Infrastructure;
|
|
4
|
-
using UserModule.API.Controllers.Admin;
|
|
5
|
-
using UserModule.Infrastructure;
|
|
1
|
+
using Shared.Infrastructure;
|
|
6
2
|
|
|
7
3
|
namespace Host.API.Extensions
|
|
8
4
|
{
|
|
@@ -12,9 +8,7 @@ namespace Host.API.Extensions
|
|
|
12
8
|
this IServiceCollection services,
|
|
13
9
|
IConfiguration configuration)
|
|
14
10
|
{
|
|
15
|
-
services.AddControllers()
|
|
16
|
-
.AddApplicationPart(typeof(UserController).Assembly)
|
|
17
|
-
.AddApplicationPart(typeof(ItemController).Assembly);
|
|
11
|
+
services.AddControllers();
|
|
18
12
|
|
|
19
13
|
services.AddEndpointsApiExplorer();
|
|
20
14
|
services.AddSwaggerGen();
|
|
@@ -33,19 +27,7 @@ namespace Host.API.Extensions
|
|
|
33
27
|
return services;
|
|
34
28
|
}
|
|
35
29
|
|
|
36
|
-
public static IServiceCollection AddUserModule(this IServiceCollection services)
|
|
37
|
-
{
|
|
38
|
-
UserDependencyInjection.AddUserModuleInfra(services);
|
|
39
|
-
return services;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
30
|
public static IServiceCollection AddItemModule(this IServiceCollection services)
|
|
43
|
-
{
|
|
44
|
-
ItemDependencyInjection.AddItemModuleInfra(services);
|
|
45
|
-
return services;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public static IServiceCollection AddSharedModule(this IServiceCollection services)
|
|
49
31
|
{
|
|
50
32
|
SharedDependencyInjection.AddSharedInfrastructure(services);
|
|
51
33
|
return services;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
using Asp.Versioning;
|
|
2
|
-
using ItemModule.API.Mappers;
|
|
3
|
-
using UserModule.API.Mappers;
|
|
4
2
|
|
|
5
3
|
namespace Host.API.Extensions
|
|
6
4
|
{
|
|
@@ -9,9 +7,7 @@ namespace Host.API.Extensions
|
|
|
9
7
|
public static IServiceCollection AddThirdParty(this IServiceCollection services)
|
|
10
8
|
{
|
|
11
9
|
services.AddAutoMapper(
|
|
12
|
-
cfg => { }
|
|
13
|
-
typeof(DtoItemMappingProfile).Assembly,
|
|
14
|
-
typeof(DtoUserMappingProfile).Assembly
|
|
10
|
+
cfg => { }
|
|
15
11
|
);
|
|
16
12
|
|
|
17
13
|
services.AddApiVersioning(opt =>
|
|
@@ -9,9 +9,8 @@ builder.Services.AddApiCore(builder.Configuration);
|
|
|
9
9
|
builder.Services.AddThirdParty();
|
|
10
10
|
|
|
11
11
|
// Modules
|
|
12
|
-
builder.Services.AddUserModule();
|
|
13
12
|
builder.Services.AddItemModule();
|
|
14
|
-
builder.Services.
|
|
13
|
+
builder.Services.AddModules(builder.Configuration);
|
|
15
14
|
|
|
16
15
|
// Database
|
|
17
16
|
builder.Services.AddMySqlDatabase(builder.Configuration);
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<ItemGroup>
|
|
22
22
|
<ProjectReference Include="..\ItemModule.Core\ItemModule.Core.csproj" />
|
|
23
|
+
<ProjectReference Include="..\ItemModule.Infrastructure\ItemModule.Infrastructure.csproj" />
|
|
23
24
|
<ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
|
|
24
25
|
</ItemGroup>
|
|
25
26
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
using ItemModule.API.Controllers.Public;
|
|
2
|
+
using ItemModule.API.Mappers;
|
|
3
|
+
using ItemModule.Core;
|
|
4
|
+
using ItemModule.Infrastructure;
|
|
5
|
+
using Microsoft.Extensions.Configuration;
|
|
6
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
7
|
+
using Shared.Core.Interfaces.Modules;
|
|
8
|
+
using System.Reflection;
|
|
9
|
+
|
|
10
|
+
namespace ItemModule.API
|
|
11
|
+
{
|
|
12
|
+
public class ItemModule : IModule
|
|
13
|
+
{
|
|
14
|
+
public string Name => "Item";
|
|
15
|
+
public void Register(IServiceCollection services, IConfiguration config)
|
|
16
|
+
{
|
|
17
|
+
ItemCoreDependencyInjection.AddModule(services);
|
|
18
|
+
ItemInfraDependencyInjection.AddModule(services);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public Assembly ApiAssembly => typeof(ItemController).Assembly;
|
|
22
|
+
public Assembly MappingAssembly => typeof(DtoItemMappingProfile).Assembly;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
using ItemModule.Core.Interfaces.API;
|
|
2
|
+
using ItemModule.Core.Services;
|
|
3
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
4
|
+
using Shared.Core.Interfaces.API;
|
|
5
|
+
using Shared.Core.Services;
|
|
6
|
+
|
|
7
|
+
namespace ItemModule.Core
|
|
8
|
+
{
|
|
9
|
+
public static class ItemCoreDependencyInjection
|
|
10
|
+
{
|
|
11
|
+
public static IServiceCollection AddModule(
|
|
12
|
+
this IServiceCollection services)
|
|
13
|
+
{
|
|
14
|
+
services.AddScoped(typeof(IItemService<>), typeof(ItemService<>));
|
|
15
|
+
services.AddScoped<IItemService, ItemService>();
|
|
16
|
+
return services;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
using ItemModule.Core.Interfaces.
|
|
2
|
-
using ItemModule.Core.Interfaces.SPI;
|
|
3
|
-
using ItemModule.Core.Services;
|
|
1
|
+
using ItemModule.Core.Interfaces.SPI;
|
|
4
2
|
using ItemModule.Infrastructure.Database;
|
|
5
3
|
using ItemModule.Infrastructure.Services;
|
|
6
4
|
using Microsoft.Extensions.DependencyInjection;
|
|
7
|
-
using Shared.Core.Interfaces.API;
|
|
8
5
|
using Shared.Core.Interfaces.SPI;
|
|
9
|
-
using Shared.Core.Services;
|
|
10
6
|
using Shared.Infrastructure.Services.MySQL;
|
|
11
7
|
|
|
12
8
|
namespace ItemModule.Infrastructure
|
|
13
9
|
{
|
|
14
|
-
public static class
|
|
10
|
+
public static class ItemInfraDependencyInjection
|
|
15
11
|
{
|
|
16
|
-
public static IServiceCollection
|
|
12
|
+
public static IServiceCollection AddModule(
|
|
17
13
|
this IServiceCollection services)
|
|
18
14
|
{
|
|
19
15
|
services.AddScoped<IModuleSeeder, Seeder>();
|
|
20
|
-
services.AddScoped(typeof(IItemService<>), typeof(ItemService<>));
|
|
21
|
-
services.AddScoped(typeof(IItemInfra<>), typeof(MySQLItemInfra<>));
|
|
22
16
|
services.AddScoped<IItemInfra, MySQLItemInfra>();
|
|
23
|
-
services.AddScoped
|
|
17
|
+
services.AddScoped(typeof(IItemInfra<>), typeof(MySQLItemInfra<>));
|
|
24
18
|
return services;
|
|
25
19
|
}
|
|
26
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
using ItemModule.Core.Entities;
|
|
2
2
|
using ItemModule.Core.Interfaces.SPI;
|
|
3
3
|
using Microsoft.Extensions.Logging;
|
|
4
|
-
using Shared.Infrastructure;
|
|
4
|
+
using Shared.Infrastructure.Database;
|
|
5
5
|
using Shared.Infrastructure.Services.MySQL;
|
|
6
6
|
|
|
7
7
|
namespace ItemModule.Infrastructure.Services
|
|
@@ -7,16 +7,22 @@
|
|
|
7
7
|
6. Tạo mới 1 module
|
|
8
8
|
- Copy lại thư mục item để thêm module mới
|
|
9
9
|
- Sửa lại tên và toàn bộ namespace
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
. Controller: .AddApplicationPart(typeof(ItemController).Assembly);
|
|
13
|
-
. Injection: ItemDependencyInjection.AddItemModuleInfra(services);
|
|
14
|
-
+ Đăng ký Mapping ở ThirdPartyExtensions.cs: typeof(DtoItemMappingProfile).Assembly,
|
|
15
|
-
+ Gọi ở Program.cs: builder.Services.AddItemModule();
|
|
10
|
+
- Bật tắt các module không cần thiết
|
|
11
|
+
- Bật tắt hoặc chuyển đổi DB nếu cần
|
|
16
12
|
|
|
17
13
|
7. Mock Data
|
|
18
14
|
- Tools → NuGet Package Manager → Package Manager Console
|
|
19
15
|
- Default project: catalog.Infra
|
|
20
16
|
- Xóa Migration cũ
|
|
21
17
|
- Add-Migration SeedInitialData
|
|
22
|
-
- Update-Database
|
|
18
|
+
- Update-Database
|
|
19
|
+
|
|
20
|
+
8. Todos
|
|
21
|
+
- Tách migration theo module
|
|
22
|
+
- Plug/ Unplug module (config)
|
|
23
|
+
- Plug/ Unplug database provider (config)
|
|
24
|
+
- Thêm chức năng tạo module qua script
|
|
25
|
+
|
|
26
|
+
(Chỉnh sửa khi làm Mock back-end)
|
|
27
|
+
- Channge DB to NoSQL
|
|
28
|
+
- Simple infra for DocumentDb and Lambda
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
using Microsoft.Extensions.Configuration;
|
|
2
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
3
|
+
using System.Reflection;
|
|
4
|
+
|
|
5
|
+
namespace Shared.Core.Interfaces.Modules
|
|
6
|
+
{
|
|
7
|
+
public interface IModule
|
|
8
|
+
{
|
|
9
|
+
string Name { get; }
|
|
10
|
+
void Register(IServiceCollection services, IConfiguration config);
|
|
11
|
+
Assembly ApiAssembly { get; }
|
|
12
|
+
Assembly MappingAssembly { get; }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
5
5
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
6
6
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
7
7
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
8
|
-
using Shared.Infrastructure;
|
|
8
|
+
using Shared.Infrastructure.Database;
|
|
9
9
|
|
|
10
10
|
#nullable disable
|
|
11
11
|
|
|
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
|
|
4
4
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
5
5
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
6
6
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
7
|
-
using Shared.Infrastructure;
|
|
7
|
+
using Shared.Infrastructure.Database;
|
|
8
8
|
|
|
9
9
|
#nullable disable
|
|
10
10
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
using Microsoft.Extensions.Configuration;
|
|
2
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
3
|
+
using Shared.Core.Interfaces.Modules;
|
|
4
|
+
using System.Reflection;
|
|
5
|
+
using UserModule.API.Controllers.Admin;
|
|
6
|
+
using UserModule.API.Mappers;
|
|
7
|
+
using UserModule.Core;
|
|
8
|
+
using UserModule.Infrastructure;
|
|
9
|
+
|
|
10
|
+
namespace UserModule.API
|
|
11
|
+
{
|
|
12
|
+
public class UserModule: IModule
|
|
13
|
+
{
|
|
14
|
+
public string Name => "User";
|
|
15
|
+
public void Register(IServiceCollection services, IConfiguration config)
|
|
16
|
+
{
|
|
17
|
+
UserCoreDependencyInjection.AddModule(services);
|
|
18
|
+
UserInfraDependencyInjection.AddModule(services);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public Assembly ApiAssembly => typeof(UserController).Assembly;
|
|
22
|
+
public Assembly MappingAssembly => typeof(DtoUserMappingProfile).Assembly;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
2
|
+
using UserModule.Core.Interfaces.API;
|
|
3
|
+
using UserModule.Core.Services;
|
|
4
|
+
|
|
5
|
+
namespace UserModule.Core
|
|
6
|
+
{
|
|
7
|
+
public static class UserCoreDependencyInjection
|
|
8
|
+
{
|
|
9
|
+
public static IServiceCollection AddModule(
|
|
10
|
+
this IServiceCollection services)
|
|
11
|
+
{
|
|
12
|
+
services.AddScoped<IUserService, UserService>();
|
|
13
|
+
return services;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
using Microsoft.Extensions.DependencyInjection;
|
|
2
2
|
using Shared.Core.Interfaces.SPI;
|
|
3
|
-
using UserModule.Core.Interfaces.API;
|
|
4
3
|
using UserModule.Core.Interfaces.SPI;
|
|
5
|
-
using UserModule.Core.Services;
|
|
6
4
|
using UserModule.Infrastructure.Database;
|
|
7
5
|
using UserModule.Infrastructure.Services;
|
|
8
6
|
|
|
9
7
|
namespace UserModule.Infrastructure
|
|
10
8
|
{
|
|
11
|
-
public static class
|
|
9
|
+
public static class UserInfraDependencyInjection
|
|
12
10
|
{
|
|
13
|
-
public static IServiceCollection
|
|
11
|
+
public static IServiceCollection AddModule(
|
|
14
12
|
this IServiceCollection services)
|
|
15
13
|
{
|
|
16
14
|
services.AddScoped<IModuleSeeder, Seeder>();
|
|
17
15
|
services.AddScoped<IUserInfra, MySQLUserInfra>();
|
|
18
|
-
services.AddScoped<IUserService, UserService>();
|
|
19
16
|
return services;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const projectName = process.argv[2];
|
|
8
|
+
if (!projectName) {
|
|
9
|
+
console.error("❌ Please specify the project name.");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const templatePath = path.join(__dirname, "BlueprintTemplate");
|
|
14
|
+
const destinationPath = path.join(process.cwd(), projectName);
|
|
15
|
+
|
|
16
|
+
if (fs.existsSync(destinationPath)) {
|
|
17
|
+
console.error(`❌ Project directory "${projectName}" already exists.`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
copyDirectory(templatePath, destinationPath);
|
|
22
|
+
|
|
23
|
+
console.log(`🎉 Project "${projectName}" created successfully!`);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
process.chdir(destinationPath);
|
|
27
|
+
execSync('git init', { stdio: 'inherit' });
|
|
28
|
+
execSync('git add .', { stdio: 'inherit' });
|
|
29
|
+
execSync('git commit -m "Initial commit from blueprint"', { stdio: 'inherit' });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error("⚠️ Git init failed:", err.message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function copyDirectory(src, dest) {
|
|
35
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
36
|
+
|
|
37
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
38
|
+
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const srcPath = path.join(src, entry.name);
|
|
41
|
+
const destPath = path.join(dest, entry.name);
|
|
42
|
+
|
|
43
|
+
if (entry.isDirectory()) {
|
|
44
|
+
copyDirectory(srcPath, destPath);
|
|
45
|
+
} else {
|
|
46
|
+
fs.copyFileSync(srcPath, destPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const newModuleName = process.argv[2];
|
|
7
|
+
if (!newModuleName) {
|
|
8
|
+
console.error("❌ Please specify the module name. Example: create-module UserModule");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const sourceModuleName = "ItemModule";
|
|
13
|
+
|
|
14
|
+
const sourcePath = path.join(process.cwd(), "Modules", sourceModuleName);
|
|
15
|
+
const destinationPath = path.join(process.cwd(), "Modules", newModuleName);
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(sourcePath)) {
|
|
18
|
+
console.error(`❌ Source module not found: ${sourcePath}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (fs.existsSync(destinationPath)) {
|
|
23
|
+
console.error(`❌ Destination module already exists: ${destinationPath}`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
copyAndRenameFiles(sourcePath, destinationPath, sourceModuleName, newModuleName);
|
|
28
|
+
|
|
29
|
+
console.log(`🎉 Module "${newModuleName}" created successfully!`);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// ===== CORE LOGIC (reuse from old script) =====
|
|
33
|
+
|
|
34
|
+
function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
35
|
+
if (fs.lstatSync(src).isDirectory()) {
|
|
36
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
37
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
38
|
+
|
|
39
|
+
for (let entry of entries) {
|
|
40
|
+
const srcPath = path.join(src, entry.name);
|
|
41
|
+
const destName = entry.name.replace(new RegExp(oldName, 'g'), newName);
|
|
42
|
+
const destPath = path.join(dest, destName);
|
|
43
|
+
|
|
44
|
+
copyAndRenameFiles(srcPath, destPath, oldName, newName);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
let content = fs.readFileSync(src, 'utf8');
|
|
48
|
+
|
|
49
|
+
// Replace namespace + class + references
|
|
50
|
+
content = content.replace(new RegExp(oldName, 'g'), newName);
|
|
51
|
+
|
|
52
|
+
fs.writeFileSync(dest, content, 'utf8');
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netcore-blueprint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "A custom project blueprint",
|
|
5
5
|
"main": "create.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"
|
|
7
|
+
"create-app": "./bin/create-app.js",
|
|
8
|
+
"create-module": "./bin/create-module.js"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/create.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execSync } = require('child_process'); // ✅ Fix: Import execSync
|
|
6
|
-
|
|
7
|
-
// Get the project name from command-line arguments
|
|
8
|
-
const projectName = process.argv[2];
|
|
9
|
-
if (!projectName) {
|
|
10
|
-
console.error("❌ Please specify the project name.");
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const templatePath = path.join(__dirname, "BlueprintTemplate"); // Copy from BlueprintTemplate
|
|
15
|
-
const destinationPath = path.join(process.cwd(), projectName);
|
|
16
|
-
|
|
17
|
-
// Function to copy and rename files
|
|
18
|
-
function copyAndRenameFiles(src, dest, oldName, newName) {
|
|
19
|
-
if (fs.lstatSync(src).isDirectory()) {
|
|
20
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
21
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
22
|
-
|
|
23
|
-
for (let entry of entries) {
|
|
24
|
-
let srcPath = path.join(src, entry.name);
|
|
25
|
-
let destPath = path.join(dest, entry.name.replace(new RegExp(oldName, 'g'), newName));
|
|
26
|
-
copyAndRenameFiles(srcPath, destPath, oldName, newName);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
let content = fs.readFileSync(src, 'utf8');
|
|
30
|
-
content = content.replace(new RegExp(oldName, 'g'), newName); // Replace occurrences of netcore-blueprint
|
|
31
|
-
fs.writeFileSync(dest, content, 'utf8');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Ensure the destination folder doesn't already exist
|
|
36
|
-
if (fs.existsSync(destinationPath)) {
|
|
37
|
-
console.error(`❌ Project directory "${projectName}" already exists.`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fs.mkdirSync(destinationPath, { recursive: true });
|
|
42
|
-
|
|
43
|
-
// Copy and rename all files
|
|
44
|
-
fs.readdirSync(templatePath).forEach(item => {
|
|
45
|
-
const srcPath = path.join(templatePath, item);
|
|
46
|
-
let destPath = path.join(destinationPath, item.replace(/netcore-blueprint/g, projectName));
|
|
47
|
-
|
|
48
|
-
if (item === "gitignore") {
|
|
49
|
-
destPath = path.join(destinationPath, ".gitignore"); // Rename gitignore
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log(`✅ Copying and renaming ${item}...`);
|
|
53
|
-
copyAndRenameFiles(srcPath, destPath, "netcore-blueprint", projectName);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
console.log(`🎉 Project "${projectName}" created successfully at ${destinationPath}`);
|
|
57
|
-
console.log(`📌 Open "${projectName}.sln" in Visual Studio to get started!`);
|
|
58
|
-
|
|
59
|
-
// Initialize Git and commit the first commit
|
|
60
|
-
try {
|
|
61
|
-
process.chdir(destinationPath); // Move into project directory
|
|
62
|
-
|
|
63
|
-
console.log("🚀 Initializing Git repository...");
|
|
64
|
-
execSync('git init', { stdio: 'inherit' });
|
|
65
|
-
|
|
66
|
-
console.log("📂 Adding all files...");
|
|
67
|
-
execSync('git add .', { stdio: 'inherit' });
|
|
68
|
-
|
|
69
|
-
console.log("✅ Creating first commit...");
|
|
70
|
-
execSync('git commit -m "Initial commit from blueprint"', { stdio: 'inherit' });
|
|
71
|
-
|
|
72
|
-
console.log("🎉 Git repository initialized successfully!");
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error("❌ Failed to initialize Git:", error);
|
|
75
|
-
}
|