portosaurus 2.1.10 → 2.1.11
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/package.json +1 -1
- package/src/cli/init.mjs +20 -12
- package/src/template/gitignore +9 -0
- package/src/template/notes/index.mdx +9 -0
package/package.json
CHANGED
package/src/cli/init.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { getPackageManager } from "../utils/packageManager.mjs";
|
|
|
5
5
|
import { PortoRoot, mirrorSync } from "../utils/cliHelpers.mjs";
|
|
6
6
|
|
|
7
7
|
export async function initCommand(projectName, options) {
|
|
8
|
-
const
|
|
8
|
+
const UsrProjDir = path.resolve(process.cwd(), projectName);
|
|
9
9
|
const templateDir = path.resolve(PortoRoot, "src/template");
|
|
10
10
|
const packageJson = JSON.parse(
|
|
11
11
|
fs.readFileSync(path.resolve(PortoRoot, "package.json"), "utf8"),
|
|
@@ -29,7 +29,10 @@ export async function initCommand(projectName, options) {
|
|
|
29
29
|
|
|
30
30
|
const contentDirs = ["blog", "notes", "static"];
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
const dotGitIgnore = path.join(UsrProjDir, ".gitignore");
|
|
33
|
+
const plainGitIgnore = path.join(UsrProjDir, "gitignore");
|
|
34
|
+
|
|
35
|
+
if (fs.existsSync(UsrProjDir)) {
|
|
33
36
|
logger.error(`Target Directory "${projectName}" already exists.`);
|
|
34
37
|
process.exit(1);
|
|
35
38
|
}
|
|
@@ -45,11 +48,11 @@ export async function initCommand(projectName, options) {
|
|
|
45
48
|
const { execSync } = await import("child_process");
|
|
46
49
|
|
|
47
50
|
// Create user project directory
|
|
48
|
-
fs.mkdirSync(
|
|
51
|
+
fs.mkdirSync(UsrProjDir, { recursive: true });
|
|
49
52
|
|
|
50
53
|
// Git Init
|
|
51
54
|
try {
|
|
52
|
-
execSync("git init", { cwd:
|
|
55
|
+
execSync("git init", { cwd: UsrProjDir, stdio: "ignore" });
|
|
53
56
|
} catch {
|
|
54
57
|
logger.warn("Failed to initialize git repository.");
|
|
55
58
|
process.exit(1);
|
|
@@ -57,12 +60,17 @@ export async function initCommand(projectName, options) {
|
|
|
57
60
|
|
|
58
61
|
// Make Content directories
|
|
59
62
|
for (const dir of contentDirs) {
|
|
60
|
-
fs.mkdirSync(path.join(
|
|
63
|
+
fs.mkdirSync(path.join(UsrProjDir, dir), { recursive: true });
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
// Copy template files, dirs
|
|
64
67
|
if (fs.existsSync(templateDir)) {
|
|
65
|
-
mirrorSync(templateDir,
|
|
68
|
+
mirrorSync(templateDir, UsrProjDir, TemplateVars, ignoreList);
|
|
69
|
+
|
|
70
|
+
// Rename gitignore to .gitignore (to bypass npm publish exclusions)
|
|
71
|
+
if (fs.existsSync(plainGitIgnore) && !fs.existsSync(dotGitIgnore)) {
|
|
72
|
+
fs.renameSync(plainGitIgnore, dotGitIgnore);
|
|
73
|
+
}
|
|
66
74
|
} else {
|
|
67
75
|
logger.error(`Portosaurus template directory not found: ${templateDir}`);
|
|
68
76
|
process.exit(1);
|
|
@@ -72,13 +80,13 @@ export async function initCommand(projectName, options) {
|
|
|
72
80
|
try {
|
|
73
81
|
// Add all files to git
|
|
74
82
|
execSync("git add .", {
|
|
75
|
-
cwd:
|
|
83
|
+
cwd: UsrProjDir,
|
|
76
84
|
stdio: "ignore",
|
|
77
85
|
});
|
|
78
86
|
|
|
79
87
|
// Initial Commit
|
|
80
88
|
execSync('git commit -m "Initialize Portosaurus project"', {
|
|
81
|
-
cwd:
|
|
89
|
+
cwd: UsrProjDir,
|
|
82
90
|
stdio: "ignore",
|
|
83
91
|
});
|
|
84
92
|
} catch {
|
|
@@ -89,7 +97,7 @@ export async function initCommand(projectName, options) {
|
|
|
89
97
|
|
|
90
98
|
// GitHub Pages setup
|
|
91
99
|
if (options.githubPages === false) {
|
|
92
|
-
const ghDir = path.join(
|
|
100
|
+
const ghDir = path.join(UsrProjDir, ".github");
|
|
93
101
|
|
|
94
102
|
// Delete copied .github directory
|
|
95
103
|
if (fs.existsSync(ghDir)) {
|
|
@@ -103,10 +111,10 @@ export async function initCommand(projectName, options) {
|
|
|
103
111
|
);
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
logger.success(`Created ${projectName} at ${
|
|
114
|
+
logger.success(`Created ${projectName} at ${UsrProjDir}`);
|
|
107
115
|
|
|
108
116
|
// Install dependencies
|
|
109
|
-
const pm = getPackageManager(
|
|
117
|
+
const pm = getPackageManager(UsrProjDir);
|
|
110
118
|
|
|
111
119
|
logger.info(`Installing dependencies with ${pm.name}...`);
|
|
112
120
|
|
|
@@ -114,7 +122,7 @@ export async function initCommand(projectName, options) {
|
|
|
114
122
|
logger.info(`Running ${pm.install}...`);
|
|
115
123
|
try {
|
|
116
124
|
const { execSync } = await import("child_process");
|
|
117
|
-
execSync(pm.install, { cwd:
|
|
125
|
+
execSync(pm.install, { cwd: UsrProjDir, stdio: "inherit" });
|
|
118
126
|
logger.success("Dependencies installed!");
|
|
119
127
|
} catch {
|
|
120
128
|
logger.error(
|