docus 1.0.6 → 2.0.0-alpha.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/LICENSE +21 -0
- package/README.md +23 -16
- package/app/app/app.config.ts +33 -0
- package/app/app/app.vue +54 -0
- package/app/app/assets/css/main.css +5 -0
- package/app/app/components/IconMenuToggle.vue +81 -0
- package/app/app/components/OgImage/OgImageDocs.vue +76 -0
- package/app/app/components/OgImage/OgImageLanding.vue +73 -0
- package/app/app/components/app/AppFooter.vue +40 -0
- package/app/app/components/app/AppHeader.vue +57 -0
- package/app/app/components/app/AppHeaderBody.vue +13 -0
- package/app/app/components/app/AppHeaderCTA.vue +3 -0
- package/app/app/components/app/AppHeaderCenter.vue +6 -0
- package/app/app/components/app/AppHeaderLogo.vue +16 -0
- package/app/app/components/docs/DocsAsideLeftTop.vue +3 -0
- package/app/app/components/docs/DocsAsideRightBottom.vue +17 -0
- package/app/app/components/docs/DocsPageHeaderLinks.vue +91 -0
- package/app/app/error.vue +42 -0
- package/app/app/layouts/docs.vue +25 -0
- package/app/app/pages/[...slug].vue +112 -0
- package/app/app/pages/index.vue +37 -0
- package/app/content.config.ts +31 -0
- package/app/nuxt.config.ts +29 -0
- package/app/nuxt.schema.ts +255 -0
- package/app/server/routes/raw/[...slug].md.get.ts +24 -0
- package/dist/main.mjs +238 -0
- package/package.json +59 -58
- package/dist/create-docus/create-docus.js +0 -7
- package/dist/create-docus/index.js +0 -122
- package/dist/helpers.js +0 -154
- package/dist/index.js +0 -10
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// cli/main.ts
|
|
4
|
+
import * as dotenv from "dotenv";
|
|
5
|
+
|
|
6
|
+
// cli/cli.ts
|
|
7
|
+
import { resolve as resolve2 } from "path";
|
|
8
|
+
import { defineCommand, runMain } from "citty";
|
|
9
|
+
|
|
10
|
+
// cli/setup.ts
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
import { resolve } from "path";
|
|
13
|
+
import { readFile } from "fs/promises";
|
|
14
|
+
|
|
15
|
+
// cli/git.ts
|
|
16
|
+
import { execSync } from "child_process";
|
|
17
|
+
import { readGitConfig } from "pkg-types";
|
|
18
|
+
import gitUrlParse from "git-url-parse";
|
|
19
|
+
function getGitBranch() {
|
|
20
|
+
const envName = process.env.CF_PAGES_BRANCH || process.env.CI_COMMIT_BRANCH || process.env.VERCEL_GIT_COMMIT_REF || process.env.BRANCH || process.env.GITHUB_REF_NAME;
|
|
21
|
+
if (envName && envName !== "HEAD") {
|
|
22
|
+
return envName;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const branch = execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
26
|
+
if (branch && branch !== "HEAD") {
|
|
27
|
+
return branch;
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
return "main";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function getLocalGitInfo(rootDir) {
|
|
34
|
+
const remote = await getLocalGitRemote(rootDir);
|
|
35
|
+
if (!remote) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { name, owner, source } = gitUrlParse(remote);
|
|
39
|
+
const url = `https://${source}/${owner}/${name}`;
|
|
40
|
+
return {
|
|
41
|
+
name,
|
|
42
|
+
owner,
|
|
43
|
+
url
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function getLocalGitRemote(dir) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
try {
|
|
49
|
+
const parsed = await readGitConfig(dir);
|
|
50
|
+
if (!parsed) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return (_b = (_a = parsed.remote) == null ? void 0 : _a["origin"]) == null ? void 0 : _b.url;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function getGitEnv() {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
const envInfo = {
|
|
60
|
+
// Provider
|
|
61
|
+
provider: process.env.VERCEL_GIT_PROVIDER || (process.env.GITHUB_SERVER_URL ? "github" : void 0) || "",
|
|
62
|
+
// Owner
|
|
63
|
+
owner: process.env.VERCEL_GIT_REPO_OWNER || process.env.GITHUB_REPOSITORY_OWNER || ((_a = process.env.CI_PROJECT_PATH) == null ? void 0 : _a.split("/").shift()) || "",
|
|
64
|
+
// Name
|
|
65
|
+
name: process.env.VERCEL_GIT_REPO_SLUG || ((_b = process.env.GITHUB_REPOSITORY) == null ? void 0 : _b.split("/").pop()) || ((_c = process.env.CI_PROJECT_PATH) == null ? void 0 : _c.split("/").splice(1).join("/")) || "",
|
|
66
|
+
// Url
|
|
67
|
+
url: process.env.REPOSITORY_URL || ""
|
|
68
|
+
// netlify
|
|
69
|
+
};
|
|
70
|
+
if (!envInfo.url && envInfo.provider && envInfo.owner && envInfo.name) {
|
|
71
|
+
envInfo.url = `https://${envInfo.provider}.com/${envInfo.owner}/${envInfo.name}`;
|
|
72
|
+
}
|
|
73
|
+
if (!envInfo.name && !envInfo.owner && envInfo.url) {
|
|
74
|
+
try {
|
|
75
|
+
const { name, owner } = gitUrlParse(envInfo.url);
|
|
76
|
+
envInfo.name = name;
|
|
77
|
+
envInfo.owner = owner;
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
name: envInfo.name,
|
|
83
|
+
owner: envInfo.owner,
|
|
84
|
+
url: envInfo.url
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// cli/setup.ts
|
|
89
|
+
var appDir = fileURLToPath(new URL("../app", import.meta.url));
|
|
90
|
+
var pkgDir = fileURLToPath(new URL("..", import.meta.url));
|
|
91
|
+
async function getNuxtConfig(dir, _opts = {}) {
|
|
92
|
+
const meta = await getPackageJsonMetadata(dir);
|
|
93
|
+
const fixLayers = (_, nuxt) => {
|
|
94
|
+
const hasDocsDir = nuxt.options._layers.some((layer) => layer.cwd === dir);
|
|
95
|
+
if (!hasDocsDir) {
|
|
96
|
+
nuxt.options._layers.unshift({
|
|
97
|
+
cwd: dir,
|
|
98
|
+
config: {
|
|
99
|
+
rootDir: dir,
|
|
100
|
+
srcDir: dir
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
global.__DOCS_DIR__ = resolve(dir, "content");
|
|
106
|
+
const gitInfo = await getLocalGitInfo(dir) || getGitEnv();
|
|
107
|
+
const url = inferSiteURL();
|
|
108
|
+
return {
|
|
109
|
+
compatibilityDate: "2025-04-24",
|
|
110
|
+
extends: [appDir],
|
|
111
|
+
modulesDir: [resolve(pkgDir, "node_modules"), resolve(appDir, "node_modules")],
|
|
112
|
+
modules: ["nuxt-llms", fixLayers],
|
|
113
|
+
appConfig: {
|
|
114
|
+
header: {
|
|
115
|
+
title: meta.name || ""
|
|
116
|
+
},
|
|
117
|
+
github: {
|
|
118
|
+
owner: gitInfo == null ? void 0 : gitInfo.owner,
|
|
119
|
+
name: gitInfo == null ? void 0 : gitInfo.name,
|
|
120
|
+
url: gitInfo == null ? void 0 : gitInfo.url,
|
|
121
|
+
branch: getGitBranch()
|
|
122
|
+
},
|
|
123
|
+
seo: {
|
|
124
|
+
titleTemplate: `%s - ${meta.name}`,
|
|
125
|
+
title: meta.name || "",
|
|
126
|
+
description: meta.description || ""
|
|
127
|
+
},
|
|
128
|
+
toc: {}
|
|
129
|
+
},
|
|
130
|
+
site: {
|
|
131
|
+
url,
|
|
132
|
+
name: meta.name || ""
|
|
133
|
+
},
|
|
134
|
+
llms: {
|
|
135
|
+
domain: url,
|
|
136
|
+
title: meta.name || "",
|
|
137
|
+
description: meta.description || ""
|
|
138
|
+
},
|
|
139
|
+
future: {
|
|
140
|
+
compatibilityVersion: 4
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function inferSiteURL() {
|
|
145
|
+
return process.env.NUXT_SITE_URL || process.env.NEXT_PUBLIC_VERCEL_URL && `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` || process.env.URL || process.env.CI_PAGES_URL || process.env.CF_PAGES_URL;
|
|
146
|
+
}
|
|
147
|
+
async function getPackageJsonMetadata(dir) {
|
|
148
|
+
try {
|
|
149
|
+
const packageJson = await readFile(resolve(dir, "package.json"), "utf-8");
|
|
150
|
+
const parsed = JSON.parse(packageJson);
|
|
151
|
+
return {
|
|
152
|
+
name: parsed.name,
|
|
153
|
+
description: parsed.description
|
|
154
|
+
};
|
|
155
|
+
} catch {
|
|
156
|
+
return {
|
|
157
|
+
name: "docs"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// cli/cli.ts
|
|
163
|
+
function createCLI(opts) {
|
|
164
|
+
const sharedArgs = {
|
|
165
|
+
dir: {
|
|
166
|
+
type: "positional",
|
|
167
|
+
description: "Docs directory",
|
|
168
|
+
required: true,
|
|
169
|
+
default: "."
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const init = defineCommand({
|
|
173
|
+
meta: {
|
|
174
|
+
name: "init",
|
|
175
|
+
description: "Initialize a fresh Docus project"
|
|
176
|
+
},
|
|
177
|
+
args: { ...sharedArgs },
|
|
178
|
+
async setup({ args }) {
|
|
179
|
+
const dir = resolve2(args.dir);
|
|
180
|
+
const { runCommand } = await import("nuxi");
|
|
181
|
+
await runCommand("init", [dir, "-t", "gh:nuxt-themes/docus/.starter#feat/docus-v2", dir]);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const dev = defineCommand({
|
|
185
|
+
meta: {
|
|
186
|
+
name: "dev",
|
|
187
|
+
description: "Start docs in development mode"
|
|
188
|
+
},
|
|
189
|
+
args: { ...sharedArgs },
|
|
190
|
+
async setup({ args }) {
|
|
191
|
+
const dir = resolve2(args.dir);
|
|
192
|
+
const nuxtConfig = await getNuxtConfig(dir, {
|
|
193
|
+
...opts.setup,
|
|
194
|
+
dev: true
|
|
195
|
+
});
|
|
196
|
+
const { runCommand } = await import("nuxi");
|
|
197
|
+
await runCommand("dev", [dir, "--no-fork", "--port", process.env.PORT || "4000"], { overrides: nuxtConfig });
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
const build = defineCommand({
|
|
201
|
+
meta: {
|
|
202
|
+
name: "build",
|
|
203
|
+
description: "Build docs for production"
|
|
204
|
+
},
|
|
205
|
+
args: { ...sharedArgs },
|
|
206
|
+
async setup({ args }) {
|
|
207
|
+
const dir = resolve2(args.dir);
|
|
208
|
+
const nuxtConfig = await getNuxtConfig(dir, opts.setup);
|
|
209
|
+
const { runCommand } = await import("nuxi");
|
|
210
|
+
await runCommand("build", [dir], { overrides: nuxtConfig });
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const main = defineCommand({
|
|
214
|
+
meta: {
|
|
215
|
+
name: opts.name,
|
|
216
|
+
description: opts.description
|
|
217
|
+
},
|
|
218
|
+
subCommands: {
|
|
219
|
+
init,
|
|
220
|
+
dev,
|
|
221
|
+
build
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return {
|
|
225
|
+
runMain: () => runMain(main)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// cli/main.ts
|
|
230
|
+
dotenv.config();
|
|
231
|
+
var cli = createCLI({
|
|
232
|
+
name: "Docus",
|
|
233
|
+
description: "Docus Docs CLI",
|
|
234
|
+
setup: {
|
|
235
|
+
defaults: {}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
cli.runMain();
|
package/package.json
CHANGED
|
@@ -1,72 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docus",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"url": "https://github.com/docusgen/cli/issues"
|
|
3
|
+
"description": "Minimal Documentation theme and CLI for shared usage across Nuxt modules",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/nuxtlabs/docus"
|
|
8
7
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"private": false,
|
|
9
|
+
"version": "2.0.0-alpha.0",
|
|
10
|
+
"keywords": [],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"keywords": [
|
|
13
|
-
"typescript",
|
|
14
|
-
"starter"
|
|
15
|
-
],
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"module": "dist/index.mjs",
|
|
18
|
-
"types": "dist/src/index.d.ts",
|
|
19
|
-
"scripts": {
|
|
20
|
-
"dev": "jiti scripts/watch.ts --cache",
|
|
21
|
-
"build": "unbuild",
|
|
22
|
-
"lint": "prettier -c --parser typescript \"{src,tests}/**/*.[jt]s?(x)\"",
|
|
23
|
-
"lint:fix": "yarn run lint --write",
|
|
24
|
-
"test:types": "tsc --build tsconfig.json",
|
|
25
|
-
"test:unit": "jest",
|
|
26
|
-
"test": "yarn run test:types && yarn run test:unit"
|
|
27
|
-
},
|
|
28
|
-
"engines": {
|
|
29
|
-
"node": ">=14.0.0"
|
|
30
|
-
},
|
|
31
12
|
"bin": {
|
|
32
|
-
"
|
|
13
|
+
"docus": "./dist/main.mjs"
|
|
33
14
|
},
|
|
34
15
|
"files": [
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
16
|
+
"app",
|
|
17
|
+
"dist",
|
|
18
|
+
"!app/**/node_modules",
|
|
19
|
+
"!app/**/.nuxt",
|
|
20
|
+
"!app/**/tsconfig.json"
|
|
38
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "npm run docs:dev",
|
|
24
|
+
"docs:dev": "NUXT_DOCS_DEV=1 npm run docus dev docs",
|
|
25
|
+
"docs:build": "npm run docus build docs",
|
|
26
|
+
"dev:prepare": "nuxi prepare app && nuxi prepare docs",
|
|
27
|
+
"build": "tsup-node ./cli/main.ts --format esm",
|
|
28
|
+
"docus": "tsx ./cli/main.ts",
|
|
29
|
+
"test": "echo \"Error: no test specified\"",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"release": "npm run lint && npm run test && npm run build && release-it"
|
|
32
|
+
},
|
|
39
33
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
34
|
+
"@iconify-json/lucide": "^1.2.47",
|
|
35
|
+
"@iconify-json/simple-icons": "^1.2.38",
|
|
36
|
+
"@iconify-json/vscode-icons": "^1.2.22",
|
|
37
|
+
"@nuxt/content": "https://pkg.pr.new/@nuxt/content@d98bf49",
|
|
38
|
+
"@nuxt/image": "^1.10.0",
|
|
39
|
+
"@nuxt/ui-pro": "^3.1.3",
|
|
40
|
+
"@nuxtjs/robots": "^5.2.10",
|
|
41
|
+
"c12": "^3.0.4",
|
|
42
|
+
"citty": "^0.1.6",
|
|
43
|
+
"dotenv": "^16.5.0",
|
|
44
|
+
"git-url-parse": "^16.1.0",
|
|
45
|
+
"minimark": "^0.2.0",
|
|
46
|
+
"motion-v": "^1.2.1",
|
|
47
|
+
"nuxi": "^3.25.1",
|
|
48
|
+
"nuxt-llms": "^0.1.3",
|
|
49
|
+
"nuxt-og-image": "^5.1.6",
|
|
50
|
+
"pkg-types": "^2.1.0",
|
|
51
|
+
"tailwindcss": "^4.1.8",
|
|
52
|
+
"ufo": "^1.6.1",
|
|
53
|
+
"unctx": "^2.4.1"
|
|
45
54
|
},
|
|
46
55
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"@types/
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"typescript": "^4.3.5",
|
|
59
|
-
"unbuild": "^0.4.2"
|
|
56
|
+
"@nuxt/eslint-config": "^1.4.1",
|
|
57
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
58
|
+
"@stylistic/eslint-plugin": "^4.4.1",
|
|
59
|
+
"@types/node": "^24.0.0",
|
|
60
|
+
"@typescript-eslint/parser": "^8.34.0",
|
|
61
|
+
"changelogen": "^0.6.1",
|
|
62
|
+
"eslint": "^9.28.0",
|
|
63
|
+
"release-it": "^19.0.3",
|
|
64
|
+
"tsup": "^8.5.0",
|
|
65
|
+
"tsx": "^4.19.4",
|
|
66
|
+
"typescript": "^5.8.3"
|
|
60
67
|
},
|
|
61
|
-
"
|
|
62
|
-
"
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"better-sqlite3": "11.x",
|
|
70
|
+
"nuxt": "3.x"
|
|
63
71
|
},
|
|
64
|
-
"
|
|
65
|
-
"*.js": [
|
|
66
|
-
"prettier --write"
|
|
67
|
-
],
|
|
68
|
-
"*.ts?(x)": [
|
|
69
|
-
"prettier --parser=typescript --write"
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
+
"packageManager": "pnpm@10.12.1"
|
|
72
73
|
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createDocus = createDocus;
|
|
7
|
-
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
var _minimist = _interopRequireDefault(require("minimist"));
|
|
13
|
-
|
|
14
|
-
var _prompts = _interopRequireDefault(require("prompts"));
|
|
15
|
-
|
|
16
|
-
var _execa = _interopRequireDefault(require("execa"));
|
|
17
|
-
|
|
18
|
-
var _helpers = require("../helpers");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
const argv = (0, _minimist.default)(process.argv.slice(2));
|
|
23
|
-
const {
|
|
24
|
-
motd,
|
|
25
|
-
primary,
|
|
26
|
-
secondary,
|
|
27
|
-
bold,
|
|
28
|
-
space,
|
|
29
|
-
broadcast
|
|
30
|
-
} = (0, _helpers.log)();
|
|
31
|
-
const cwd = process.cwd();
|
|
32
|
-
|
|
33
|
-
async function createDocus() {
|
|
34
|
-
motd();
|
|
35
|
-
let targetDir = argv._[0];
|
|
36
|
-
|
|
37
|
-
if (!targetDir) {
|
|
38
|
-
const {
|
|
39
|
-
projectName
|
|
40
|
-
} = await (0, _prompts.default)({
|
|
41
|
-
type: "text",
|
|
42
|
-
name: "projectName",
|
|
43
|
-
message: "Project name:",
|
|
44
|
-
initial: "my-website"
|
|
45
|
-
});
|
|
46
|
-
targetDir = projectName.trim();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const packageName = await (0, _helpers.getValidPackageName)(targetDir);
|
|
50
|
-
|
|
51
|
-
const root = _path.default.join(cwd, targetDir);
|
|
52
|
-
|
|
53
|
-
await (0, _helpers.overwriteDir)(root);
|
|
54
|
-
space();
|
|
55
|
-
broadcast(secondary("Scaffolding project in ") + targetDir + secondary("..."));
|
|
56
|
-
const {
|
|
57
|
-
templateDir
|
|
58
|
-
} = await (0, _helpers.getTemplate)();
|
|
59
|
-
|
|
60
|
-
const write = (file, content = void 0) => {
|
|
61
|
-
const targetPath = _path.default.join(root, file);
|
|
62
|
-
|
|
63
|
-
if (content) _fs.default.writeFileSync(targetPath, content);else (0, _helpers.copy)(_path.default.join(templateDir, file), targetPath);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const files = _fs.default.readdirSync(templateDir);
|
|
67
|
-
|
|
68
|
-
for (const file of files.filter(f => f !== "package.json")) write(file);
|
|
69
|
-
|
|
70
|
-
const pkg = require(_path.default.join(templateDir, "package.json"));
|
|
71
|
-
|
|
72
|
-
pkg.name = packageName;
|
|
73
|
-
write("package.json", JSON.stringify(pkg, null, 2));
|
|
74
|
-
const pkgManager = /pnpm/.test(process.env.npm_execpath || "") || /pnpm/.test(process.env.npm_config_user_agent || "") ? "pnpm" : /yarn/.test(process.env.npm_execpath || "") ? "yarn" : "npm";
|
|
75
|
-
|
|
76
|
-
const related = _path.default.relative(cwd, root);
|
|
77
|
-
|
|
78
|
-
broadcast(primary("Done."));
|
|
79
|
-
space();
|
|
80
|
-
const {
|
|
81
|
-
yes
|
|
82
|
-
} = await (0, _prompts.default)({
|
|
83
|
-
type: "confirm",
|
|
84
|
-
name: "yes",
|
|
85
|
-
initial: "Y",
|
|
86
|
-
message: "Install and start it now?"
|
|
87
|
-
});
|
|
88
|
-
if (yes) await startProject(root);else startItLater(pkgManager, root, related);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function startProject(projectPath) {
|
|
92
|
-
space();
|
|
93
|
-
const {
|
|
94
|
-
agent
|
|
95
|
-
} = await (0, _prompts.default)({
|
|
96
|
-
name: "agent",
|
|
97
|
-
type: "select",
|
|
98
|
-
message: "Choose the agent",
|
|
99
|
-
choices: ["yarn", "npm", "pnpm"].map(i => ({
|
|
100
|
-
value: i,
|
|
101
|
-
title: i
|
|
102
|
-
}))
|
|
103
|
-
});
|
|
104
|
-
if (!agent) return;
|
|
105
|
-
await (0, _execa.default)(agent, ["install"], {
|
|
106
|
-
stdio: "inherit",
|
|
107
|
-
cwd: projectPath
|
|
108
|
-
});
|
|
109
|
-
await (0, _execa.default)(agent, ["run", "dev"], {
|
|
110
|
-
stdio: "inherit",
|
|
111
|
-
cwd: projectPath
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function startItLater(pkgManager, root, dir) {
|
|
116
|
-
space();
|
|
117
|
-
broadcast(secondary("Start it later with:"));
|
|
118
|
-
space();
|
|
119
|
-
if (root !== cwd) broadcast(primary(`cd ${bold(dir)}`));
|
|
120
|
-
broadcast(primary(`${pkgManager === "yarn" ? "yarn" : `${pkgManager} install`}`));
|
|
121
|
-
broadcast(primary(`${pkgManager === "yarn" ? "yarn dev" : `${pkgManager} run dev`}`));
|
|
122
|
-
}
|
package/dist/helpers.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.copy = copy;
|
|
7
|
-
exports.log = log;
|
|
8
|
-
exports.getTemplate = getTemplate;
|
|
9
|
-
exports.overwriteDir = overwriteDir;
|
|
10
|
-
exports.getValidPackageName = getValidPackageName;
|
|
11
|
-
|
|
12
|
-
var _package = require("../package.json");
|
|
13
|
-
|
|
14
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
15
|
-
|
|
16
|
-
var _path = _interopRequireDefault(require("path"));
|
|
17
|
-
|
|
18
|
-
var _kolorist = require("kolorist");
|
|
19
|
-
|
|
20
|
-
var _prompts = _interopRequireDefault(require("prompts"));
|
|
21
|
-
|
|
22
|
-
var _degit = _interopRequireDefault(require("degit"));
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function copyDir(srcDir, destDir) {
|
|
27
|
-
_fs.default.mkdirSync(destDir, {
|
|
28
|
-
recursive: true
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
for (const file of _fs.default.readdirSync(srcDir)) {
|
|
32
|
-
const srcFile = _path.default.resolve(srcDir, file);
|
|
33
|
-
|
|
34
|
-
const destFile = _path.default.resolve(destDir, file);
|
|
35
|
-
|
|
36
|
-
copy(srcFile, destFile);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function emptyDir(dir) {
|
|
41
|
-
if (!_fs.default.existsSync(dir)) return;
|
|
42
|
-
|
|
43
|
-
for (const file of _fs.default.readdirSync(dir)) {
|
|
44
|
-
const abs = _path.default.resolve(dir, file);
|
|
45
|
-
|
|
46
|
-
if (_fs.default.lstatSync(abs).isDirectory()) {
|
|
47
|
-
emptyDir(abs);
|
|
48
|
-
|
|
49
|
-
_fs.default.rmdirSync(abs);
|
|
50
|
-
} else {
|
|
51
|
-
_fs.default.unlinkSync(abs);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function copy(src, dest) {
|
|
57
|
-
const stat = _fs.default.statSync(src);
|
|
58
|
-
|
|
59
|
-
if (stat.isDirectory()) copyDir(src, dest);else _fs.default.copyFileSync(src, dest);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function log() {
|
|
63
|
-
const commands = {
|
|
64
|
-
space: () => console.log(),
|
|
65
|
-
bold: str => (0, _kolorist.bold)(str),
|
|
66
|
-
primary: str => (0, _kolorist.green)(str),
|
|
67
|
-
secondary: str => (0, _kolorist.dim)(str),
|
|
68
|
-
warning: str => (0, _kolorist.yellow)(str),
|
|
69
|
-
broadcast: str => console.log(` ${str}`),
|
|
70
|
-
motd: () => {
|
|
71
|
-
commands.space();
|
|
72
|
-
commands.broadcast(`${(0, _kolorist.bold)("Docus") + commands.secondary(" CLI")} ${commands.primary(`v${_package.version}`)}`);
|
|
73
|
-
commands.space();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return commands;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async function getTemplate() {
|
|
80
|
-
const {
|
|
81
|
-
broadcast,
|
|
82
|
-
primary,
|
|
83
|
-
secondary
|
|
84
|
-
} = log();
|
|
85
|
-
|
|
86
|
-
const templateDir = _path.default.join(__dirname, "./template");
|
|
87
|
-
|
|
88
|
-
broadcast([secondary("Cloning the latest"), primary("Docus"), secondary("template...")].join(" "));
|
|
89
|
-
emptyDir(templateDir);
|
|
90
|
-
const repo = (0, _degit.default)("git@github.com:docusgen/starter.git", {
|
|
91
|
-
force: true,
|
|
92
|
-
verbose: true,
|
|
93
|
-
mode: "git"
|
|
94
|
-
});
|
|
95
|
-
await repo.clone(templateDir);
|
|
96
|
-
return {
|
|
97
|
-
templateDir
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function overwriteDir(path2) {
|
|
102
|
-
const {
|
|
103
|
-
broadcast,
|
|
104
|
-
warning,
|
|
105
|
-
space
|
|
106
|
-
} = log();
|
|
107
|
-
|
|
108
|
-
if (!_fs.default.existsSync(path2)) {
|
|
109
|
-
_fs.default.mkdirSync(path2, {
|
|
110
|
-
recursive: true
|
|
111
|
-
});
|
|
112
|
-
} else {
|
|
113
|
-
const existing = _fs.default.readdirSync(path2);
|
|
114
|
-
|
|
115
|
-
const dir = path2.split("/");
|
|
116
|
-
const dirName = dir[dir.length - 1];
|
|
117
|
-
|
|
118
|
-
if (existing.length) {
|
|
119
|
-
space();
|
|
120
|
-
broadcast(warning(`Target directory "${dirName}" is not empty.`));
|
|
121
|
-
space();
|
|
122
|
-
const {
|
|
123
|
-
yes
|
|
124
|
-
} = await (0, _prompts.default)({
|
|
125
|
-
type: "confirm",
|
|
126
|
-
name: "yes",
|
|
127
|
-
initial: "Y",
|
|
128
|
-
message: "Remove existing files and continue?"
|
|
129
|
-
});
|
|
130
|
-
if (yes) emptyDir(path2);else return;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function getValidPackageName(projectName) {
|
|
136
|
-
projectName = _path.default.basename(projectName);
|
|
137
|
-
const packageNameRegExp = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
138
|
-
|
|
139
|
-
if (packageNameRegExp.test(projectName)) {
|
|
140
|
-
return projectName;
|
|
141
|
-
} else {
|
|
142
|
-
const suggestedPackageName = projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9-~]+/g, "-");
|
|
143
|
-
const {
|
|
144
|
-
inputPackageName
|
|
145
|
-
} = await (0, _prompts.default)({
|
|
146
|
-
type: "text",
|
|
147
|
-
name: "inputPackageName",
|
|
148
|
-
message: "Package name:",
|
|
149
|
-
initial: suggestedPackageName,
|
|
150
|
-
validate: input => packageNameRegExp.test(input) ? true : "Invalid package.json name"
|
|
151
|
-
});
|
|
152
|
-
return inputPackageName;
|
|
153
|
-
}
|
|
154
|
-
}
|