create-valaxy 0.15.2-dev.0 → 0.15.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/bin/index.mjs +0 -0
  3. package/dist/index.mjs +6 -278
  4. package/package.json +14 -10
  5. package/template-blog/package.json +2 -2
  6. package/build.config.ts +0 -3
  7. package/src/config.ts +0 -45
  8. package/src/index.ts +0 -6
  9. package/src/theme.ts +0 -46
  10. package/src/utils.ts +0 -73
  11. package/src/valaxy.ts +0 -202
  12. package/valaxy-blog/.dockerignore +0 -2
  13. package/valaxy-blog/.editorconfig +0 -9
  14. package/valaxy-blog/.github/workflows/gh-pages.yml +0 -42
  15. package/valaxy-blog/.vscode/extensions.json +0 -11
  16. package/valaxy-blog/.vscode/settings.json +0 -16
  17. package/valaxy-blog/Dockerfile +0 -18
  18. package/valaxy-blog/README.md +0 -51
  19. package/valaxy-blog/components/README.md +0 -7
  20. package/valaxy-blog/layouts/README.md +0 -3
  21. package/valaxy-blog/locales/README.md +0 -3
  22. package/valaxy-blog/locales/en.yml +0 -4
  23. package/valaxy-blog/locales/zh-CN.yml +0 -4
  24. package/valaxy-blog/netlify.toml +0 -16
  25. package/valaxy-blog/package.json +0 -21
  26. package/valaxy-blog/pages/404.md +0 -3
  27. package/valaxy-blog/pages/about/index.md +0 -15
  28. package/valaxy-blog/pages/about/site.md +0 -7
  29. package/valaxy-blog/pages/archives/index.md +0 -5
  30. package/valaxy-blog/pages/categories/index.md +0 -9
  31. package/valaxy-blog/pages/links/index.md +0 -9
  32. package/valaxy-blog/pages/posts/hello-valaxy.md +0 -20
  33. package/valaxy-blog/pages/tags/index.md +0 -7
  34. package/valaxy-blog/public/_headers +0 -3
  35. package/valaxy-blog/public/favicon.svg +0 -33
  36. package/valaxy-blog/public/pwa-192x192.png +0 -0
  37. package/valaxy-blog/public/pwa-512x512.png +0 -0
  38. package/valaxy-blog/public/safari-pinned-tab.svg +0 -41
  39. package/valaxy-blog/site.config.ts +0 -120
  40. package/valaxy-blog/styles/README.md +0 -9
  41. package/valaxy-blog/styles/css-vars.scss +0 -1
  42. package/valaxy-blog/styles/index.scss +0 -1
  43. package/valaxy-blog/tsconfig.json +0 -21
  44. package/valaxy-blog/valaxy.config.ts +0 -51
  45. package/valaxy-blog/vercel.json +0 -8
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 云游君 YunYouJun <me@yunyoujun.cn>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/index.mjs CHANGED
File without changes
package/dist/index.mjs CHANGED
@@ -1,278 +1,6 @@
1
- import process from 'node:process';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { execa } from 'execa';
6
- import { red, dim, gray, blue, yellow, bold, green, cyan, reset } from 'kolorist';
7
- import minimist from 'minimist';
8
- import prompts from 'prompts';
9
-
10
- const version = "0.15.2-dev.0";
11
-
12
- function formatTargetDir(targetDir) {
13
- return targetDir?.trim().replace(/\/+$/g, "");
14
- }
15
- function isEmpty(path2) {
16
- const files = fs.readdirSync(path2);
17
- return files.length === 0 || files.length === 1 && files[0] === ".git";
18
- }
19
- function copy(src, dest) {
20
- const stat = fs.statSync(src);
21
- if (stat.isDirectory())
22
- copyDir(src, dest);
23
- else
24
- fs.copyFileSync(src, dest);
25
- }
26
- function copyDir(srcDir, destDir) {
27
- fs.mkdirSync(destDir, { recursive: true });
28
- for (const file of fs.readdirSync(srcDir)) {
29
- const srcFile = path.resolve(srcDir, file);
30
- const destFile = path.resolve(destDir, file);
31
- copy(srcFile, destFile);
32
- }
33
- }
34
- function emptyDir(dir) {
35
- console.log(`
36
- ${red(`Removing`)} ${dim(dir)}`);
37
- if (!fs.existsSync(dir))
38
- return;
39
- for (const file of fs.readdirSync(dir)) {
40
- if (file === ".git")
41
- continue;
42
- fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });
43
- }
44
- }
45
- function isValidPackageName(projectName) {
46
- return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(
47
- projectName
48
- );
49
- }
50
- function toValidPackageName(projectName) {
51
- return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-");
52
- }
53
- function pkgFromUserAgent(userAgent) {
54
- if (!userAgent)
55
- return void 0;
56
- const pkgSpec = userAgent.split(" ")[0];
57
- const pkgSpecArr = pkgSpec.split("/");
58
- return {
59
- name: pkgSpecArr[0],
60
- version: pkgSpecArr[1]
61
- };
62
- }
63
-
64
- const starterTheme = {
65
- name: "starter",
66
- display: `Starter`,
67
- repo: "https://github.com/valaxyjs/valaxy-theme-starter"
68
- };
69
- async function initTheme(options) {
70
- const defaultThemeName = starterTheme.name;
71
- let themeName = options.themeName || defaultThemeName;
72
- if (!themeName) {
73
- const { theme } = await prompts({
74
- type: "text",
75
- name: "theme",
76
- message: "Theme name: valaxy-theme-",
77
- initial: defaultThemeName
78
- });
79
- themeName = theme || defaultThemeName;
80
- }
81
- const targetDir = `valaxy-theme-${themeName.trim()}`;
82
- console.log(` ${dim("npx")} ${gray("degit")} ${blue(starterTheme.repo)} ${yellow(targetDir)}`);
83
- await execa("npx", ["degit", starterTheme.repo, targetDir], { stdio: "inherit" });
84
- console.log();
85
- console.log(` ${bold("Check it")}:`);
86
- console.log();
87
- console.log(`- Change ${bold("author")} name in ${yellow("LICENSE")} & ${green("package.json")} & ${blue(".github")}`);
88
- console.log(`- Change ${blue("valaxy.config.ts")} theme: ${yellow("starter")} to ${cyan(`${themeName}`)}`);
89
- console.log(`- Rename ${yellow(`valaxy-theme-${themeName}`)} to ${cyan(`valaxy-theme-${themeName}`)}`);
90
- console.log();
91
- console.log(` ${cyan("\u2728")}`);
92
- console.log();
93
- return `valaxy-theme-${themeName}`;
94
- }
95
-
96
- const renameFiles = {
97
- _gitignore: ".gitignore",
98
- _npmrc: ".npmrc"
99
- };
100
- const TEMPLATES = [
101
- {
102
- name: "blog",
103
- display: `Blog`,
104
- desc: "For Most Users",
105
- message: "Project name:",
106
- initial: "valaxy-blog",
107
- color: cyan
108
- },
109
- {
110
- name: "theme",
111
- display: `Theme`,
112
- desc: "For Theme Developers",
113
- message: "Theme name: valaxy-theme-",
114
- initial: "starter",
115
- prefix: "valaxy-theme-",
116
- color: green,
117
- customInit: async (options) => {
118
- return initTheme(options).catch((e) => {
119
- console.error(e);
120
- });
121
- }
122
- },
123
- {
124
- name: "addon",
125
- display: `Addon`,
126
- desc: "For Addon Developers",
127
- message: "Addon name: valaxy-addon-",
128
- initial: "template",
129
- prefix: "valaxy-addon-",
130
- color: yellow
131
- }
132
- ];
133
- const TEMPLATE_CHOICES = TEMPLATES.map((template) => template.name);
134
-
135
- const argv = minimist(process.argv.slice(2));
136
- const cwd = process.cwd();
137
- const defaultTargetDir = "valaxy-blog";
138
- async function init() {
139
- console.log();
140
- console.log(` ${bold("\u{1F30C} Valaxy")} ${blue(`v${version}`)}`);
141
- console.log();
142
- const argTargetDir = formatTargetDir(argv._[0]);
143
- const argTemplate = argv.template || argv.t;
144
- let targetDir = argTargetDir || defaultTargetDir;
145
- const getProjectName = () => targetDir === "." ? path.basename(path.resolve()) : targetDir;
146
- let result;
147
- const { template } = await prompts({
148
- type: argTemplate && TEMPLATE_CHOICES.includes(argTemplate) ? null : "select",
149
- name: "template",
150
- message: typeof argTemplate === "string" && !TEMPLATE_CHOICES.includes(argTemplate) ? reset(
151
- `"${argTemplate}" isn't a valid template. Please choose from below: `
152
- ) : reset("Select a type:"),
153
- initial: 0,
154
- choices: TEMPLATES.map((template2) => {
155
- const tColor = template2.color;
156
- return {
157
- title: tColor(template2.display || template2.name) + dim(` - ${template2.desc}`),
158
- value: template2
159
- };
160
- })
161
- });
162
- try {
163
- result = await prompts([
164
- {
165
- type: argTargetDir ? null : "text",
166
- name: "projectName",
167
- message: reset(template.message),
168
- initial: template.initial,
169
- onState: (state) => {
170
- targetDir = formatTargetDir(template.prefix ? template.prefix + state.value : state.value) || template.initial;
171
- }
172
- },
173
- {
174
- type: () => !fs.existsSync(targetDir) || isEmpty(targetDir) ? null : "confirm",
175
- name: "overwrite",
176
- message: () => `${targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`} is not empty. Remove existing files and continue?`
177
- },
178
- {
179
- type: (_, { overwrite: overwrite2 }) => {
180
- if (overwrite2 === false)
181
- throw new Error(`${red("\u2716")} Operation cancelled`);
182
- return null;
183
- },
184
- name: "overwriteChecker"
185
- },
186
- {
187
- type: () => isValidPackageName(getProjectName()) ? null : "text",
188
- name: "packageName",
189
- message: reset("Package name:"),
190
- initial: () => toValidPackageName(getProjectName()),
191
- validate: (dir) => isValidPackageName(dir) || "Invalid package.json name"
192
- }
193
- ], {
194
- onCancel: () => {
195
- throw new Error(`${red("\u2716")} Operation cancelled`);
196
- }
197
- });
198
- } catch (cancelled) {
199
- console.log(cancelled.message);
200
- return;
201
- }
202
- const { projectName, overwrite } = result;
203
- const dirName = template.prefix ? template.prefix + projectName : projectName;
204
- const root = path.join(cwd, dirName);
205
- if (overwrite)
206
- emptyDir(root);
207
- else if (!fs.existsSync(root))
208
- fs.mkdirSync(root, { recursive: true });
209
- if (template.customInit) {
210
- await template.customInit({ themeName: projectName });
211
- } else {
212
- const templateDir = path.resolve(
213
- fileURLToPath(import.meta.url),
214
- "../..",
215
- `template-${template.name}`
216
- );
217
- const write = (filename, content) => {
218
- const targetPath = renameFiles[filename] ? path.join(root, renameFiles[filename]) : path.join(root, filename);
219
- if (content)
220
- fs.writeFileSync(targetPath, content);
221
- else
222
- copy(path.join(templateDir, filename), targetPath);
223
- };
224
- const files = fs.readdirSync(templateDir);
225
- for (const file of files.filter((f) => f !== "package.json"))
226
- write(file);
227
- const pkg = await import(path.join(templateDir, "package.json"));
228
- pkg.name = projectName || getProjectName();
229
- write("package.json", JSON.stringify(pkg, null, 2));
230
- }
231
- console.log(` ${dim("\u{1F4C1}")} ${dim(root)}`);
232
- console.log();
233
- console.log(dim(" Scaffolding project in ") + targetDir + dim(" ..."));
234
- const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
235
- const pkgManager = pkgInfo ? pkgInfo.name : "npm";
236
- const related = path.relative(cwd, root);
237
- console.log(green(" Done.\n"));
238
- if (template.name === "addon")
239
- return;
240
- const { yes } = await prompts({
241
- type: "confirm",
242
- name: "yes",
243
- initial: "Y",
244
- message: "Install and start it now?"
245
- });
246
- if (yes) {
247
- const { agent } = await prompts({
248
- name: "agent",
249
- type: "select",
250
- message: "Choose the agent",
251
- choices: ["npm", "yarn", "pnpm"].map((i) => ({ value: i, title: i }))
252
- });
253
- if (!agent)
254
- return;
255
- await execa(agent, ["install"], { stdio: "inherit", cwd: root });
256
- await execa(agent, ["run", "dev"], { stdio: "inherit", cwd: root });
257
- } else {
258
- console.log(dim("\n start it later by:\n"));
259
- if (root !== cwd)
260
- console.log(` ${green("cd")} ${blue(related)}`);
261
- switch (pkgManager) {
262
- case "yarn":
263
- console.log(` ${green("yarn")}`);
264
- console.log(` ${green("yarn")} dev`);
265
- break;
266
- default:
267
- console.log(` ${green(pkgManager)} install`);
268
- console.log(` ${green(pkgManager)} run dev`);
269
- break;
270
- }
271
- console.log();
272
- console.log(` ${cyan("\u2728")}`);
273
- }
274
- }
275
-
276
- init().catch((e) => {
277
- console.error(e);
278
- });
1
+ import S from"node:process";import a from"node:fs";import i from"node:path";import{fileURLToPath as U}from"node:url";import{execa as k}from"execa";import{red as j,dim as m,gray as J,blue as y,yellow as u,bold as C,green as g,cyan as f,reset as x}from"kolorist";import B from"minimist";import v from"prompts";const G="0.15.3";function D(e){return e?.trim().replace(/\/+$/g,"")}function H(e){const o=a.readdirSync(e);return o.length===0||o.length===1&&o[0]===".git"}function I(e,o){a.statSync(e).isDirectory()?K(e,o):a.copyFileSync(e,o)}function K(e,o){a.mkdirSync(o,{recursive:!0});for(const n of a.readdirSync(e)){const c=i.resolve(e,n),p=i.resolve(o,n);I(c,p)}}function Y(e){if(console.log(`
2
+ ${j("Removing")} ${m(e)}`),!!a.existsSync(e))for(const o of a.readdirSync(e))o!==".git"&&a.rmSync(i.resolve(e,o),{recursive:!0,force:!0})}function P(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function q(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function Q(e){if(!e)return;const o=e.split(" ")[0].split("/");return{name:o[0],version:o[1]}}const b={name:"starter",display:"Starter",repo:"https://github.com/valaxyjs/valaxy-theme-starter"};async function W(e){const o=b.name;let n=e.themeName||o;if(!n){const{theme:p}=await v({type:"text",name:"theme",message:"Theme name: valaxy-theme-",initial:o});n=p||o}const c=`valaxy-theme-${n.trim()}`;return console.log(` ${m("npx")} ${J("degit")} ${y(b.repo)} ${u(c)}`),await k("npx",["degit",b.repo,c],{stdio:"inherit"}),console.log(),console.log(` ${C("Check it")}:`),console.log(),console.log(`- Change ${C("author")} name in ${u("LICENSE")} & ${g("package.json")} & ${y(".github")}`),console.log(`- Change ${y("valaxy.config.ts")} theme: ${u("starter")} to ${f(`${n}`)}`),console.log(`- Rename ${u(`valaxy-theme-${n}`)} to ${f(`valaxy-theme-${n}`)}`),console.log(),console.log(` ${f("\u2728")}`),console.log(),`valaxy-theme-${n}`}const X={_gitignore:".gitignore",_npmrc:".npmrc"},A=[{name:"blog",display:"Blog",desc:"For Most Users",message:"Project name:",initial:"valaxy-blog",color:f},{name:"theme",display:"Theme",desc:"For Theme Developers",message:"Theme name: valaxy-theme-",initial:"starter",prefix:"valaxy-theme-",color:g,customInit:async e=>W(e).catch(o=>{console.error(o)})},{name:"addon",display:"Addon",desc:"For Addon Developers",message:"Addon name: valaxy-addon-",initial:"template",prefix:"valaxy-addon-",color:u}],O=A.map(e=>e.name),T=B(S.argv.slice(2)),E=S.cwd(),Z="valaxy-blog",ee=U(import.meta.url);async function oe(){console.log(),console.log(` ${C("\u{1F30C} Valaxy")} ${y(`v${G}`)}`),console.log();const e=D(T._[0]),o=T.template||T.t;let n=e||Z;const c=()=>n==="."?i.basename(i.resolve()):n;let p;const{template:r}=await v({type:o&&O.includes(o)?null:"select",name:"template",message:typeof o=="string"&&!O.includes(o)?x(`"${o}" isn't a valid template. Please choose from below: `):x("Select a type:"),initial:0,choices:A.map(t=>{const s=t.color;return{title:s(t.display||t.name)+m(` - ${t.desc}`),value:t}})});try{p=await v([{type:e?null:"text",name:"projectName",message:x(r.message),initial:r.initial,onState:t=>{n=D(r.prefix?r.prefix+t.value:t.value)||r.initial}},{type:()=>!a.existsSync(n)||H(n)?null:"confirm",name:"overwrite",message:()=>`${n==="."?"Current directory":`Target directory "${n}"`} is not empty. Remove existing files and continue?`},{type:(t,{overwrite:s})=>{if(s===!1)throw new Error(`${j("\u2716")} Operation cancelled`);return null},name:"overwriteChecker"},{type:()=>P(c())?null:"text",name:"packageName",message:x("Package name:"),initial:()=>q(c()),validate:t=>P(t)||"Invalid package.json name"}],{onCancel:()=>{throw new Error(`${j("\u2716")} Operation cancelled`)}})}catch(t){console.log(t.message);return}const{projectName:$,overwrite:z}=p,L=r.prefix?r.prefix+$:$,l=i.join(E,L);if(z?Y(l):a.existsSync(l)||a.mkdirSync(l,{recursive:!0}),r.customInit)await r.customInit({themeName:$});else{const t=i.resolve(ee,"../..",`template-${r.name}`),s=(d,h)=>{const _=i.join(l,X[d]??d);h?a.writeFileSync(_,h):I(i.join(t,d),_)},M=a.readdirSync(t);for(const d of M.filter(h=>h!=="package.json"))s(d);const N=JSON.parse(a.readFileSync(i.join(t,"package.json"),"utf-8"));N.name=$||c(),s("package.json",`${JSON.stringify(N,null,2)}
3
+ `)}console.log(` ${m("\u{1F4C1}")} ${m(l)}`),console.log(),console.log(m(" Scaffolding project in ")+n+m(" ..."));const F=Q(S.env.npm_config_user_agent),w=F?F.name:"npm",R=i.relative(E,l);if(console.log(g(` Done.
4
+ `)),r.name==="addon")return;const{yes:V}=await v({type:"confirm",name:"yes",initial:"Y",message:"Install and start it now?"});if(V){const{agent:t}=await v({name:"agent",type:"select",message:"Choose the agent",choices:["npm","yarn","pnpm"].map(s=>({value:s,title:s}))});if(!t)return;await k(t,["install"],{stdio:"inherit",cwd:l}),await k(t,["run","dev"],{stdio:"inherit",cwd:l})}else{switch(console.log(m(`
5
+ start it later by:
6
+ `)),l!==E&&console.log(` ${g("cd")} ${y(R)}`),w){case"yarn":console.log(` ${g("yarn")}`),console.log(` ${g("yarn")} dev`);break;default:console.log(` ${g(w)} install`),console.log(` ${g(w)} run dev`);break}console.log(),console.log(` ${f("\u2728")}`)}}oe().catch(e=>{console.error(e)});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-valaxy",
3
3
  "type": "module",
4
- "version": "0.15.2-dev.0",
4
+ "version": "0.15.3",
5
5
  "description": "Create Starter Template for Valaxy",
6
6
  "author": {
7
7
  "email": "me@yunyoujun.cn",
@@ -18,20 +18,24 @@
18
18
  "bin": {
19
19
  "create-valaxy": "bin/index.mjs"
20
20
  },
21
+ "files": [
22
+ "bin",
23
+ "dist",
24
+ "template-*"
25
+ ],
21
26
  "engines": {
22
- "node": "^14.18.0 || >=16.0.0"
23
- },
24
- "scripts": {
25
- "build": "unbuild",
26
- "dev": "unbuild --stub",
27
- "prepublishOnly": "npm run build",
28
- "start": "tsx src/index.ts",
29
- "typecheck": "tsc --noEmit"
27
+ "node": "^18.0.0 || >=20.0.0"
30
28
  },
31
29
  "dependencies": {
32
30
  "execa": "8.0.1",
33
31
  "kolorist": "^1.8.0",
34
32
  "minimist": "^1.2.8",
35
33
  "prompts": "^2.4.2"
34
+ },
35
+ "scripts": {
36
+ "build": "unbuild",
37
+ "dev": "unbuild --stub",
38
+ "start": "tsx src/index.ts",
39
+ "typecheck": "tsc --noEmit"
36
40
  }
37
- }
41
+ }
@@ -12,8 +12,8 @@
12
12
  "serve": "vite preview"
13
13
  },
14
14
  "dependencies": {
15
- "valaxy": "0.15.2",
16
- "valaxy-theme-yun": "0.15.2"
15
+ "valaxy": "0.15.3",
16
+ "valaxy-theme-yun": "0.15.3"
17
17
  },
18
18
  "devDependencies": {
19
19
  "typescript": "^5.2.2"
package/build.config.ts DELETED
@@ -1,3 +0,0 @@
1
- export default {
2
- entries: ['./src/index'],
3
- }
package/src/config.ts DELETED
@@ -1,45 +0,0 @@
1
- import { cyan, green, yellow } from 'kolorist'
2
- import { initTheme } from './theme'
3
-
4
- export const renameFiles: Record<string, string> = {
5
- _gitignore: '.gitignore',
6
- _npmrc: '.npmrc',
7
- }
8
-
9
- export const TEMPLATES = [
10
- {
11
- name: 'blog',
12
- display: `Blog`,
13
- desc: 'For Most Users',
14
- message: 'Project name:',
15
- initial: 'valaxy-blog',
16
- color: cyan,
17
- },
18
- {
19
- name: 'theme',
20
- display: `Theme`,
21
- desc: 'For Theme Developers',
22
- message: 'Theme name: valaxy-theme-',
23
- initial: 'starter',
24
- prefix: 'valaxy-theme-',
25
- color: green,
26
- customInit: async (options: {
27
- themeName?: string
28
- }) => {
29
- return initTheme(options).catch((e) => {
30
- console.error(e)
31
- })
32
- },
33
- },
34
- {
35
- name: 'addon',
36
- display: `Addon`,
37
- desc: 'For Addon Developers',
38
- message: 'Addon name: valaxy-addon-',
39
- initial: 'template',
40
- prefix: 'valaxy-addon-',
41
- color: yellow,
42
- },
43
- ]
44
-
45
- export const TEMPLATE_CHOICES = TEMPLATES.map(template => template.name)
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { init } from './valaxy'
3
-
4
- init().catch((e) => {
5
- console.error(e)
6
- })
package/src/theme.ts DELETED
@@ -1,46 +0,0 @@
1
- /* eslint-disable no-console */
2
- import prompts from 'prompts'
3
- import { execa } from 'execa'
4
- import { blue, bold, cyan, dim, gray, green, yellow } from 'kolorist'
5
-
6
- const starterTheme = {
7
- name: 'starter',
8
- display: `Starter`,
9
- repo: 'https://github.com/valaxyjs/valaxy-theme-starter',
10
- }
11
-
12
- export async function initTheme(options: {
13
- themeName?: string
14
- }) {
15
- const defaultThemeName = starterTheme.name
16
- let themeName = options.themeName || defaultThemeName
17
- if (!themeName) {
18
- /**
19
- * @type {{ theme: string }}
20
- */
21
- const { theme } = await prompts({
22
- type: 'text',
23
- name: 'theme',
24
- message: 'Theme name: valaxy-theme-',
25
- initial: defaultThemeName,
26
- })
27
- themeName = theme || defaultThemeName
28
- }
29
-
30
- const targetDir = `valaxy-theme-${themeName!.trim()}`
31
-
32
- console.log(` ${dim('npx')} ${gray('degit')} ${blue(starterTheme.repo)} ${yellow(targetDir)}`)
33
- await execa('npx', ['degit', starterTheme.repo, targetDir], { stdio: 'inherit' })
34
-
35
- console.log()
36
- console.log(` ${bold('Check it')}:`)
37
- console.log()
38
- console.log(`- Change ${bold('author')} name in ${yellow('LICENSE')} & ${green('package.json')} & ${blue('.github')}`)
39
- console.log(`- Change ${blue('valaxy.config.ts')} theme: ${yellow('starter')} to ${cyan(`${themeName}`)}`)
40
- console.log(`- Rename ${yellow(`valaxy-theme-${themeName}`)} to ${cyan(`valaxy-theme-${themeName}`)}`)
41
- console.log()
42
- console.log(` ${cyan('✨')}`)
43
- console.log()
44
-
45
- return `valaxy-theme-${themeName}`
46
- }
package/src/utils.ts DELETED
@@ -1,73 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { dim, red } from 'kolorist'
4
-
5
- /**
6
- * remove trailing slash
7
- */
8
- export function formatTargetDir(targetDir: string | undefined) {
9
- return targetDir?.trim().replace(/\/+$/g, '')
10
- }
11
-
12
- export function isEmpty(path: string) {
13
- const files = fs.readdirSync(path)
14
- return files.length === 0 || (files.length === 1 && files[0] === '.git')
15
- }
16
-
17
- export function copy(src: string, dest: string) {
18
- const stat = fs.statSync(src)
19
- if (stat.isDirectory())
20
- copyDir(src, dest)
21
-
22
- else
23
- fs.copyFileSync(src, dest)
24
- }
25
-
26
- export function copyDir(srcDir: string, destDir: string) {
27
- fs.mkdirSync(destDir, { recursive: true })
28
- for (const file of fs.readdirSync(srcDir)) {
29
- const srcFile = path.resolve(srcDir, file)
30
- const destFile = path.resolve(destDir, file)
31
- copy(srcFile, destFile)
32
- }
33
- }
34
-
35
- export function emptyDir(dir: string) {
36
- // eslint-disable-next-line no-console
37
- console.log(`\n ${red(`Removing`)} ${dim(dir)}`)
38
- if (!fs.existsSync(dir))
39
- return
40
-
41
- for (const file of fs.readdirSync(dir)) {
42
- if (file === '.git')
43
- continue
44
-
45
- fs.rmSync(path.resolve(dir, file), { recursive: true, force: true })
46
- }
47
- }
48
-
49
- export function isValidPackageName(projectName: string) {
50
- return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(
51
- projectName,
52
- )
53
- }
54
-
55
- export function toValidPackageName(projectName: string) {
56
- return projectName
57
- .trim()
58
- .toLowerCase()
59
- .replace(/\s+/g, '-')
60
- .replace(/^[._]/, '')
61
- .replace(/[^a-z\d\-~]+/g, '-')
62
- }
63
-
64
- export function pkgFromUserAgent(userAgent: string | undefined) {
65
- if (!userAgent)
66
- return undefined
67
- const pkgSpec = userAgent.split(' ')[0]
68
- const pkgSpecArr = pkgSpec.split('/')
69
- return {
70
- name: pkgSpecArr[0],
71
- version: pkgSpecArr[1],
72
- }
73
- }