nl-d365boilerplate-vite 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/bin/cli.js +86 -67
  2. package/package.json +2 -1
package/bin/cli.js CHANGED
@@ -1,84 +1,103 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import fs from "fs";
4
4
  import path from "path";
5
5
  import { fileURLToPath } from "url";
6
+ import { intro, outro, text, isCancel, cancel } from "@clack/prompts";
6
7
 
7
8
  const __filename = fileURLToPath(import.meta.url);
8
9
  const __dirname = path.dirname(__filename);
9
10
 
10
- const targetDirName = process.argv[2];
11
+ async function main() {
12
+ intro(`šŸš€ Create NL D365 Boilerplate`);
11
13
 
12
- if (!targetDirName) {
13
- console.error("Please specify the project directory:");
14
- console.error(" npm create nl-d365boilerplate-vite <project-directory>");
15
- process.exit(1);
16
- }
17
-
18
- const targetPath = path.join(process.cwd(), targetDirName);
19
- const templatePath = path.join(__dirname, "..");
14
+ let targetDirName = process.argv[2];
20
15
 
21
- if (fs.existsSync(targetPath)) {
22
- console.error(`Directory ${targetDirName} already exists.`);
23
- process.exit(1);
24
- }
16
+ if (!targetDirName) {
17
+ const projectName = await text({
18
+ message: "What is the name of your project?",
19
+ placeholder: "my-d365-app",
20
+ validate(value) {
21
+ if (value.length === 0) return "Value is required!";
22
+ },
23
+ });
25
24
 
26
- console.log(`Creating a new app in ${targetPath}...`);
27
- fs.mkdirSync(targetPath, { recursive: true });
28
-
29
- const SKIP_FILES = [
30
- "node_modules",
31
- ".git",
32
- ".env",
33
- "package-lock.json",
34
- "bin",
35
- "dist",
36
- ".npmignore",
37
- ".DS_Store",
38
- ];
39
-
40
- function copyDir(src, dest) {
41
- const entries = fs.readdirSync(src, { withFileTypes: true });
42
-
43
- for (const entry of entries) {
44
- const srcPath = path.join(src, entry.name);
45
- const destPath = path.join(dest, entry.name);
46
-
47
- if (SKIP_FILES.includes(entry.name)) {
48
- continue;
25
+ if (isCancel(projectName)) {
26
+ cancel("Operation cancelled.");
27
+ process.exit(0);
49
28
  }
50
29
 
51
- if (entry.isDirectory()) {
52
- fs.mkdirSync(destPath, { recursive: true });
53
- copyDir(srcPath, destPath);
54
- } else {
55
- fs.copyFileSync(srcPath, destPath);
30
+ targetDirName = projectName;
31
+ }
32
+
33
+ const targetPath = path.join(process.cwd(), targetDirName);
34
+ const templatePath = path.join(__dirname, "..");
35
+
36
+ if (fs.existsSync(targetPath)) {
37
+ console.error(`\nāŒ Directory "${targetDirName}" already exists.`);
38
+ process.exit(1);
39
+ }
40
+
41
+ console.log(`\nCreating a new app in ${targetPath}...`);
42
+ fs.mkdirSync(targetPath, { recursive: true });
43
+
44
+ const SKIP_FILES = [
45
+ "node_modules",
46
+ ".git",
47
+ ".env",
48
+ "package-lock.json",
49
+ "bin",
50
+ "dist",
51
+ ".npmignore",
52
+ ".DS_Store",
53
+ ];
54
+
55
+ function copyDir(src, dest) {
56
+ const entries = fs.readdirSync(src, { withFileTypes: true });
57
+
58
+ for (const entry of entries) {
59
+ const srcPath = path.join(src, entry.name);
60
+ const destPath = path.join(dest, entry.name);
61
+
62
+ if (SKIP_FILES.includes(entry.name)) {
63
+ continue;
64
+ }
65
+
66
+ // Prevent copying the new project directory into itself
67
+ if (path.resolve(srcPath) === path.resolve(targetPath)) {
68
+ continue;
69
+ }
70
+
71
+ if (entry.isDirectory()) {
72
+ fs.mkdirSync(destPath, { recursive: true });
73
+ copyDir(srcPath, destPath);
74
+ } else {
75
+ fs.copyFileSync(srcPath, destPath);
76
+ }
56
77
  }
57
78
  }
79
+
80
+ // Copy files
81
+ copyDir(templatePath, targetPath);
82
+
83
+ // Update package.json
84
+ const pkgJsonPath = path.join(targetPath, "package.json");
85
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
86
+
87
+ pkg.name = targetDirName;
88
+ pkg.version = "0.0.0";
89
+ pkg.private = true;
90
+ delete pkg.bin;
91
+ delete pkg.files;
92
+
93
+ fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2));
94
+
95
+ outro(`You're all set!`);
96
+
97
+ console.log(`Next steps:`);
98
+ console.log(` cd ${targetDirName}`);
99
+ console.log(` npm install`);
100
+ console.log(` npm run dev`);
58
101
  }
59
102
 
60
- // Copy files
61
- copyDir(templatePath, targetPath);
62
-
63
- // Update package.json
64
- const pkgJsonPath = path.join(targetPath, "package.json");
65
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
66
-
67
- pkg.name = targetDirName;
68
- pkg.version = "0.0.0";
69
- pkg.private = true;
70
- delete pkg.bin;
71
- delete pkg.files;
72
-
73
- fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2));
74
-
75
- console.log("\nSuccess! Created project at " + targetPath);
76
- console.log("Inside that directory, you can run several commands:\n");
77
- console.log(" npm install");
78
- console.log(" Installs dependencies.\n");
79
- console.log(" npm run dev");
80
- console.log(" Starts the development server.\n");
81
- console.log("\nWe suggest that you begin by typing:\n");
82
- console.log(` cd ${targetDirName}`);
83
- console.log(" npm install");
84
- console.log(" npm run dev");
103
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nl-d365boilerplate-vite",
3
3
  "private": false,
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "nl-d365boilerplate-vite": "./bin/cli.js"
@@ -31,6 +31,7 @@
31
31
  "lint:fix": "eslint . --fix"
32
32
  },
33
33
  "dependencies": {
34
+ "@clack/prompts": "^0.11.0",
34
35
  "@radix-ui/react-dialog": "^1.1.15",
35
36
  "@radix-ui/react-label": "^2.1.8",
36
37
  "@radix-ui/react-separator": "^1.1.8",