@ahmedrowaihi/8n 0.2.0 → 0.2.2
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/dist/index.mjs +39 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { builtinModules, createRequire } from "node:module";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import path, { delimiter, dirname, join, normalize, resolve } from "node:path";
|
|
5
|
-
import fs, { createWriteStream, existsSync, mkdirSync, promises, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import fs, { appendFileSync, createWriteStream, existsSync, mkdirSync, promises, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import process$1, { cwd } from "node:process";
|
|
7
7
|
import { PassThrough, pipeline } from "node:stream";
|
|
8
8
|
import c from "node:readline";
|
|
@@ -18,6 +18,7 @@ import { PassThrough as PassThrough$1 } from "stream";
|
|
|
18
18
|
import { cwd as cwd$1 } from "process";
|
|
19
19
|
import { spawn as spawn$1 } from "child_process";
|
|
20
20
|
import me from "readline";
|
|
21
|
+
import { createInterface } from "node:readline/promises";
|
|
21
22
|
|
|
22
23
|
//#region \0rolldown/runtime.js
|
|
23
24
|
var __create = Object.create;
|
|
@@ -37137,16 +37138,17 @@ summary: Initial release.
|
|
|
37137
37138
|
First version of the docs.
|
|
37138
37139
|
`
|
|
37139
37140
|
};
|
|
37140
|
-
|
|
37141
|
-
|
|
37142
|
-
|
|
37141
|
+
const GITIGNORE_ENTRIES = [".sudocs"];
|
|
37142
|
+
function isDirEmpty(dir) {
|
|
37143
|
+
if (!existsSync(dir)) return true;
|
|
37144
|
+
return readdirSync(dir).filter((f) => !f.startsWith(".")).length === 0;
|
|
37145
|
+
}
|
|
37146
|
+
function scaffold(targetDir) {
|
|
37143
37147
|
let created = 0;
|
|
37144
|
-
let skipped = 0;
|
|
37145
37148
|
for (const [rel, content] of Object.entries(SCAFFOLD)) {
|
|
37146
|
-
const abs = resolve(
|
|
37149
|
+
const abs = resolve(targetDir, rel);
|
|
37147
37150
|
if (existsSync(abs)) {
|
|
37148
37151
|
console.log(import_picocolors.default.dim(` skip ${rel}`));
|
|
37149
|
-
skipped++;
|
|
37150
37152
|
continue;
|
|
37151
37153
|
}
|
|
37152
37154
|
mkdirSync(join(abs, ".."), { recursive: true });
|
|
@@ -37154,9 +37156,38 @@ function init() {
|
|
|
37154
37156
|
console.log(import_picocolors.default.green(" create") + import_picocolors.default.dim(` ${rel}`));
|
|
37155
37157
|
created++;
|
|
37156
37158
|
}
|
|
37157
|
-
|
|
37159
|
+
const gitignorePath = resolve(targetDir, ".gitignore");
|
|
37160
|
+
const existing = existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf-8") : "";
|
|
37161
|
+
const missing = GITIGNORE_ENTRIES.filter((e) => !existing.split("\n").includes(e));
|
|
37162
|
+
if (missing.length > 0) {
|
|
37163
|
+
appendFileSync(gitignorePath, (existing.length > 0 && !existing.endsWith("\n") ? "\n" : "") + missing.join("\n") + "\n");
|
|
37164
|
+
for (const e of missing) console.log(import_picocolors.default.green(" gitignore") + import_picocolors.default.dim(` ${e}`));
|
|
37165
|
+
created += missing.length;
|
|
37166
|
+
}
|
|
37167
|
+
if (created > 0) console.log(import_picocolors.default.green("\n✓") + ` ready — run ${import_picocolors.default.cyan("8n dev")} to start`);
|
|
37158
37168
|
else console.log(import_picocolors.default.dim("\n already initialized"));
|
|
37159
37169
|
}
|
|
37170
|
+
async function init() {
|
|
37171
|
+
const cwd = process.cwd();
|
|
37172
|
+
console.log(import_picocolors.default.cyan("8n") + import_picocolors.default.dim(" init"));
|
|
37173
|
+
if (isDirEmpty(cwd)) {
|
|
37174
|
+
scaffold(cwd);
|
|
37175
|
+
return;
|
|
37176
|
+
}
|
|
37177
|
+
const rl = createInterface({
|
|
37178
|
+
input: process.stdin,
|
|
37179
|
+
output: process.stdout
|
|
37180
|
+
});
|
|
37181
|
+
const name = (await rl.question(import_picocolors.default.dim(" directory name: "))).trim();
|
|
37182
|
+
rl.close();
|
|
37183
|
+
if (!name) {
|
|
37184
|
+
console.log(import_picocolors.default.red(" aborted"));
|
|
37185
|
+
return;
|
|
37186
|
+
}
|
|
37187
|
+
const targetDir = resolve(cwd, name);
|
|
37188
|
+
mkdirSync(targetDir, { recursive: true });
|
|
37189
|
+
scaffold(targetDir);
|
|
37190
|
+
}
|
|
37160
37191
|
|
|
37161
37192
|
//#endregion
|
|
37162
37193
|
//#region src/index.ts
|