moonwave-gitlab 1.3.3

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.
@@ -0,0 +1,83 @@
1
+ import { spawn } from "child_process"
2
+ import chokidar from "chokidar"
3
+ import fs from "fs-extra"
4
+ import path from "path"
5
+ import { Args } from "../argv.js"
6
+ import { getBinaryPath } from "../binary.js"
7
+ import { prepareProject } from "../prepareProject.js"
8
+
9
+ export default async function devCommand(args: Args) {
10
+ try {
11
+ const binaryPath = await getBinaryPath()
12
+
13
+ const { tempDir, watchPaths, projectDir } = prepareProject(process.cwd(), {
14
+ codePaths: args.code,
15
+ fresh: args.fresh,
16
+ install: args.install,
17
+ binaryPath,
18
+ })
19
+
20
+ console.error(
21
+ `Moonwave: Temporary build directory is located at ${tempDir}`
22
+ )
23
+
24
+ chokidar
25
+ .watch(projectDir, {
26
+ ignoreInitial: true,
27
+ })
28
+ .on("all", (event, changedPath) => {
29
+ if (
30
+ watchPaths.some((watchPath) => {
31
+ if (path.normalize(watchPath) === path.normalize(changedPath)) {
32
+ return true
33
+ }
34
+
35
+ const relative = path.relative(watchPath, changedPath)
36
+ return (
37
+ relative &&
38
+ !relative.startsWith("..") &&
39
+ !path.isAbsolute(relative)
40
+ )
41
+ })
42
+ ) {
43
+ if (event === "unlink" || event == "unlinkDir") {
44
+ const relativePath = path.relative(projectDir, changedPath)
45
+ const targetPath = path.join(tempDir, relativePath)
46
+
47
+ fs.removeSync(targetPath)
48
+ }
49
+
50
+ prepareProject(process.cwd(), {
51
+ codePaths: args.code,
52
+ fresh: false,
53
+ skipRootCopy: true,
54
+ binaryPath,
55
+ })
56
+ }
57
+ })
58
+
59
+ const exitCode = await new Promise((resolve) => {
60
+ spawn(
61
+ "npm" + (process.platform === "win32" ? ".cmd" : ""),
62
+ ["run", "start"],
63
+ {
64
+ cwd: tempDir,
65
+ shell: true,
66
+ stdio: "inherit",
67
+ }
68
+ )
69
+ .on("exit", resolve)
70
+ .on("error", console.error)
71
+ })
72
+
73
+ if (exitCode !== 0) {
74
+ throw new Error("Non-zero exit code")
75
+ }
76
+ } catch (e) {
77
+ console.error(typeof e === "object" && e !== null ? e.toString() : e)
78
+ console.error(
79
+ "Moonwave: It looks like something went wrong. Check the error output above."
80
+ )
81
+ process.exit(1)
82
+ }
83
+ }
@@ -0,0 +1,168 @@
1
+ import fs from "fs-extra"
2
+ import path from "path"
3
+ import { ClassOrder, Config, FoldersEnabled } from "./prepareProject.js"
4
+
5
+ export interface GenerateConfigParams {
6
+ codePaths: string[]
7
+ enablePlugins: FoldersEnabled
8
+ config: Config
9
+ customCssExists: boolean
10
+ customSidebarExists: boolean
11
+ changelogExists: boolean
12
+ projectDir: string
13
+ binaryPath: string
14
+ classOrder: ClassOrder
15
+ apiCategories: string[]
16
+ autoSectionPath?: string
17
+ }
18
+
19
+ export default function getDocusaurusConfig({
20
+ codePaths,
21
+ enablePlugins,
22
+ config,
23
+ customCssExists,
24
+ customSidebarExists,
25
+ changelogExists,
26
+ projectDir,
27
+ binaryPath,
28
+ classOrder,
29
+ apiCategories,
30
+ autoSectionPath,
31
+ }: GenerateConfigParams) {
32
+ const gitRepoUrl = config.gitRepoUrl
33
+
34
+ const validCodePaths = codePaths
35
+ .map((codePath) => path.join(process.cwd(), codePath))
36
+ .filter((codePath) => fs.existsSync(codePath))
37
+
38
+ return {
39
+ onBrokenLinks: "throw",
40
+ onBrokenMarkdownLinks: "warn",
41
+ url: `https://${config.docusaurus?.organizationName}.github.io`,
42
+
43
+ ...config.docusaurus,
44
+
45
+ customFields: {
46
+ bannerImage: config.home?.bannerImage,
47
+ },
48
+
49
+ themeConfig: {
50
+ prism: {
51
+ additionalLanguages: [
52
+ "lua",
53
+ "bash",
54
+ "css",
55
+ "javascript",
56
+ "diff",
57
+ "git",
58
+ "json",
59
+ "typescript",
60
+ "toml",
61
+ ],
62
+ },
63
+
64
+ navbar: {
65
+ ...config.navbar,
66
+
67
+ items: [
68
+ ...(enablePlugins.docs
69
+ ? [
70
+ {
71
+ type: "doc",
72
+ docId: "intro",
73
+ position: "left",
74
+ label: "Docs",
75
+ },
76
+ ]
77
+ : []),
78
+ ...(enablePlugins.blog
79
+ ? [{ to: "/blog", label: "Blog", position: "left" }]
80
+ : []),
81
+ ...(validCodePaths.length > 0
82
+ ? [{ to: "/api/", label: "API", position: "left" }]
83
+ : []),
84
+ ...(changelogExists
85
+ ? [{ to: "/changelog", label: "Changelog", position: "left" }]
86
+ : []),
87
+ ...(config?.navbar?.items || []),
88
+ ...(gitRepoUrl
89
+ ? [
90
+ {
91
+ href: gitRepoUrl,
92
+ label: "GitLab",
93
+ position: "right",
94
+ },
95
+ ]
96
+ : []),
97
+ ],
98
+ },
99
+ footer: {
100
+ style: "dark",
101
+ copyright: `Copyright © ${new Date().getFullYear()} ${
102
+ config.docusaurus?.organizationName ?? ""
103
+ }. Built with Moonwave and Docusaurus.`,
104
+ ...config.footer,
105
+ },
106
+
107
+ colorMode: {
108
+ respectPrefersColorScheme: true,
109
+ },
110
+ },
111
+ plugins: [
112
+ [
113
+ "docusaurus-plugin-moonwave",
114
+ {
115
+ id: "moonwave",
116
+ code: validCodePaths,
117
+ sourceUrl: gitRepoUrl + `-/blob/${config.gitSourceBranch ?? "main"}`,
118
+ projectDir,
119
+ classOrder,
120
+ apiCategories,
121
+ binaryPath,
122
+ autoSectionPath,
123
+ },
124
+ ],
125
+ "docusaurus-lunr-search",
126
+ ],
127
+ presets: [
128
+ [
129
+ "@docusaurus/preset-classic",
130
+ {
131
+ docs: enablePlugins.docs
132
+ ? {
133
+ // Please change this to your repo.
134
+ editUrl: gitRepoUrl
135
+ ? `${gitRepoUrl}/-/edit/${config.gitSourceBranch ?? "main"}/`
136
+ : undefined, // Omitting this variable entirely will disable edit links
137
+ sidebarCollapsible: true,
138
+ sidebarPath: customSidebarExists
139
+ ? "./src/sidebars.js"
140
+ : undefined,
141
+ }
142
+ : false,
143
+ blog: enablePlugins.blog
144
+ ? {
145
+ showReadingTime: true,
146
+ // Please change this to your repo.
147
+ editUrl: gitRepoUrl
148
+ ? `${gitRepoUrl}/-/edit/${config.gitSourceBranch ?? "main"}/`
149
+ : undefined, // Omitting this variable entirely will disable edit links
150
+ }
151
+ : false,
152
+ pages: {
153
+ path: "pages",
154
+
155
+ //exclude any file starting with an underscore
156
+ exclude: ["_*.*"],
157
+ },
158
+ theme: {
159
+ customCss: [
160
+ "src/css/moonwave.css",
161
+ ...(customCssExists ? ["src/css/custom.css"] : []),
162
+ ],
163
+ },
164
+ },
165
+ ],
166
+ ],
167
+ }
168
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "./argv.js"