create-vitnode-app 1.2.0-canary.7 → 1.2.0-canary.70
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/LICENSE.md +1 -1
- package/README.md +25 -5
- package/copy-of-vitnode-app/.vscode/settings.json +11 -0
- package/copy-of-vitnode-app/api/.gitignore_template +29 -0
- package/copy-of-vitnode-app/api/drizzle.config.ts +12 -0
- package/copy-of-vitnode-app/api/src/index.ts +27 -0
- package/copy-of-vitnode-app/api/src/vitnode.api.config.ts +23 -0
- package/copy-of-vitnode-app/api/tsconfig.json +16 -0
- package/copy-of-vitnode-app/api-bun/src/index.ts +16 -0
- package/copy-of-vitnode-app/api-single-app/.env.example +8 -0
- package/copy-of-vitnode-app/api-single-app/.gitignore_template +37 -0
- package/copy-of-vitnode-app/api-single-app/drizzle.config.ts +12 -0
- package/copy-of-vitnode-app/api-single-app/src/app/api/[...route]/route.ts +16 -0
- package/copy-of-vitnode-app/api-single-app/src/vitnode.api.config.ts +18 -0
- package/copy-of-vitnode-app/docker/docker-compose.yml +20 -0
- package/copy-of-vitnode-app/eslint/.prettierrc.mjs +1 -1
- package/copy-of-vitnode-app/eslint/eslint.config.mjs +18 -2
- package/copy-of-vitnode-app/eslint-react/eslint.config.mjs +19 -0
- package/copy-of-vitnode-app/monorepo/.gitignore_template +41 -0
- package/copy-of-vitnode-app/monorepo/apps/api/.env.example +8 -0
- package/copy-of-vitnode-app/monorepo/apps/web/.env.example +1 -0
- package/copy-of-vitnode-app/monorepo/turbo.json +40 -0
- package/copy-of-vitnode-app/root/.env.example +2 -4
- package/copy-of-vitnode-app/root/.gitignore_template +37 -0
- package/copy-of-vitnode-app/root/README.md +47 -0
- package/copy-of-vitnode-app/root/global.d.ts +9 -0
- package/copy-of-vitnode-app/root/next.config.ts +3 -6
- package/copy-of-vitnode-app/root/postcss.config.mjs +1 -1
- package/copy-of-vitnode-app/root/src/app/[locale]/(main)/[...rest]/page.tsx +1 -1
- package/copy-of-vitnode-app/root/src/app/[locale]/(main)/layout.tsx +8 -3
- package/copy-of-vitnode-app/root/src/app/[locale]/(main)/not-found.tsx +1 -1
- package/copy-of-vitnode-app/root/src/app/[locale]/(main)/page.tsx +20 -27
- package/copy-of-vitnode-app/root/src/app/[locale]/admin/(auth)/layout.tsx +2 -2
- package/copy-of-vitnode-app/root/src/app/[locale]/admin/page.tsx +1 -1
- package/copy-of-vitnode-app/root/src/app/[locale]/layout.tsx +20 -17
- package/copy-of-vitnode-app/root/src/app/global-error.tsx +8 -11
- package/copy-of-vitnode-app/root/src/app/global.css +63 -64
- package/copy-of-vitnode-app/root/src/app/layout.tsx +1 -1
- package/copy-of-vitnode-app/root/src/proxy.ts +24 -0
- package/copy-of-vitnode-app/root/src/vitnode.config.ts +32 -0
- package/copy-of-vitnode-app/root/tsconfig.json +1 -1
- package/copy-of-vitnode-plugin/root/.swcrc +25 -0
- package/copy-of-vitnode-plugin/root/global.d.ts +10 -0
- package/copy-of-vitnode-plugin/root/npmignore.template +19 -0
- package/copy-of-vitnode-plugin/root/tsconfig.json +25 -0
- package/dist/src/create/create-package-json.js +251 -56
- package/dist/src/create/create-vitnode.js +180 -28
- package/dist/src/create/package-versions.js +41 -0
- package/dist/src/helpers/get-available-package-managers.js +6 -6
- package/dist/src/helpers/get-package-json.js +2 -2
- package/dist/src/helpers/get-package-manager-from-root.js +15 -0
- package/dist/src/helpers/get-vitnode-package-version.js +9 -0
- package/dist/src/helpers/init-vitnode.js +21 -0
- package/dist/src/helpers/install-dependencies.js +55 -14
- package/dist/src/helpers/is-folder-empty.js +25 -26
- package/dist/src/helpers/is-online.js +16 -16
- package/dist/src/helpers/is-writeable.js +3 -3
- package/dist/src/helpers/validate-pkg.js +1 -1
- package/dist/src/helpers/with-If.js +1 -0
- package/dist/src/index.js +29 -26
- package/dist/src/plugin/create/add-plugin-to-workspace.js +74 -0
- package/dist/src/plugin/create/create-package-json.js +62 -0
- package/dist/src/plugin/create/create-plugin-vitnode.js +72 -0
- package/dist/src/plugin/index.js +17 -6
- package/dist/src/plugin/questions.js +14 -0
- package/dist/src/plugin/validation.js +76 -0
- package/dist/src/prepare/prepare.js +11 -8
- package/dist/src/questions.js +52 -15
- package/dist/src/validation.js +15 -15
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -9
- package/copy-of-vitnode-app/root/.prettierrc.mjs +0 -11
- package/copy-of-vitnode-app/root/drizzle.config.ts +0 -12
- package/copy-of-vitnode-app/root/gitignore_template +0 -43
- package/copy-of-vitnode-app/root/src/app/[locale]/admin/not-found.tsx +0 -5
- package/copy-of-vitnode-app/root/src/app/api/[...route]/route.ts +0 -18
- package/copy-of-vitnode-app/root/src/app/not-found.tsx +0 -13
- package/copy-of-vitnode-app/root/src/vitnode.api.config.ts +0 -5
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
export const initFilesVitnode = ({ packageManager: pm, cwd, flag, }) => {
|
|
3
|
+
const packageManager = pm.split("@")[0];
|
|
4
|
+
const args = [
|
|
5
|
+
"vitnode",
|
|
6
|
+
"prepare-plugins",
|
|
7
|
+
flag ? `--${flag}` : "",
|
|
8
|
+
];
|
|
9
|
+
spawn(packageManager, args, {
|
|
10
|
+
cwd,
|
|
11
|
+
shell: true,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export const generateMigrationsVitnode = ({ packageManager: pm, cwd, }) => {
|
|
15
|
+
const packageManager = pm.split("@")[0];
|
|
16
|
+
const args = ["vitnode", "migrate", "--generate"];
|
|
17
|
+
spawn(packageManager, args, {
|
|
18
|
+
cwd,
|
|
19
|
+
shell: true,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -1,30 +1,71 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import
|
|
3
|
-
import { getOnline } from
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import consoleColor from "picocolors";
|
|
3
|
+
import { getOnline } from "./is-online.js";
|
|
4
|
+
function printInstallErrorSuggestions(stderr, color) {
|
|
5
|
+
if (stderr.includes("ENOTFOUND") || stderr.includes("network")) {
|
|
6
|
+
console.error(color.yellow("💡 Network error detected. Please check your internet connection."));
|
|
7
|
+
}
|
|
8
|
+
else if (stderr.includes("EACCES") ||
|
|
9
|
+
stderr.includes("permission denied")) {
|
|
10
|
+
console.error(color.yellow("💡 Permission error detected. Try running with elevated privileges or check file permissions."));
|
|
11
|
+
}
|
|
12
|
+
else if (stderr.includes("ENOSPC")) {
|
|
13
|
+
console.error(color.yellow("💡 Disk space error detected. Please free up some disk space."));
|
|
14
|
+
}
|
|
15
|
+
else if (stderr.includes("ERR_PNPM_PEER_DEP_ISSUES")) {
|
|
16
|
+
console.error(color.yellow("💡 Peer dependency issues detected. Consider using --force flag or resolve conflicts manually."));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const installDependencies = async ({ packageManager: pm, cwd, }) => {
|
|
20
|
+
const packageManager = pm.split("@")[0];
|
|
6
21
|
const isOnline = await getOnline();
|
|
7
|
-
const args =
|
|
22
|
+
const args = ["install"];
|
|
8
23
|
if (!isOnline) {
|
|
9
|
-
console.log(
|
|
10
|
-
args.push(
|
|
24
|
+
console.log(consoleColor.yellow("You appear to be offline.\nFalling back to the local cache."));
|
|
25
|
+
args.push("--offline");
|
|
11
26
|
}
|
|
12
27
|
return new Promise((resolve, reject) => {
|
|
28
|
+
let stdout = "";
|
|
29
|
+
let stderr = "";
|
|
13
30
|
const child = spawn(packageManager, args, {
|
|
14
|
-
stdio:
|
|
31
|
+
stdio: "pipe",
|
|
32
|
+
cwd,
|
|
33
|
+
shell: true,
|
|
15
34
|
env: {
|
|
16
35
|
...process.env,
|
|
17
|
-
ADBLOCK:
|
|
18
|
-
NODE_ENV:
|
|
19
|
-
DISABLE_OPENCOLLECTIVE:
|
|
36
|
+
ADBLOCK: "1",
|
|
37
|
+
NODE_ENV: "development",
|
|
38
|
+
DISABLE_OPENCOLLECTIVE: "1",
|
|
20
39
|
},
|
|
21
40
|
});
|
|
22
|
-
child.on(
|
|
41
|
+
child.stdout?.on("data", (data) => {
|
|
42
|
+
const output = data.toString();
|
|
43
|
+
stdout += output;
|
|
44
|
+
});
|
|
45
|
+
child.stderr?.on("data", (data) => {
|
|
46
|
+
const output = data.toString();
|
|
47
|
+
stderr += output;
|
|
48
|
+
});
|
|
49
|
+
child.on("close", code => {
|
|
23
50
|
if (code !== 0) {
|
|
24
|
-
|
|
51
|
+
console.error(consoleColor.red(`\n❌ Installation failed with exit code: ${code}`));
|
|
52
|
+
if (stderr) {
|
|
53
|
+
console.error(consoleColor.red("Error output:"));
|
|
54
|
+
console.error(stderr);
|
|
55
|
+
}
|
|
56
|
+
if (stdout) {
|
|
57
|
+
console.log(consoleColor.yellow("Standard output:"));
|
|
58
|
+
console.log(stdout);
|
|
59
|
+
}
|
|
60
|
+
printInstallErrorSuggestions(stderr, consoleColor);
|
|
61
|
+
reject(new Error(`Failed to install dependencies using ${packageManager}. Exit code: ${code}\n${stderr || stdout}`));
|
|
25
62
|
return;
|
|
26
63
|
}
|
|
27
64
|
resolve();
|
|
28
65
|
});
|
|
66
|
+
child.on("error", error => {
|
|
67
|
+
console.error(consoleColor.red(`❌ Failed to start ${packageManager}:`), error.message);
|
|
68
|
+
reject(new Error(`Failed to start ${packageManager}: ${error.message}`));
|
|
69
|
+
});
|
|
29
70
|
});
|
|
30
71
|
};
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { lstatSync, readdirSync } from
|
|
2
|
-
import { join } from
|
|
3
|
-
import colors from
|
|
1
|
+
import { lstatSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import colors from "picocolors";
|
|
4
4
|
export function isFolderEmpty(root, name) {
|
|
5
5
|
const validFiles = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
".DS_Store",
|
|
7
|
+
".git",
|
|
8
|
+
".gitattributes",
|
|
9
|
+
".gitignore",
|
|
10
|
+
".gitlab-ci.yml",
|
|
11
|
+
".hg",
|
|
12
|
+
".hgcheck",
|
|
13
|
+
".hgignore",
|
|
14
|
+
".idea",
|
|
15
|
+
".npmignore",
|
|
16
|
+
".travis.yml",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"Thumbs.db",
|
|
19
|
+
"docs",
|
|
20
|
+
"mkdocs.yml",
|
|
21
|
+
"npm-debug.log",
|
|
22
|
+
"yarn-debug.log",
|
|
23
|
+
"yarn-error.log",
|
|
24
|
+
"yarnrc.yml",
|
|
25
|
+
".yarn",
|
|
26
26
|
];
|
|
27
|
-
const conflicts = readdirSync(root).filter(file => !validFiles.includes(file)
|
|
28
|
-
!file.endsWith('.iml'));
|
|
27
|
+
const conflicts = readdirSync(root).filter(file => !(validFiles.includes(file) || file.endsWith(".iml")));
|
|
29
28
|
if (conflicts.length > 0) {
|
|
30
29
|
console.log(`The directory ${colors.green(name)} contains files that could conflict:\n`);
|
|
31
30
|
for (const file of conflicts) {
|
|
@@ -42,7 +41,7 @@ export function isFolderEmpty(root, name) {
|
|
|
42
41
|
console.log(file);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
console.log(
|
|
44
|
+
console.log("\nEither try using a new directory name, or remove the files listed above.\n");
|
|
46
45
|
return false;
|
|
47
46
|
}
|
|
48
47
|
return true;
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { execSync } from
|
|
2
|
-
import { lookup } from
|
|
3
|
-
import { URL } from
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { lookup } from "node:dns/promises";
|
|
3
|
+
import { URL } from "node:url";
|
|
4
|
+
function getProxy() {
|
|
5
|
+
if (process.env.https_proxy) {
|
|
6
|
+
return process.env.https_proxy;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const httpsProxy = execSync("npm config get https-proxy").toString().trim();
|
|
10
|
+
return httpsProxy !== "null" ? httpsProxy : undefined;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
export async function getOnline() {
|
|
5
17
|
try {
|
|
6
|
-
await lookup(
|
|
18
|
+
await lookup("registry.yarnpkg.com");
|
|
7
19
|
return true;
|
|
8
20
|
}
|
|
9
21
|
catch {
|
|
@@ -24,15 +36,3 @@ export async function getOnline() {
|
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
|
-
function getProxy() {
|
|
28
|
-
if (process.env.https_proxy) {
|
|
29
|
-
return process.env.https_proxy;
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const httpsProxy = execSync('npm config get https-proxy').toString().trim();
|
|
33
|
-
return httpsProxy !== 'null' ? httpsProxy : undefined;
|
|
34
|
-
}
|
|
35
|
-
catch (_) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { W_OK } from
|
|
2
|
-
import { access } from
|
|
1
|
+
import { W_OK } from "node:constants";
|
|
2
|
+
import { access } from "node:fs/promises";
|
|
3
3
|
export async function isWriteable(directory) {
|
|
4
4
|
try {
|
|
5
5
|
await access(directory, W_OK);
|
|
6
6
|
return true;
|
|
7
7
|
}
|
|
8
|
-
catch
|
|
8
|
+
catch {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const withIf = (cond, obj) => (cond ? obj : {});
|
package/dist/src/index.js
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { input } from
|
|
3
|
-
import { Command, Option } from
|
|
4
|
-
import { basename, resolve } from
|
|
5
|
-
import color from
|
|
6
|
-
import { createVitNode } from
|
|
7
|
-
import { packageJson } from
|
|
8
|
-
import { validateNpmName } from
|
|
9
|
-
import { createPlugin } from
|
|
10
|
-
import { createQuestionsCli } from
|
|
11
|
-
import { validationProject } from
|
|
12
|
-
const [major] = process.versions.node.split(
|
|
2
|
+
import { input } from "@inquirer/prompts";
|
|
3
|
+
import { Command, Option } from "commander";
|
|
4
|
+
import { basename, resolve } from "node:path";
|
|
5
|
+
import color from "picocolors";
|
|
6
|
+
import { createVitNode } from "./create/create-vitnode.js";
|
|
7
|
+
import { packageJson } from "./helpers/get-package-json.js";
|
|
8
|
+
import { validateNpmName } from "./helpers/validate-pkg.js";
|
|
9
|
+
import { createPlugin } from "./plugin/index.js";
|
|
10
|
+
import { createQuestionsCli } from "./questions.js";
|
|
11
|
+
import { validationProject } from "./validation.js";
|
|
12
|
+
const [major] = process.versions.node.split(".").map(Number);
|
|
13
13
|
if (major < 20) {
|
|
14
14
|
console.error(color.red(`\nError: VitNode requires Node.js version 20 or higher.\nYou are currently using Node.js ${process.versions.node}\n`));
|
|
15
15
|
process.exit(1);
|
|
16
16
|
}
|
|
17
|
-
process.on(
|
|
18
|
-
if (error.name ===
|
|
19
|
-
console.log(color.dim(
|
|
17
|
+
process.on("uncaughtException", (error) => {
|
|
18
|
+
if (error.name === "ExitPromptError") {
|
|
19
|
+
console.log(color.dim("👋 VitNode setup cancelled - see you next time!"));
|
|
20
20
|
process.exit(0);
|
|
21
21
|
}
|
|
22
|
-
console.error(color.red(
|
|
22
|
+
console.error(color.red("An unexpected error occurred:"));
|
|
23
23
|
console.error(color.red(error.stack ?? error.message));
|
|
24
24
|
process.exit(1);
|
|
25
25
|
});
|
|
26
26
|
const init = async () => {
|
|
27
|
-
let projectPath =
|
|
27
|
+
let projectPath = "";
|
|
28
28
|
const program = new Command()
|
|
29
|
-
.version(packageJson.version)
|
|
30
|
-
.argument(
|
|
31
|
-
.usage(`${color.green(
|
|
29
|
+
.version(packageJson.version ?? "0.1.0")
|
|
30
|
+
.argument("[project-directory]")
|
|
31
|
+
.usage(`${color.green("[project-directory]")} [options]`)
|
|
32
32
|
.action(name => {
|
|
33
33
|
projectPath = name;
|
|
34
34
|
});
|
|
35
|
-
program.addOption(new Option(
|
|
36
|
-
program.option(
|
|
37
|
-
program.option(
|
|
38
|
-
program.
|
|
35
|
+
program.addOption(new Option("--package-manager <package-manager>", "Specify the package manager to use").choices(["npm", "pnpm", "bun"]));
|
|
36
|
+
program.option("--eslint", "Initialize with ESLint & Prettier config.");
|
|
37
|
+
program.option("--skip-install", "Skip installing packages after initializing the project.");
|
|
38
|
+
program.addOption(new Option("--mode <mode>", "What type of app do you want to create?").choices(["singleApp", "apiMonorepo", "onlyApi"]));
|
|
39
|
+
program.option("--monorepo", "Create project with monorepo structure.");
|
|
40
|
+
program.option("--docker", "Initialize with Docker support.");
|
|
41
|
+
program.option("--plugin", "Create a plugin.");
|
|
39
42
|
program.parse(process.argv);
|
|
40
43
|
const opts = program.opts();
|
|
41
44
|
if (opts.plugin) {
|
|
42
|
-
await createPlugin(projectPath);
|
|
45
|
+
await createPlugin({ projectPath, program });
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
45
48
|
if (!projectPath) {
|
|
46
49
|
projectPath = await input({
|
|
47
|
-
message:
|
|
48
|
-
default:
|
|
50
|
+
message: "What is your project named?",
|
|
51
|
+
default: "my-vitnode",
|
|
49
52
|
validate: (name) => {
|
|
50
53
|
const validation = validateNpmName({ name: basename(resolve(name)) });
|
|
51
54
|
if (validation.valid)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readdir, readFile, writeFile } from "fs/promises";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
const writeJson = async (path, data) => writeFile(path, JSON.stringify(data, null, 2) + "\n");
|
|
4
|
+
const findPackageJsonFiles = async (dir, results = []) => {
|
|
5
|
+
try {
|
|
6
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
7
|
+
for (const entry of entries) {
|
|
8
|
+
const fullPath = join(dir, entry.name);
|
|
9
|
+
if (entry.name === "node_modules" || entry.name === "dist") {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
await findPackageJsonFiles(fullPath, results);
|
|
14
|
+
}
|
|
15
|
+
else if (entry.name === "package.json") {
|
|
16
|
+
results.push(fullPath);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
};
|
|
24
|
+
export const addPluginToWorkspace = async ({ packageManager, pluginName, pluginPath, rootPath, }) => {
|
|
25
|
+
const packageJsonFiles = await findPackageJsonFiles(rootPath);
|
|
26
|
+
const pluginParentDir = dirname(pluginPath);
|
|
27
|
+
for (const packageJsonPath of packageJsonFiles) {
|
|
28
|
+
if (packageJsonPath === join(pluginPath, "package.json")) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const packageDir = dirname(dirname(packageJsonPath));
|
|
32
|
+
if (packageDir === pluginParentDir) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const content = await readFile(packageJsonPath, "utf-8");
|
|
37
|
+
const pkg = JSON.parse(content);
|
|
38
|
+
const hasVitnodeCore = pkg.dependencies?.["@vitnode/core"] ??
|
|
39
|
+
pkg.devDependencies?.["@vitnode/core"];
|
|
40
|
+
if (!hasVitnodeCore) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
let workspaceReference;
|
|
44
|
+
switch (packageManager) {
|
|
45
|
+
case "bun":
|
|
46
|
+
workspaceReference = "workspace:*";
|
|
47
|
+
break;
|
|
48
|
+
case "npm":
|
|
49
|
+
workspaceReference = "*";
|
|
50
|
+
break;
|
|
51
|
+
case "pnpm":
|
|
52
|
+
workspaceReference = "workspace:*";
|
|
53
|
+
break;
|
|
54
|
+
case "yarn":
|
|
55
|
+
workspaceReference = "workspace:*";
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
workspaceReference = "workspace:*";
|
|
59
|
+
}
|
|
60
|
+
pkg.dependencies ??= {};
|
|
61
|
+
pkg.dependencies[pluginName] = workspaceReference;
|
|
62
|
+
pkg.dependencies = Object.keys(pkg.dependencies)
|
|
63
|
+
.sort()
|
|
64
|
+
.reduce((acc, key) => {
|
|
65
|
+
acc[key] = pkg.dependencies?.[key] ?? "";
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
await writeJson(packageJsonPath, pkg);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { writeFile } from "fs/promises";
|
|
2
|
+
import { versionsPackageJson } from "../../create/package-versions.js";
|
|
3
|
+
import { getVitnodePackageVersion } from "../../helpers/get-vitnode-package-version.js";
|
|
4
|
+
import { withIf } from "../../helpers/with-If.js";
|
|
5
|
+
const writeJson = async (path, data) => writeFile(path, JSON.stringify(data, null, 2));
|
|
6
|
+
export const createPluginPackageJSON = async ({ pluginName, pluginPath, eslint, }) => {
|
|
7
|
+
const vitnodeVersionRange = await getVitnodePackageVersion();
|
|
8
|
+
const pluginPkg = {
|
|
9
|
+
name: pluginName,
|
|
10
|
+
version: "0.1.0",
|
|
11
|
+
private: true,
|
|
12
|
+
type: "module",
|
|
13
|
+
scripts: {
|
|
14
|
+
"build:plugins": "tsc && swc src -d dist --config-file .swcrc && tsc-alias -p tsconfig.json",
|
|
15
|
+
dev: 'concurrently "tsc -w --preserveWatchOutput" "swc src -d dist --config-file .swcrc -w" "tsc-alias -w" "vitnode plugin --w"',
|
|
16
|
+
"dev:email": "email dev --dir src/emails",
|
|
17
|
+
...withIf(eslint, {
|
|
18
|
+
lint: "turbo lint",
|
|
19
|
+
"lint:fix": "turbo lint:fix",
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
exports: {
|
|
23
|
+
"./*": {
|
|
24
|
+
import: "./dist/src/*.js",
|
|
25
|
+
types: "./dist/src/*.d.ts",
|
|
26
|
+
default: "./dist/src/*.js",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
dependencies: {
|
|
30
|
+
"@hono/zod-openapi": versionsPackageJson.honoZodOpenapi,
|
|
31
|
+
"@vitnode/core": vitnodeVersionRange,
|
|
32
|
+
"drizzle-kit": versionsPackageJson.drizzleKit,
|
|
33
|
+
"drizzle-orm": versionsPackageJson.drizzleOrm,
|
|
34
|
+
hono: versionsPackageJson.hono,
|
|
35
|
+
"lucide-react": versionsPackageJson.lucide,
|
|
36
|
+
next: versionsPackageJson.nextSingle,
|
|
37
|
+
"next-intl": versionsPackageJson.nextIntl,
|
|
38
|
+
react: versionsPackageJson.react,
|
|
39
|
+
"react-dom": versionsPackageJson.reactDom,
|
|
40
|
+
"react-email": versionsPackageJson.reactEmail,
|
|
41
|
+
"react-hook-form": versionsPackageJson.rhf,
|
|
42
|
+
sonner: versionsPackageJson.sonner,
|
|
43
|
+
"use-intl": versionsPackageJson.useIntl,
|
|
44
|
+
zod: versionsPackageJson.zod,
|
|
45
|
+
},
|
|
46
|
+
devDependencies: {
|
|
47
|
+
"@react-email/components": versionsPackageJson.reactEmailComponents,
|
|
48
|
+
"@swc/cli": versionsPackageJson.swcCli,
|
|
49
|
+
"@swc/core": versionsPackageJson.swcCore,
|
|
50
|
+
"@types/react": versionsPackageJson.typesReact,
|
|
51
|
+
"@types/react-dom": versionsPackageJson.typesReactDom,
|
|
52
|
+
"@vitnode/config": vitnodeVersionRange,
|
|
53
|
+
concurrently: versionsPackageJson.concurrently,
|
|
54
|
+
...withIf(eslint, {
|
|
55
|
+
eslint: versionsPackageJson.eslint,
|
|
56
|
+
}),
|
|
57
|
+
"tsc-alias": versionsPackageJson.tscAlias,
|
|
58
|
+
typescript: versionsPackageJson.typescript,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
await writeJson(`${pluginPath}/package.json`, pluginPkg);
|
|
62
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { cp, mkdir, rename } from "fs/promises";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
import color from "picocolors";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { getPackageManagerFromRoot } from "../../helpers/get-package-manager-from-root.js";
|
|
8
|
+
import { installDependencies } from "../../helpers/install-dependencies.js";
|
|
9
|
+
import { isFolderEmpty } from "../../helpers/is-folder-empty.js";
|
|
10
|
+
import { addPluginToWorkspace } from "./add-plugin-to-workspace.js";
|
|
11
|
+
import { createPluginPackageJSON } from "./create-package-json.js";
|
|
12
|
+
export const createPluginVitNode = async ({ pluginPath, pluginName, install, eslint, }) => {
|
|
13
|
+
const packageManager = getPackageManagerFromRoot(process.cwd());
|
|
14
|
+
const spinner = ora(`Creating a new VitNode plugin in ${color.green(pluginPath)}. Using ${color.green(packageManager)}...`).start();
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
const templatePath = join(__dirname, "..", "..", "..", "..", "copy-of-vitnode-plugin", "root");
|
|
18
|
+
if (!existsSync(templatePath)) {
|
|
19
|
+
spinner.fail(`\n${color.red("Error!")} Template path ${color.cyan(templatePath)} does not exist.`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
await mkdir(pluginPath, { recursive: true });
|
|
23
|
+
if (!isFolderEmpty(pluginPath, pluginName)) {
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
spinner.text = "Preparing the plugin structure...";
|
|
27
|
+
await cp(templatePath, pluginPath, { recursive: true });
|
|
28
|
+
const npmIgnoreTemplatePath = join(pluginPath, "npmignore.template");
|
|
29
|
+
const dotNpmIgnorePath = join(pluginPath, ".npmignore");
|
|
30
|
+
if (existsSync(npmIgnoreTemplatePath)) {
|
|
31
|
+
await rename(npmIgnoreTemplatePath, dotNpmIgnorePath);
|
|
32
|
+
}
|
|
33
|
+
spinner.text = "Creating package.json...";
|
|
34
|
+
await createPluginPackageJSON({
|
|
35
|
+
pluginName,
|
|
36
|
+
pluginPath,
|
|
37
|
+
eslint,
|
|
38
|
+
});
|
|
39
|
+
if (eslint) {
|
|
40
|
+
spinner.text = "Setting up ESLint...";
|
|
41
|
+
const templateEslintPath = join(__dirname, "..", "..", "..", "..", "copy-of-vitnode-app", "eslint-react");
|
|
42
|
+
if (!existsSync(templateEslintPath)) {
|
|
43
|
+
spinner.fail(`\n${color.red("Error!")} ESLint template path ${color.cyan(templateEslintPath)} does not exist.`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
await cp(templateEslintPath, pluginPath, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
let rootPath = process.cwd();
|
|
49
|
+
let currentDir = rootPath;
|
|
50
|
+
while (currentDir !== dirname(currentDir)) {
|
|
51
|
+
if (existsSync(join(currentDir, "turbo.json"))) {
|
|
52
|
+
rootPath = currentDir;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
currentDir = dirname(currentDir);
|
|
56
|
+
}
|
|
57
|
+
spinner.text = "Adding plugin to workspace packages...";
|
|
58
|
+
await addPluginToWorkspace({
|
|
59
|
+
packageManager,
|
|
60
|
+
pluginName,
|
|
61
|
+
pluginPath,
|
|
62
|
+
rootPath,
|
|
63
|
+
});
|
|
64
|
+
if (install) {
|
|
65
|
+
spinner.text = "Installing dependencies...";
|
|
66
|
+
await installDependencies({
|
|
67
|
+
packageManager,
|
|
68
|
+
cwd: pluginPath,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
spinner.succeed(`${color.green("Success!")} Created ${color.cyan(pluginName)} at ${color.cyan(pluginPath)}`);
|
|
72
|
+
};
|
package/dist/src/plugin/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { input } from
|
|
2
|
-
import { basename, resolve } from
|
|
3
|
-
import { validateNpmName } from
|
|
4
|
-
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
2
|
+
import { basename, resolve } from "node:path";
|
|
3
|
+
import { validateNpmName } from "../helpers/validate-pkg.js";
|
|
4
|
+
import { createPluginVitNode } from "./create/create-plugin-vitnode.js";
|
|
5
|
+
import { createPluginQuestionsCli } from "./questions.js";
|
|
6
|
+
import { validationProjectForPlugin } from "./validation.js";
|
|
7
|
+
export const createPlugin = async ({ program, projectPath, }) => {
|
|
5
8
|
let name = projectPath;
|
|
6
9
|
if (!name) {
|
|
7
10
|
name = await input({
|
|
8
|
-
message:
|
|
9
|
-
default:
|
|
11
|
+
message: "What is your plugin named?",
|
|
12
|
+
default: "my-vitnode-plugin",
|
|
10
13
|
validate: (name) => {
|
|
11
14
|
const validation = validateNpmName({ name: basename(resolve(name)) });
|
|
12
15
|
if (validation.valid)
|
|
@@ -15,4 +18,12 @@ export const createPlugin = async (projectPath) => {
|
|
|
15
18
|
},
|
|
16
19
|
});
|
|
17
20
|
}
|
|
21
|
+
const { pluginName, pluginPath, eslint } = await validationProjectForPlugin(name);
|
|
22
|
+
const options = await createPluginQuestionsCli(program);
|
|
23
|
+
await createPluginVitNode({
|
|
24
|
+
pluginName,
|
|
25
|
+
pluginPath,
|
|
26
|
+
eslint,
|
|
27
|
+
...options,
|
|
28
|
+
});
|
|
18
29
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { confirm } from "@inquirer/prompts";
|
|
2
|
+
import color from "picocolors";
|
|
3
|
+
export const createPluginQuestionsCli = async (program) => {
|
|
4
|
+
const optionsFromProgram = program.opts();
|
|
5
|
+
const options = {
|
|
6
|
+
install: !optionsFromProgram.skipInstall,
|
|
7
|
+
};
|
|
8
|
+
if (optionsFromProgram.skipInstall === undefined) {
|
|
9
|
+
options.install = await confirm({
|
|
10
|
+
message: `Would you like to ${color.blue("Install dependencies")}?`,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return options;
|
|
14
|
+
};
|