@remyyy/create-velox 0.0.1 → 0.0.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.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @remyyy/create-velox
2
+
3
+ **Scaffolding tool for the Velox Framework**
4
+
5
+ Get started with Velox in seconds.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ npm create @remyyy/velox@latest
11
+ ```
12
+
13
+ This command will prompt you to select a template:
14
+
15
+ - **Vanilla TypeScript** (Recommended)
16
+ - **Vanilla JavaScript**
17
+
18
+ ## Documentation
19
+
20
+ For full documentation, visit the [main repository](https://github.com/TheRemyyy/velox-framework).
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import n from"fs";import o from"path";import{fileURLToPath as h}from"url";import j from"minimist";import k from"prompts";import{red as g,green as d,bold as N}from"kolorist";var x=j(process.argv.slice(2),{string:["_"]}),p=process.cwd(),F=[{name:"vanilla-ts",display:"Vanilla TypeScript",color:d},{name:"vanilla-js",display:"Vanilla JavaScript",color:g}],T={_gitignore:".gitignore"};async function D(){let r="@remyyy/velox-project",e=x._[0]||r,i;try{i=await k([{type:e?null:"text",name:"projectName",message:"Project name:",initial:r,onState:t=>{e=t.value.trim()||r}},{type:()=>!n.existsSync(e)||C(e)?null:"confirm",name:"overwrite",message:()=>(e==="."?"Current directory":`Target directory "${e}"`)+" is not empty. Remove existing files and continue?"},{type:(t,{overwrite:c})=>{if(c===!1)throw new Error(g("\u2716")+" Operation cancelled");return null},name:"overwriteChecker"},{type:"select",name:"framework",message:"Select a variant:",initial:0,choices:F.map(t=>{let c=t.color;return{title:c(t.display||t.name),value:t}})}],{onCancel:()=>{throw new Error(g("\u2716")+" Operation cancelled")}})}catch(t){console.log(t.message);return}let{framework:a,overwrite:l,packageName:S}=i,s=o.join(p,e);l?O(s):n.existsSync(s)||n.mkdirSync(s,{recursive:!0});let m=o.resolve(h(import.meta.url),"../..",`templates/${a.name}`),f=(t,c)=>{let u=o.join(s,T[t]??t);c?n.writeFileSync(u,c):v(o.join(m,t),u)},w=n.readdirSync(m);for(let t of w)f(t);let y=JSON.parse(n.readFileSync(o.join(m,"package.json"),"utf-8"));y.name=S||e,f("package.json",JSON.stringify(y,null,2)),console.log(`
3
+ ${N(d("Done!"))} Now run:
4
+ `),s!==p&&console.log(` cd ${o.relative(p,s)}`),console.log(" npm install"),console.log(" npm run dev"),console.log()}function v(r,e){n.statSync(r).isDirectory()?E(r,e):n.copyFileSync(r,e)}function E(r,e){n.mkdirSync(e,{recursive:!0});for(let i of n.readdirSync(r)){let a=o.resolve(r,i),l=o.resolve(e,i);v(a,l)}}function C(r){let e=n.readdirSync(r);return e.length===0||e.length===1&&e[0]===".git"}function O(r){if(n.existsSync(r))for(let e of n.readdirSync(r))e!==".git"&&n.rmSync(o.resolve(r,e),{recursive:!0,force:!0})}D().catch(r=>{console.error(r)});
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@remyyy/create-velox",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "Scaffolding tool for Velox Framework",
8
8
  "bin": {
9
- "create-velox": "index.js",
10
- "cv": "index.js"
9
+ "create-velox": "dist/index.mjs",
10
+ "cv": "dist/index.mjs"
11
11
  },
12
- "main": "index.js",
12
+ "files": [
13
+ "dist",
14
+ "templates",
15
+ "README.md"
16
+ ],
17
+ "main": "dist/index.mjs",
13
18
  "scripts": {
14
19
  "build": "tsup src/index.ts --format esm --clean --minify",
15
20
  "dev": "tsup src/index.ts --format esm --watch",
package/src/index.ts DELETED
@@ -1,174 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
- import minimist from 'minimist'
5
- import prompts from 'prompts'
6
- import { red, green, bold } from 'kolorist'
7
-
8
- const argv = minimist(process.argv.slice(2), { string: ['_'] })
9
- const cwd = process.cwd()
10
-
11
- const TEMPLATES = [
12
- {
13
- name: 'vanilla-ts',
14
- display: 'Vanilla TypeScript',
15
- color: green
16
- },
17
- {
18
- name: 'vanilla-js',
19
- display: 'Vanilla JavaScript',
20
- color: red // Just for distinction
21
- }
22
- ]
23
-
24
- const renameFiles: Record<string, string | undefined> = {
25
- _gitignore: '.gitignore'
26
- }
27
-
28
- async function init() {
29
- const defaultTargetDir = '@remyyy/velox-project'
30
- let targetDir = argv._[0] || defaultTargetDir
31
-
32
- let result: prompts.Answers<'projectName' | 'overwrite' | 'packageName' | 'framework'>
33
-
34
- try {
35
- result = await prompts(
36
- [
37
- {
38
- type: targetDir ? null : 'text',
39
- name: 'projectName',
40
- message: 'Project name:',
41
- initial: defaultTargetDir,
42
- onState: (state) => {
43
- targetDir = state.value.trim() || defaultTargetDir
44
- }
45
- },
46
- {
47
- type: () =>
48
- !fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
49
- name: 'overwrite',
50
- message: () =>
51
- (targetDir === '.'
52
- ? 'Current directory'
53
- : `Target directory "${targetDir}"`) +
54
- ` is not empty. Remove existing files and continue?`
55
- },
56
- {
57
- type: (_, { overwrite }: { overwrite?: boolean }) => {
58
- if (overwrite === false) {
59
- throw new Error(red('✖') + ' Operation cancelled')
60
- }
61
- return null
62
- },
63
- name: 'overwriteChecker'
64
- },
65
- {
66
- type: 'select',
67
- name: 'framework',
68
- message: 'Select a variant:',
69
- initial: 0,
70
- choices: TEMPLATES.map((framework) => {
71
- const frameworkColor = framework.color
72
- return {
73
- title: frameworkColor(framework.display || framework.name),
74
- value: framework
75
- }
76
- })
77
- }
78
- ],
79
- {
80
- onCancel: () => {
81
- throw new Error(red('✖') + ' Operation cancelled')
82
- }
83
- }
84
- )
85
- } catch (cancelled: any) {
86
- console.log(cancelled.message)
87
- return
88
- }
89
-
90
- const { framework, overwrite, packageName } = result
91
- const root = path.join(cwd, targetDir)
92
-
93
- if (overwrite) {
94
- emptyDir(root)
95
- } else if (!fs.existsSync(root)) {
96
- fs.mkdirSync(root, { recursive: true })
97
- }
98
-
99
- // Determine template
100
- const templateDir = path.resolve(
101
- fileURLToPath(import.meta.url),
102
- '../..',
103
- `templates/${framework.name}`
104
- )
105
-
106
- const write = (file: string, content?: string) => {
107
- const targetPath = path.join(root, renameFiles[file] ?? file)
108
- if (content) {
109
- fs.writeFileSync(targetPath, content)
110
- } else {
111
- copy(path.join(templateDir, file), targetPath)
112
- }
113
- }
114
-
115
- const files = fs.readdirSync(templateDir)
116
- for (const file of files) {
117
- write(file)
118
- }
119
-
120
- const pkg = JSON.parse(
121
- fs.readFileSync(path.join(templateDir, 'package.json'), 'utf-8')
122
- )
123
-
124
- pkg.name = packageName || targetDir
125
-
126
- write('package.json', JSON.stringify(pkg, null, 2))
127
-
128
- console.log(`\n${bold(green('Done!'))} Now run:\n`)
129
- if (root !== cwd) {
130
- console.log(` cd ${path.relative(cwd, root)}`)
131
- }
132
- console.log(` npm install`)
133
- console.log(` npm run dev`)
134
- console.log()
135
- }
136
-
137
- function copy(src: string, dest: string) {
138
- const stat = fs.statSync(src)
139
- if (stat.isDirectory()) {
140
- copyDir(src, dest)
141
- } else {
142
- fs.copyFileSync(src, dest)
143
- }
144
- }
145
-
146
- function copyDir(srcDir: string, destDir: string) {
147
- fs.mkdirSync(destDir, { recursive: true })
148
- for (const file of fs.readdirSync(srcDir)) {
149
- const srcFile = path.resolve(srcDir, file)
150
- const destFile = path.resolve(destDir, file)
151
- copy(srcFile, destFile)
152
- }
153
- }
154
-
155
- function isEmpty(path: string) {
156
- const files = fs.readdirSync(path)
157
- return files.length === 0 || (files.length === 1 && files[0] === '.git')
158
- }
159
-
160
- function emptyDir(dir: string) {
161
- if (!fs.existsSync(dir)) {
162
- return
163
- }
164
- for (const file of fs.readdirSync(dir)) {
165
- if (file === '.git') {
166
- continue
167
- }
168
- fs.rmSync(path.resolve(dir, file), { recursive: true, force: true })
169
- }
170
- }
171
-
172
- init().catch((e) => {
173
- console.error(e)
174
- })
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "target": "es2020",
6
- "module": "esnext",
7
- "moduleResolution": "bundler",
8
- "esModuleInterop": true,
9
- "lib": [
10
- "esnext",
11
- "dom"
12
- ],
13
- "skipLibCheck": true
14
- },
15
- "include": [
16
- "src"
17
- ]
18
- }