this.gui 1.0.14 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "this.gui",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "This Graphic User Interface.",
5
5
  "main": "dist/this-gui.umd.js",
6
6
  "module": "dist/this-gui.es.js",
@@ -1,19 +1,17 @@
1
1
  // this.GUI/scripts/postinstall.js
2
2
  import { mkdir, writeFile, access } from 'fs/promises';
3
3
  import { join } from 'path';
4
- import { fileURLToPath } from 'url';
5
4
 
6
- // Get the current directory path
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = join(__filename, '..', '..');
5
+ // Use process.env.INIT_CWD to get the root of the user's project during npm install
6
+ const appRootDir = process.env.INIT_CWD || process.cwd();
9
7
 
10
- // Define paths for directories
11
- const guiDir = join(__dirname, '..', 'GUI');
8
+ // Define paths for directories at the app level
9
+ const guiDir = join(appRootDir, 'GUI');
12
10
  const componentsDir = join(guiDir, 'components');
13
11
  const mdxDir = join(guiDir, 'mdx');
14
12
  const stylesDir = join(guiDir, 'styles');
15
13
 
16
- // Helper function to create directories
14
+ // Helper function to create directories only if they don't already exist
17
15
  async function createDir(dirPath) {
18
16
  try {
19
17
  await access(dirPath);
@@ -24,35 +22,34 @@ async function createDir(dirPath) {
24
22
  }
25
23
  }
26
24
 
27
- // Helper function to create initial files if they don't exist
25
+ // Helper function to create initial files only if they don't already exist
26
+ async function createFile(filePath, content) {
27
+ try {
28
+ await access(filePath);
29
+ console.log(`File already exists: ${filePath}`);
30
+ } catch {
31
+ await writeFile(filePath, content);
32
+ console.log(`Created: ${filePath}`);
33
+ }
34
+ }
35
+
36
+ // Function to initialize the directory structure and files
28
37
  async function initializeFiles() {
29
38
  const mdxWelcomeFile = join(mdxDir, 'Welcome.mdx');
30
39
  const stylesFile = join(stylesDir, 'global.css');
31
40
 
32
- try {
33
- await access(mdxWelcomeFile);
34
- console.log(`File already exists: ${mdxWelcomeFile}`);
35
- } catch {
36
- await writeFile(
37
- mdxWelcomeFile,
38
- `# Welcome to Your Custom GUI\n\nThis is your first MDX file. Edit it to start building your pages!`
39
- );
40
- console.log(`Created: ${mdxWelcomeFile}`);
41
- }
41
+ await createFile(
42
+ mdxWelcomeFile,
43
+ `# Welcome to Your Custom GUI\n\nThis is your first MDX file. Edit it to start building your pages!`
44
+ );
42
45
 
43
- try {
44
- await access(stylesFile);
45
- console.log(`File already exists: ${stylesFile}`);
46
- } catch {
47
- await writeFile(
48
- stylesFile,
49
- `/* Add your custom styles here */\nbody { font-family: 'Roboto', sans-serif; }`
50
- );
51
- console.log(`Created: ${stylesFile}`);
52
- }
46
+ await createFile(
47
+ stylesFile,
48
+ `/* Add your custom styles here */\nbody { font-family: 'Roboto', sans-serif; }`
49
+ );
53
50
  }
54
51
 
55
- // Create the directory structure and initialize files
52
+ // Create the directory structure and initialize files at the app level
56
53
  (async () => {
57
54
  await createDir(guiDir);
58
55
  await createDir(componentsDir);
@@ -60,5 +57,5 @@ async function initializeFiles() {
60
57
  await createDir(stylesDir);
61
58
  await initializeFiles();
62
59
 
63
- console.log('this.GUI setup complete!');
64
- })();
60
+ console.log('this.GUI setup complete at the app level!');
61
+ })();