docus 1.0.7 → 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/helpers.js +0 -244
- package/dist/create-docus/index.js +0 -87
- 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,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getProjectType = getProjectType;
|
|
7
|
-
exports.getTemplate = getTemplate;
|
|
8
|
-
exports.createDir = createDir;
|
|
9
|
-
exports.getValidPackageName = getValidPackageName;
|
|
10
|
-
exports.getTargetDir = getTargetDir;
|
|
11
|
-
exports.createProject = createProject;
|
|
12
|
-
exports.log = exports.pkgManager = exports.args = exports.cwd = void 0;
|
|
13
|
-
|
|
14
|
-
var _package = require("../../package.json");
|
|
15
|
-
|
|
16
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
17
|
-
|
|
18
|
-
var _path = _interopRequireDefault(require("path"));
|
|
19
|
-
|
|
20
|
-
var _kolorist = require("kolorist");
|
|
21
|
-
|
|
22
|
-
var _minimist = _interopRequireDefault(require("minimist"));
|
|
23
|
-
|
|
24
|
-
var _prompts = _interopRequireDefault(require("prompts"));
|
|
25
|
-
|
|
26
|
-
var _degit = _interopRequireDefault(require("degit"));
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
|
|
30
|
-
const cwd = process.cwd();
|
|
31
|
-
exports.cwd = cwd;
|
|
32
|
-
const args = (0, _minimist.default)(process.argv.slice(2));
|
|
33
|
-
exports.args = args;
|
|
34
|
-
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";
|
|
35
|
-
exports.pkgManager = pkgManager;
|
|
36
|
-
const log = {
|
|
37
|
-
space: () => console.log(),
|
|
38
|
-
bold: str => (0, _kolorist.bold)(str),
|
|
39
|
-
primary: str => (0, _kolorist.green)(str),
|
|
40
|
-
secondary: str => (0, _kolorist.dim)(str),
|
|
41
|
-
warning: str => (0, _kolorist.yellow)(str),
|
|
42
|
-
error: str => (0, _kolorist.red)(str),
|
|
43
|
-
broadcast: str => console.log(` ${str}`),
|
|
44
|
-
motd: () => {
|
|
45
|
-
log.space();
|
|
46
|
-
log.broadcast(`${(0, _kolorist.bold)("Docus") + log.secondary(" CLI")} ${log.primary(`v${_package.version}`)}`);
|
|
47
|
-
log.space();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.log = log;
|
|
51
|
-
const REPOSITORIES = {
|
|
52
|
-
website: "git@github.com:docusgen/starter.git",
|
|
53
|
-
theme: "git@github.com:docusgen/theme-starter.git",
|
|
54
|
-
module: "git@github.com:docusgen/module-starter.git"
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function copyDir(srcDir, destDir) {
|
|
58
|
-
_fs.default.mkdirSync(destDir, {
|
|
59
|
-
recursive: true
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
for (const file of _fs.default.readdirSync(srcDir)) {
|
|
63
|
-
const srcFile = _path.default.resolve(srcDir, file);
|
|
64
|
-
|
|
65
|
-
const destFile = _path.default.resolve(destDir, file);
|
|
66
|
-
|
|
67
|
-
copy(srcFile, destFile);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function emptyDir(dir) {
|
|
72
|
-
if (!_fs.default.existsSync(dir)) return;
|
|
73
|
-
|
|
74
|
-
for (const file of _fs.default.readdirSync(dir)) {
|
|
75
|
-
const abs = _path.default.resolve(dir, file);
|
|
76
|
-
|
|
77
|
-
if (_fs.default.lstatSync(abs).isDirectory()) {
|
|
78
|
-
emptyDir(abs);
|
|
79
|
-
|
|
80
|
-
_fs.default.rmdirSync(abs);
|
|
81
|
-
} else {
|
|
82
|
-
_fs.default.unlinkSync(abs);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function copy(src, dest) {
|
|
88
|
-
const stat = _fs.default.statSync(src);
|
|
89
|
-
|
|
90
|
-
if (stat.isDirectory()) copyDir(src, dest);else _fs.default.copyFileSync(src, dest);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function getProjectType() {
|
|
94
|
-
switch (args["type"]) {
|
|
95
|
-
case "theme":
|
|
96
|
-
return "theme";
|
|
97
|
-
|
|
98
|
-
case "module":
|
|
99
|
-
return "module";
|
|
100
|
-
|
|
101
|
-
default:
|
|
102
|
-
return "website";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function getTemplate(projectType) {
|
|
107
|
-
const {
|
|
108
|
-
broadcast,
|
|
109
|
-
primary,
|
|
110
|
-
secondary
|
|
111
|
-
} = log;
|
|
112
|
-
|
|
113
|
-
const templateDir = _path.default.join(__dirname, "./template");
|
|
114
|
-
|
|
115
|
-
broadcast([secondary("Cloning the latest"), primary(projectType === "website" ? "Docus" : projectType), secondary("template...")].join(" "));
|
|
116
|
-
emptyDir(templateDir);
|
|
117
|
-
const projectRepository = REPOSITORIES[projectType];
|
|
118
|
-
const repo = (0, _degit.default)(projectRepository, {
|
|
119
|
-
force: true,
|
|
120
|
-
verbose: true,
|
|
121
|
-
mode: "git"
|
|
122
|
-
});
|
|
123
|
-
await repo.clone(templateDir);
|
|
124
|
-
return templateDir;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function createDir(targetDir) {
|
|
128
|
-
const projectPath = _path.default.join(cwd, targetDir);
|
|
129
|
-
|
|
130
|
-
const {
|
|
131
|
-
broadcast,
|
|
132
|
-
warning,
|
|
133
|
-
error,
|
|
134
|
-
space,
|
|
135
|
-
secondary
|
|
136
|
-
} = log;
|
|
137
|
-
|
|
138
|
-
if (!_fs.default.existsSync(projectPath)) {
|
|
139
|
-
_fs.default.mkdirSync(projectPath, {
|
|
140
|
-
recursive: true
|
|
141
|
-
});
|
|
142
|
-
} else {
|
|
143
|
-
const existing = _fs.default.readdirSync(projectPath);
|
|
144
|
-
|
|
145
|
-
const dir = projectPath.split("/");
|
|
146
|
-
const dirName = dir[dir.length - 1];
|
|
147
|
-
|
|
148
|
-
if (existing.length) {
|
|
149
|
-
space();
|
|
150
|
-
broadcast(warning(`Target directory "${dirName}" is not empty.`));
|
|
151
|
-
space();
|
|
152
|
-
const {
|
|
153
|
-
yes
|
|
154
|
-
} = await (0, _prompts.default)({
|
|
155
|
-
type: "confirm",
|
|
156
|
-
name: "yes",
|
|
157
|
-
initial: "Y",
|
|
158
|
-
message: "Remove existing files and continue?"
|
|
159
|
-
});
|
|
160
|
-
if (yes) emptyDir(projectPath);else {
|
|
161
|
-
space();
|
|
162
|
-
broadcast(warning(`Target directory is not empty and you do not want to overwrite it.`));
|
|
163
|
-
space();
|
|
164
|
-
broadcast(error(`Cancelling project creation.`));
|
|
165
|
-
process.exit(1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
space();
|
|
171
|
-
broadcast(secondary("Scaffolding project in ") + targetDir + secondary("..."));
|
|
172
|
-
return projectPath;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async function getValidPackageName(projectName) {
|
|
176
|
-
projectName = _path.default.basename(projectName);
|
|
177
|
-
const packageNameRegExp = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
178
|
-
|
|
179
|
-
if (packageNameRegExp.test(projectName)) {
|
|
180
|
-
return projectName;
|
|
181
|
-
} else {
|
|
182
|
-
const suggestedPackageName = projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9-~]+/g, "-");
|
|
183
|
-
const {
|
|
184
|
-
inputPackageName
|
|
185
|
-
} = await (0, _prompts.default)({
|
|
186
|
-
type: "text",
|
|
187
|
-
name: "inputPackageName",
|
|
188
|
-
message: "Package name:",
|
|
189
|
-
initial: suggestedPackageName,
|
|
190
|
-
validate: input => packageNameRegExp.test(input) ? true : "Invalid package.json name"
|
|
191
|
-
});
|
|
192
|
-
return inputPackageName;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async function getTargetDir(projectType) {
|
|
197
|
-
const {
|
|
198
|
-
space,
|
|
199
|
-
broadcast,
|
|
200
|
-
error,
|
|
201
|
-
warning
|
|
202
|
-
} = log;
|
|
203
|
-
let targetDir = args._[0];
|
|
204
|
-
|
|
205
|
-
if (!targetDir) {
|
|
206
|
-
const {
|
|
207
|
-
projectName
|
|
208
|
-
} = await (0, _prompts.default)({
|
|
209
|
-
type: "text",
|
|
210
|
-
name: "projectName",
|
|
211
|
-
message: "Project name:",
|
|
212
|
-
initial: `my-${projectType}`
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (!projectName) {
|
|
216
|
-
space();
|
|
217
|
-
broadcast(warning(`You must specify a project name.`));
|
|
218
|
-
space();
|
|
219
|
-
broadcast(error(`Cancelling project creation.`));
|
|
220
|
-
process.exit(1);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
targetDir = projectName.trim();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return targetDir;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function createProject(root, templateDir, packageName) {
|
|
230
|
-
const write = (file, content = void 0) => {
|
|
231
|
-
const targetPath = _path.default.join(root, file);
|
|
232
|
-
|
|
233
|
-
if (content) _fs.default.writeFileSync(targetPath, content);else copy(_path.default.join(templateDir, file), targetPath);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const files = _fs.default.readdirSync(templateDir);
|
|
237
|
-
|
|
238
|
-
for (const file of files.filter(f => f !== "package.json")) write(file);
|
|
239
|
-
|
|
240
|
-
const pkg = require(_path.default.join(templateDir, "package.json"));
|
|
241
|
-
|
|
242
|
-
pkg.name = packageName;
|
|
243
|
-
write("package.json", JSON.stringify(pkg, null, 2));
|
|
244
|
-
}
|