makepack 1.7.14 → 1.7.15
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 +365 -122
- package/package.json +62 -62
- package/src/actions/build/bundler.js +131 -131
- package/src/actions/build/index.js +74 -74
- package/src/actions/create/files/gitignore.js +9 -9
- package/src/actions/create/files/main.js +36 -36
- package/src/actions/create/files/package-json.js +49 -49
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +50 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +50 -50
- package/src/actions/create/files/readme.md.js +62 -62
- package/src/actions/create/files/tsconfig.js +33 -33
- package/src/actions/create/index.js +95 -95
- package/src/actions/create/makeFiles.js +65 -65
- package/src/actions/release/index.js +19 -19
- package/src/actions/start/index.js +215 -215
- package/src/actions/start/vite.js +72 -72
- package/src/helpers.js +120 -120
- package/src/index.js +39 -39
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `import React, { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
const Index = () => {
|
|
5
|
-
const [count, setCount] = useState(0);
|
|
6
|
-
const increment = () => setCount(prevCount => prevCount + 1);
|
|
7
|
-
const decrement = () => setCount(prevCount => prevCount - 1);
|
|
8
|
-
const reset = () => setCount(0);
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div style={styles.container}>
|
|
12
|
-
<h1>Count App</h1>
|
|
13
|
-
<div style={styles.counter}>{count}</div>
|
|
14
|
-
<div style={styles.buttonContainer}>
|
|
15
|
-
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
-
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
-
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const styles = {
|
|
24
|
-
container: {
|
|
25
|
-
textAlign: 'center',
|
|
26
|
-
padding: '20px',
|
|
27
|
-
fontFamily: 'Arial, sans-serif'
|
|
28
|
-
},
|
|
29
|
-
counter: {
|
|
30
|
-
fontSize: '2rem',
|
|
31
|
-
margin: '20px 0',
|
|
32
|
-
},
|
|
33
|
-
buttonContainer: {
|
|
34
|
-
display: 'flex',
|
|
35
|
-
justifyContent: 'center',
|
|
36
|
-
gap: '10px',
|
|
37
|
-
},
|
|
38
|
-
button: {
|
|
39
|
-
padding: '10px 20px',
|
|
40
|
-
fontSize: '1rem',
|
|
41
|
-
cursor: 'pointer',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default Index;
|
|
46
|
-
`
|
|
47
|
-
return {
|
|
48
|
-
content,
|
|
49
|
-
filename: `src/index.jsx`
|
|
50
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `import React, { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
const Index = () => {
|
|
5
|
+
const [count, setCount] = useState(0);
|
|
6
|
+
const increment = () => setCount(prevCount => prevCount + 1);
|
|
7
|
+
const decrement = () => setCount(prevCount => prevCount - 1);
|
|
8
|
+
const reset = () => setCount(0);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div style={styles.container}>
|
|
12
|
+
<h1>Count App</h1>
|
|
13
|
+
<div style={styles.counter}>{count}</div>
|
|
14
|
+
<div style={styles.buttonContainer}>
|
|
15
|
+
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
+
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
+
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const styles = {
|
|
24
|
+
container: {
|
|
25
|
+
textAlign: 'center',
|
|
26
|
+
padding: '20px',
|
|
27
|
+
fontFamily: 'Arial, sans-serif'
|
|
28
|
+
},
|
|
29
|
+
counter: {
|
|
30
|
+
fontSize: '2rem',
|
|
31
|
+
margin: '20px 0',
|
|
32
|
+
},
|
|
33
|
+
buttonContainer: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
gap: '10px',
|
|
37
|
+
},
|
|
38
|
+
button: {
|
|
39
|
+
padding: '10px 20px',
|
|
40
|
+
fontSize: '1rem',
|
|
41
|
+
cursor: 'pointer',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default Index;
|
|
46
|
+
`
|
|
47
|
+
return {
|
|
48
|
+
content,
|
|
49
|
+
filename: `src/index.jsx`
|
|
50
|
+
}
|
|
51
51
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `
|
|
3
|
-
function sum(a: number, b: number): number {
|
|
4
|
-
return a + b;
|
|
5
|
-
}
|
|
6
|
-
export default sum`
|
|
7
|
-
return {
|
|
8
|
-
content,
|
|
9
|
-
filename: `src/index.ts`
|
|
10
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `
|
|
3
|
+
function sum(a: number, b: number): number {
|
|
4
|
+
return a + b;
|
|
5
|
+
}
|
|
6
|
+
export default sum`
|
|
7
|
+
return {
|
|
8
|
+
content,
|
|
9
|
+
filename: `src/index.ts`
|
|
10
|
+
}
|
|
11
11
|
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `import React, { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
const Index: React.FC = () => {
|
|
5
|
-
const [count, setCount] = useState<number>(0);
|
|
6
|
-
const increment = (): void => setCount(prevCount => prevCount + 1);
|
|
7
|
-
const decrement = (): void => setCount(prevCount => prevCount - 1);
|
|
8
|
-
const reset = (): void => setCount(0);
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div style={styles.container}>
|
|
12
|
-
<h1>Count App</h1>
|
|
13
|
-
<div style={styles.counter}>{count}</div>
|
|
14
|
-
<div style={styles.buttonContainer}>
|
|
15
|
-
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
-
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
-
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const styles: { [key: string]: React.CSSProperties } = {
|
|
24
|
-
container: {
|
|
25
|
-
textAlign: 'center',
|
|
26
|
-
padding: '20px',
|
|
27
|
-
fontFamily: 'Arial, sans-serif',
|
|
28
|
-
},
|
|
29
|
-
counter: {
|
|
30
|
-
fontSize: '2rem',
|
|
31
|
-
margin: '20px 0',
|
|
32
|
-
},
|
|
33
|
-
buttonContainer: {
|
|
34
|
-
display: 'flex',
|
|
35
|
-
justifyContent: 'center',
|
|
36
|
-
gap: '10px',
|
|
37
|
-
},
|
|
38
|
-
button: {
|
|
39
|
-
padding: '10px 20px',
|
|
40
|
-
fontSize: '1rem',
|
|
41
|
-
cursor: 'pointer',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default Index;
|
|
46
|
-
`
|
|
47
|
-
return {
|
|
48
|
-
content,
|
|
49
|
-
filename: `src/index.tsx`
|
|
50
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `import React, { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
const Index: React.FC = () => {
|
|
5
|
+
const [count, setCount] = useState<number>(0);
|
|
6
|
+
const increment = (): void => setCount(prevCount => prevCount + 1);
|
|
7
|
+
const decrement = (): void => setCount(prevCount => prevCount - 1);
|
|
8
|
+
const reset = (): void => setCount(0);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div style={styles.container}>
|
|
12
|
+
<h1>Count App</h1>
|
|
13
|
+
<div style={styles.counter}>{count}</div>
|
|
14
|
+
<div style={styles.buttonContainer}>
|
|
15
|
+
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
+
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
+
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const styles: { [key: string]: React.CSSProperties } = {
|
|
24
|
+
container: {
|
|
25
|
+
textAlign: 'center',
|
|
26
|
+
padding: '20px',
|
|
27
|
+
fontFamily: 'Arial, sans-serif',
|
|
28
|
+
},
|
|
29
|
+
counter: {
|
|
30
|
+
fontSize: '2rem',
|
|
31
|
+
margin: '20px 0',
|
|
32
|
+
},
|
|
33
|
+
buttonContainer: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
gap: '10px',
|
|
37
|
+
},
|
|
38
|
+
button: {
|
|
39
|
+
padding: '10px 20px',
|
|
40
|
+
fontSize: '1rem',
|
|
41
|
+
cursor: 'pointer',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default Index;
|
|
46
|
+
`
|
|
47
|
+
return {
|
|
48
|
+
content,
|
|
49
|
+
filename: `src/index.tsx`
|
|
50
|
+
}
|
|
51
51
|
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
export default async (info) => {
|
|
3
|
-
let pkgname = info.projectDirName
|
|
4
|
-
const content = `# ${pkgname}
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/${pkgname})
|
|
7
|
-
[](https://github.com/your-username/${pkgname}/blob/main/LICENSE)
|
|
8
|
-
[](https://www.npmjs.com/package/${pkgname})
|
|
9
|
-
|
|
10
|
-
A brief description of what your package does and its purpose.
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
\`\`\`sh
|
|
15
|
-
npm install ${pkgname}
|
|
16
|
-
\`\`\`
|
|
17
|
-
|
|
18
|
-
or with yarn:
|
|
19
|
-
|
|
20
|
-
\`\`\`sh
|
|
21
|
-
yarn add ${pkgname}
|
|
22
|
-
\`\`\`
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
25
|
-
|
|
26
|
-
\`\`\`js
|
|
27
|
-
import { feature } from "${pkgname}";
|
|
28
|
-
|
|
29
|
-
const result = feature("example");
|
|
30
|
-
console.log(result);
|
|
31
|
-
\`\`\`
|
|
32
|
-
|
|
33
|
-
## API
|
|
34
|
-
|
|
35
|
-
### \`feature(input: string): string\`
|
|
36
|
-
Description of the function and its parameters.
|
|
37
|
-
|
|
38
|
-
## Configuration (if applicable)
|
|
39
|
-
Explain any configuration options if your package requires setup.
|
|
40
|
-
|
|
41
|
-
## Examples
|
|
42
|
-
Provide additional usage examples for clarity.
|
|
43
|
-
|
|
44
|
-
## Contributing
|
|
45
|
-
Contributions are welcome! Please follow the guidelines in [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
46
|
-
|
|
47
|
-
## License
|
|
48
|
-
|
|
49
|
-
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
50
|
-
|
|
51
|
-
## Links
|
|
52
|
-
- [GitHub Repository](https://github.com/your-username/${pkgname})
|
|
53
|
-
- [NPM Package](https://www.npmjs.com/package/${pkgname})
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
Feel free to modify this template based on your package's specific needs.
|
|
58
|
-
`;
|
|
59
|
-
return {
|
|
60
|
-
content,
|
|
61
|
-
filename: `readme.md`
|
|
62
|
-
}
|
|
1
|
+
|
|
2
|
+
export default async (info) => {
|
|
3
|
+
let pkgname = info.projectDirName
|
|
4
|
+
const content = `# ${pkgname}
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/${pkgname})
|
|
7
|
+
[](https://github.com/your-username/${pkgname}/blob/main/LICENSE)
|
|
8
|
+
[](https://www.npmjs.com/package/${pkgname})
|
|
9
|
+
|
|
10
|
+
A brief description of what your package does and its purpose.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
\`\`\`sh
|
|
15
|
+
npm install ${pkgname}
|
|
16
|
+
\`\`\`
|
|
17
|
+
|
|
18
|
+
or with yarn:
|
|
19
|
+
|
|
20
|
+
\`\`\`sh
|
|
21
|
+
yarn add ${pkgname}
|
|
22
|
+
\`\`\`
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
\`\`\`js
|
|
27
|
+
import { feature } from "${pkgname}";
|
|
28
|
+
|
|
29
|
+
const result = feature("example");
|
|
30
|
+
console.log(result);
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
### \`feature(input: string): string\`
|
|
36
|
+
Description of the function and its parameters.
|
|
37
|
+
|
|
38
|
+
## Configuration (if applicable)
|
|
39
|
+
Explain any configuration options if your package requires setup.
|
|
40
|
+
|
|
41
|
+
## Examples
|
|
42
|
+
Provide additional usage examples for clarity.
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
Contributions are welcome! Please follow the guidelines in [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
50
|
+
|
|
51
|
+
## Links
|
|
52
|
+
- [GitHub Repository](https://github.com/your-username/${pkgname})
|
|
53
|
+
- [NPM Package](https://www.npmjs.com/package/${pkgname})
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
Feel free to modify this template based on your package's specific needs.
|
|
58
|
+
`;
|
|
59
|
+
return {
|
|
60
|
+
content,
|
|
61
|
+
filename: `readme.md`
|
|
62
|
+
}
|
|
63
63
|
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = {
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"target": "es5",
|
|
5
|
-
"lib": [
|
|
6
|
-
"dom",
|
|
7
|
-
"dom.iterable",
|
|
8
|
-
"esnext"
|
|
9
|
-
],
|
|
10
|
-
"allowJs": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"strict": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"module": "esnext",
|
|
17
|
-
"moduleResolution": "node",
|
|
18
|
-
"resolveJsonModule": true,
|
|
19
|
-
"isolatedModules": true,
|
|
20
|
-
"noEmit": true,
|
|
21
|
-
"jsx": "react"
|
|
22
|
-
},
|
|
23
|
-
"include": ["src"],
|
|
24
|
-
"exclude": [
|
|
25
|
-
"node_modules",
|
|
26
|
-
".mpack",
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
content: JSON.stringify(content, null, 2),
|
|
32
|
-
filename: "tsconfig.json"
|
|
33
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = {
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"lib": [
|
|
6
|
+
"dom",
|
|
7
|
+
"dom.iterable",
|
|
8
|
+
"esnext"
|
|
9
|
+
],
|
|
10
|
+
"allowJs": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"jsx": "react"
|
|
22
|
+
},
|
|
23
|
+
"include": ["src"],
|
|
24
|
+
"exclude": [
|
|
25
|
+
"node_modules",
|
|
26
|
+
".mpack",
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
content: JSON.stringify(content, null, 2),
|
|
32
|
+
filename: "tsconfig.json"
|
|
33
|
+
}
|
|
34
34
|
}
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { execSync, concolor, logger } from "../../helpers.js"
|
|
2
|
-
import makeFiles from "./makeFiles.js"
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import inquirer from 'inquirer'
|
|
5
|
-
import fs from "fs-extra"
|
|
6
|
-
const cwd = process.cwd()
|
|
7
|
-
const cwdFolder = cwd.split(path.sep).pop()
|
|
8
|
-
|
|
9
|
-
const valiateProjectName = (name) => {
|
|
10
|
-
if (!name) {
|
|
11
|
-
console.error("Project name cannot be empty.");
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
15
|
-
console.error("Project name can only contain lowercase letters, numbers, and hyphens.");
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (name.length < 3) {
|
|
19
|
-
console.error("Project name must be at least 3 characters long.");
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (name.length > 50) {
|
|
23
|
-
console.error("Project name must be less than 50 characters long.");
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const create = async () => {
|
|
30
|
-
|
|
31
|
-
let info = await inquirer.prompt([
|
|
32
|
-
{
|
|
33
|
-
type: 'input',
|
|
34
|
-
name: 'pdir',
|
|
35
|
-
message: 'Enter the project name',
|
|
36
|
-
default: cwdFolder
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
type: 'list',
|
|
40
|
-
name: 'template',
|
|
41
|
-
message: 'Select a template',
|
|
42
|
-
choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
|
|
43
|
-
default: "typescript"
|
|
44
|
-
}
|
|
45
|
-
])
|
|
46
|
-
|
|
47
|
-
// check if the pdir is exists
|
|
48
|
-
let pdir = info.pdir.trim().replace(/\s+/g, '-').toLowerCase();
|
|
49
|
-
const isValidProjectName = valiateProjectName(pdir)
|
|
50
|
-
if (!isValidProjectName) return
|
|
51
|
-
|
|
52
|
-
if (pdir !== cwdFolder) {
|
|
53
|
-
if (fs.existsSync(path.join(cwd, pdir))) {
|
|
54
|
-
const { proceed } = await inquirer.prompt([
|
|
55
|
-
{
|
|
56
|
-
type: "confirm",
|
|
57
|
-
name: 'proceed',
|
|
58
|
-
message: "The directory already exists, do you want to overwrite it?",
|
|
59
|
-
default: "No"
|
|
60
|
-
}
|
|
61
|
-
])
|
|
62
|
-
if (!proceed) {
|
|
63
|
-
console.log('Project creation canceled.');
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const rootdir = path.join(cwd, pdir)
|
|
70
|
-
let isCurrentDir = pdir !== cwdFolder
|
|
71
|
-
logger.info("", "Creating project...", false)
|
|
72
|
-
|
|
73
|
-
if (!fs.existsSync(rootdir)) {
|
|
74
|
-
fs.mkdirSync(rootdir)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!fs.existsSync(path.join(rootdir, 'src'))) {
|
|
78
|
-
fs.mkdirSync(path.join(rootdir, 'src'))
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
await makeFiles(info)
|
|
82
|
-
|
|
83
|
-
logger.info("", "Installing Dependencies", false)
|
|
84
|
-
execSync("npm install", {
|
|
85
|
-
cwd: rootdir,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
logger.success("Project setup complete!", "")
|
|
89
|
-
if (isCurrentDir) {
|
|
90
|
-
logger.info(`Run the development server: ${concolor.yellow("npm start")}\nEnjoy your new project! 😊`);
|
|
91
|
-
} else {
|
|
92
|
-
logger.info(`Navigate to your project directory:\n${concolor.yellow("cd " + info.pdir, false)} and Run the development server: ${concolor.yellow("npm start")}\nEnjoy your new project! 😊`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
1
|
+
import { execSync, concolor, logger } from "../../helpers.js"
|
|
2
|
+
import makeFiles from "./makeFiles.js"
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import inquirer from 'inquirer'
|
|
5
|
+
import fs from "fs-extra"
|
|
6
|
+
const cwd = process.cwd()
|
|
7
|
+
const cwdFolder = cwd.split(path.sep).pop()
|
|
8
|
+
|
|
9
|
+
const valiateProjectName = (name) => {
|
|
10
|
+
if (!name) {
|
|
11
|
+
console.error("Project name cannot be empty.");
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
15
|
+
console.error("Project name can only contain lowercase letters, numbers, and hyphens.");
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (name.length < 3) {
|
|
19
|
+
console.error("Project name must be at least 3 characters long.");
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (name.length > 50) {
|
|
23
|
+
console.error("Project name must be less than 50 characters long.");
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const create = async () => {
|
|
30
|
+
|
|
31
|
+
let info = await inquirer.prompt([
|
|
32
|
+
{
|
|
33
|
+
type: 'input',
|
|
34
|
+
name: 'pdir',
|
|
35
|
+
message: 'Enter the project name',
|
|
36
|
+
default: cwdFolder
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: 'list',
|
|
40
|
+
name: 'template',
|
|
41
|
+
message: 'Select a template',
|
|
42
|
+
choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
|
|
43
|
+
default: "typescript"
|
|
44
|
+
}
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
// check if the pdir is exists
|
|
48
|
+
let pdir = info.pdir.trim().replace(/\s+/g, '-').toLowerCase();
|
|
49
|
+
const isValidProjectName = valiateProjectName(pdir)
|
|
50
|
+
if (!isValidProjectName) return
|
|
51
|
+
|
|
52
|
+
if (pdir !== cwdFolder) {
|
|
53
|
+
if (fs.existsSync(path.join(cwd, pdir))) {
|
|
54
|
+
const { proceed } = await inquirer.prompt([
|
|
55
|
+
{
|
|
56
|
+
type: "confirm",
|
|
57
|
+
name: 'proceed',
|
|
58
|
+
message: "The directory already exists, do you want to overwrite it?",
|
|
59
|
+
default: "No"
|
|
60
|
+
}
|
|
61
|
+
])
|
|
62
|
+
if (!proceed) {
|
|
63
|
+
console.log('Project creation canceled.');
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const rootdir = path.join(cwd, pdir)
|
|
70
|
+
let isCurrentDir = pdir !== cwdFolder
|
|
71
|
+
logger.info("", "Creating project...", false)
|
|
72
|
+
|
|
73
|
+
if (!fs.existsSync(rootdir)) {
|
|
74
|
+
fs.mkdirSync(rootdir)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!fs.existsSync(path.join(rootdir, 'src'))) {
|
|
78
|
+
fs.mkdirSync(path.join(rootdir, 'src'))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
await makeFiles(info)
|
|
82
|
+
|
|
83
|
+
logger.info("", "Installing Dependencies", false)
|
|
84
|
+
execSync("npm install", {
|
|
85
|
+
cwd: rootdir,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
logger.success("Project setup complete!", "")
|
|
89
|
+
if (isCurrentDir) {
|
|
90
|
+
logger.info(`Run the development server: ${concolor.yellow("npm start")}\nEnjoy your new project! 😊`);
|
|
91
|
+
} else {
|
|
92
|
+
logger.info(`Navigate to your project directory:\n${concolor.yellow("cd " + info.pdir, false)} and Run the development server: ${concolor.yellow("npm start")}\nEnjoy your new project! 😊`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
96
|
export default create
|