niral 0.1.0
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/bin/create-niral.js +21 -0
- package/bin/niral.js +7 -0
- package/index.js +96 -0
- package/package.json +16 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// npx create-niral my-app — the beginner's one command.
|
|
3
|
+
import { ensureFramework, installLauncher, runNiral } from "../index.js";
|
|
4
|
+
|
|
5
|
+
const name = process.argv[2];
|
|
6
|
+
if (!name || name.startsWith("-")) {
|
|
7
|
+
console.error("usage: npx create-niral <app-name>");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
await ensureFramework();
|
|
12
|
+
const code = runNiral(["create", name]);
|
|
13
|
+
if (code !== 0) process.exit(code);
|
|
14
|
+
|
|
15
|
+
const { profile, added } = installLauncher();
|
|
16
|
+
console.log("");
|
|
17
|
+
if (added) console.log(`✓ \`niral\` command installed — PATH updated in ${profile} (open a new terminal)`);
|
|
18
|
+
console.log(`Next:
|
|
19
|
+
cd ${name}
|
|
20
|
+
niral dev # or: npx niral dev
|
|
21
|
+
`);
|
package/bin/niral.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// niral <command> — forwards to the framework at ~/.niral/framework.
|
|
3
|
+
// Available globally after `npm i -g create-niral`, or per-call via `npx niral dev`.
|
|
4
|
+
import { ensureFramework, runNiral } from "../index.js";
|
|
5
|
+
|
|
6
|
+
await ensureFramework();
|
|
7
|
+
process.exit(runNiral(process.argv.slice(2)));
|
package/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* create-niral — the one-command bootstrap.
|
|
3
|
+
*
|
|
4
|
+
* This is the ONLY thing that lives on npm. It downloads the real framework
|
|
5
|
+
* (which has zero dependencies) from GitHub into ~/.niral/framework and
|
|
6
|
+
* forwards commands to it. The framework itself never touches npm.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync, chmodSync, appendFileSync, readFileSync } from "node:fs";
|
|
10
|
+
import { spawnSync, execSync } from "node:child_process";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { get } from "node:https";
|
|
14
|
+
|
|
15
|
+
export const NIRAL_HOME = process.env.NIRAL_HOME || join(homedir(), ".niral");
|
|
16
|
+
const FRAMEWORK = join(NIRAL_HOME, "framework");
|
|
17
|
+
const TARBALL = "https://codeload.github.com/Zyora-Dev/niral/tar.gz/refs/heads/main";
|
|
18
|
+
const REPO = "https://github.com/Zyora-Dev/niral.git";
|
|
19
|
+
|
|
20
|
+
function download(url, dest) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
get(url, (res) => {
|
|
23
|
+
if (res.statusCode !== 200) return reject(new Error(`download failed: HTTP ${res.statusCode}`));
|
|
24
|
+
const chunks = [];
|
|
25
|
+
res.on("data", (c) => chunks.push(c));
|
|
26
|
+
res.on("end", () => {
|
|
27
|
+
writeFileSync(dest, Buffer.concat(chunks));
|
|
28
|
+
resolve();
|
|
29
|
+
});
|
|
30
|
+
res.on("error", reject);
|
|
31
|
+
}).on("error", reject);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function hasGit() {
|
|
36
|
+
try {
|
|
37
|
+
execSync("git --version", { stdio: "ignore" });
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Download the framework to ~/.niral/framework (git if available, tarball otherwise). */
|
|
45
|
+
export async function ensureFramework({ update = false } = {}) {
|
|
46
|
+
if (existsSync(join(FRAMEWORK, "bin", "niral.js")) && !update) return FRAMEWORK;
|
|
47
|
+
console.log("நிரல் · downloading the framework (one time, ~1 MB — it has zero dependencies)…");
|
|
48
|
+
mkdirSync(NIRAL_HOME, { recursive: true });
|
|
49
|
+
if (hasGit()) {
|
|
50
|
+
if (existsSync(join(FRAMEWORK, ".git"))) {
|
|
51
|
+
execSync("git pull -q", { cwd: FRAMEWORK, stdio: "ignore" });
|
|
52
|
+
} else {
|
|
53
|
+
rmSync(FRAMEWORK, { recursive: true, force: true });
|
|
54
|
+
execSync(`git clone -q --depth 1 ${REPO} "${FRAMEWORK}"`, { stdio: "ignore" });
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
const tgz = join(NIRAL_HOME, "niral.tgz");
|
|
58
|
+
await download(TARBALL, tgz);
|
|
59
|
+
rmSync(FRAMEWORK, { recursive: true, force: true });
|
|
60
|
+
mkdirSync(FRAMEWORK, { recursive: true });
|
|
61
|
+
execSync(`tar -xzf "${tgz}" -C "${FRAMEWORK}" --strip-components=1`, { stdio: "ignore" });
|
|
62
|
+
rmSync(tgz);
|
|
63
|
+
}
|
|
64
|
+
if (!existsSync(join(FRAMEWORK, "bin", "niral.js"))) throw new Error("framework download failed — try again or clone github.com/Zyora-Dev/niral manually");
|
|
65
|
+
return FRAMEWORK;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Put a `niral` launcher on the PATH so every later command is just `niral dev`. */
|
|
69
|
+
export function installLauncher() {
|
|
70
|
+
const binDir = join(NIRAL_HOME, "bin");
|
|
71
|
+
mkdirSync(binDir, { recursive: true });
|
|
72
|
+
const shim = join(binDir, "niral");
|
|
73
|
+
writeFileSync(shim, `#!/usr/bin/env bash\nexec node "${join(FRAMEWORK, "bin", "niral.js")}" "$@"\n`);
|
|
74
|
+
chmodSync(shim, 0o755);
|
|
75
|
+
|
|
76
|
+
const profile =
|
|
77
|
+
(process.env.SHELL ?? "").endsWith("/zsh") ? join(homedir(), ".zshrc")
|
|
78
|
+
: (process.env.SHELL ?? "").endsWith("/bash") ? join(homedir(), ".bashrc")
|
|
79
|
+
: null;
|
|
80
|
+
if (profile) {
|
|
81
|
+
const line = `export PATH="$HOME/.niral/bin:$PATH"`;
|
|
82
|
+
const current = existsSync(profile) ? readFileSync(profile, "utf8") : "";
|
|
83
|
+
if (!current.includes(".niral/bin")) {
|
|
84
|
+
appendFileSync(profile, `\n# niral — நிரல்\n${line}\n`);
|
|
85
|
+
return { shim, profile, added: true };
|
|
86
|
+
}
|
|
87
|
+
return { shim, profile, added: false };
|
|
88
|
+
}
|
|
89
|
+
return { shim, profile: null, added: false };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Forward a command to the framework CLI. */
|
|
93
|
+
export function runNiral(args) {
|
|
94
|
+
const r = spawnSync("node", [join(FRAMEWORK, "bin", "niral.js"), ...args], { stdio: "inherit" });
|
|
95
|
+
return r.status ?? 0;
|
|
96
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "niral",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "நிரல் · Niral — the zero-dependency full-stack framework by ZyoraLabs. This package is a tiny launcher; the framework itself lives at github.com/Zyora-Dev/niral and has zero dependencies.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"niral": "bin/niral.js",
|
|
7
|
+
"create-niral": "bin/create-niral.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"engines": { "node": ">=22" },
|
|
11
|
+
"keywords": ["niral", "framework", "fullstack", "zero-dependencies", "ssr", "zyoralabs"],
|
|
12
|
+
"homepage": "https://niral.zyora.club",
|
|
13
|
+
"repository": { "type": "git", "url": "git+https://github.com/Zyora-Dev/niral.git" },
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {}
|
|
16
|
+
}
|