react-fs-router 1.0.13 → 2.0.0

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 (66) hide show
  1. package/README.md +724 -175
  2. package/dist/adapters/custom.d.ts +9 -0
  3. package/dist/adapters/custom.d.ts.map +1 -0
  4. package/dist/adapters/custom.js +11 -0
  5. package/dist/adapters/custom.js.map +1 -0
  6. package/dist/adapters/index.d.ts +8 -0
  7. package/dist/adapters/index.d.ts.map +1 -0
  8. package/dist/adapters/index.js +14 -0
  9. package/dist/adapters/index.js.map +1 -0
  10. package/dist/adapters/react-router.d.ts +18 -0
  11. package/dist/adapters/react-router.d.ts.map +1 -0
  12. package/dist/adapters/react-router.js +58 -0
  13. package/dist/adapters/react-router.js.map +1 -0
  14. package/dist/adapters/tanstack.d.ts +16 -0
  15. package/dist/adapters/tanstack.d.ts.map +1 -0
  16. package/dist/adapters/tanstack.js +75 -0
  17. package/dist/adapters/tanstack.js.map +1 -0
  18. package/dist/cli.d.ts +3 -0
  19. package/dist/cli.d.ts.map +1 -0
  20. package/dist/cli.js +59 -0
  21. package/dist/cli.js.map +1 -0
  22. package/dist/config.d.ts +24 -0
  23. package/dist/config.d.ts.map +1 -0
  24. package/dist/config.js +81 -0
  25. package/dist/config.js.map +1 -0
  26. package/dist/generator.d.ts +48 -0
  27. package/dist/generator.d.ts.map +1 -0
  28. package/dist/generator.js +272 -0
  29. package/dist/generator.js.map +1 -0
  30. package/dist/index.d.ts +9 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +8 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/render.d.ts +53 -0
  35. package/dist/render.d.ts.map +1 -0
  36. package/dist/render.js +100 -0
  37. package/dist/render.js.map +1 -0
  38. package/dist/scanner.d.ts +27 -0
  39. package/dist/scanner.d.ts.map +1 -0
  40. package/dist/scanner.js +38 -0
  41. package/dist/scanner.js.map +1 -0
  42. package/dist/tree.d.ts +11 -0
  43. package/dist/tree.d.ts.map +1 -0
  44. package/dist/tree.js +83 -0
  45. package/dist/tree.js.map +1 -0
  46. package/dist/types.d.ts +98 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +2 -0
  49. package/dist/types.js.map +1 -0
  50. package/dist/vite.d.ts +14 -0
  51. package/dist/vite.d.ts.map +1 -0
  52. package/dist/vite.js +33 -0
  53. package/dist/vite.js.map +1 -0
  54. package/dist/webpack.d.ts +32 -0
  55. package/dist/webpack.d.ts.map +1 -0
  56. package/dist/webpack.js +26 -0
  57. package/dist/webpack.js.map +1 -0
  58. package/package.json +103 -35
  59. package/.idea/git_toolbox_prj.xml +0 -15
  60. package/.idea/modules.xml +0 -8
  61. package/.idea/react-filesystem-router.iml +0 -12
  62. package/.idea/vcs.xml +0 -6
  63. package/genPath.js +0 -212
  64. package/index.js +0 -19
  65. package/lib/components/Routes.js +0 -0
  66. package/tsconfig.json +0 -7
package/genPath.js DELETED
@@ -1,212 +0,0 @@
1
- const fs = require("fs");
2
- const prettier = require("prettier");
3
- const chokidar = require("chokidar");
4
-
5
- let isNotThefirstTimeRunning = true;
6
-
7
- const genPath = (page_directory, configs_directory, runOnce) => {
8
- //main function
9
- const pathMaker = () => {
10
- //parse parameters in path
11
- const parsePageName = (fileName) => {
12
- const isParam = fileName.includes("[") && fileName.includes("]");
13
-
14
- const splitFileName = fileName.split("/");
15
- if (splitFileName.length && isParam) {
16
- const paramName = splitFileName[splitFileName.length - 1];
17
- const paramNameWithoutExtention = paramName.split(".")[0];
18
- const paramNameWithoutBraces = paramNameWithoutExtention
19
- .replace("[", "")
20
- .replace("]", "");
21
- splitFileName[splitFileName.length - 1] = `:${paramNameWithoutBraces}`;
22
- return splitFileName.join("/");
23
- } else if (fileName === "index" && !isParam) return "";
24
- else return fileName;
25
- };
26
-
27
- const parseFilePath = (filePath) => {
28
- if (filePath.includes(":")) {
29
- const splitPath = filePath.split("/");
30
- const lastItemInPath = splitPath[splitPath.length - 1].replace(":", "");
31
- splitPath[splitPath.length - 1] = `[${lastItemInPath}]`;
32
- return splitPath.join("/");
33
- } else return filePath;
34
- };
35
-
36
- //read page directory
37
- const readDirectory = (directory, includeDirectory) => {
38
- const pages = {};
39
- const read = fs.readdirSync(directory);
40
- const readFiltered = read.filter((file) => !file.startsWith("_"));
41
- readFiltered.forEach((page) => {
42
- const name = page.split(".")[0];
43
- if (page.includes(".")) {
44
- pages[page.replace(".", "_")] = `${
45
- includeDirectory ? directory : ""
46
- }/${name === "index" ? "" : name}`;
47
- } else {
48
- pages[name] = readDirectory(`${directory}/${page}`, true);
49
- }
50
- });
51
- return pages;
52
- };
53
-
54
- const pages = readDirectory(page_directory);
55
-
56
- const readFileProperties = (filepath) => {
57
- const file = String(fs.readFileSync(page_directory + filepath));
58
- const not = ["default", "function", "export"];
59
- const component = file.match(
60
- /((export default .*)|(default function .*))\w/g
61
- );
62
-
63
- const props = file.match(
64
- /((name|icon|index):( |).*[^{}\[\]-_=\/\\\(\)\*&^%$#@!~`|?><,;:"'])/g
65
- );
66
- const result = {
67
- component: null,
68
- name: null,
69
- icon: null,
70
- index: null,
71
- };
72
-
73
- if (!file) return result;
74
- if (component?.length) {
75
- result.component = component[0]
76
- .split(" ")
77
- .filter((match) => !not.includes(match))[0];
78
- }
79
- if (props?.length) {
80
- const name = props.filter((match) => match.includes("name"));
81
- const icon = props.filter((match) => match.includes("icon"));
82
- const index = props.filter((match) => match.includes("index"));
83
- if (name.length) result.name = name[0].split(":")[1].trim();
84
- if (icon.length) result.icon = icon[0].split(":")[1].trim();
85
- if (index.length)
86
- result.index = Number(index[0].split(":")[1].trim()) || 0;
87
- }
88
- return result;
89
- };
90
-
91
- const makeRouteObject = (filepath, filename) => {
92
- const route = {
93
- component: null,
94
- name: null,
95
- icon: null,
96
- index: 0,
97
- path: filepath,
98
- };
99
- const { component, name, icon, index } = readFileProperties(
100
- `${filepath.match(/(\/)/g).length ? filepath : ""}${
101
- filename.includes("index")
102
- ? "/" + filename.replace("_", ".")
103
- : "." + filename.split("_")[1]
104
- }`
105
- );
106
- if (component) route.component = component;
107
- if (name) route.name = name;
108
- if (icon) route.icon = icon;
109
- if (index) route.index = index;
110
- if (filepath) route.path = parsePageName(filepath);
111
- if (filename) route.file = filename.replace("_", ".");
112
-
113
- return route;
114
- };
115
-
116
- const makePathsArray = (paths, prevPath) => {
117
- const result = [];
118
- for (const [file, path] of Object.entries(paths)) {
119
- if (typeof path === "string") {
120
- const oj = { file };
121
- if (prevPath) oj.path = path.replace(page_directory, "");
122
- else oj.path = path;
123
- result.push(oj);
124
- } else result.push(...makePathsArray(path, true));
125
- }
126
- return result;
127
- };
128
-
129
- const routes = makePathsArray(pages)
130
- .map((page) => makeRouteObject(page.path, page.file))
131
- .sort((a, b) => b.index - a.index);
132
-
133
- const _config = `export const routes = ${JSON.stringify(routes)}`;
134
-
135
- const _routes = `${routes
136
- .map((node) =>
137
- node?.component
138
- ? `import ${node.component} from "${
139
- process.env.PWD + page_directory.replace(".", "")
140
- }${node.path === "/" ? "" : parseFilePath(node.path)}";`
141
- : ""
142
- )
143
- .join("")} \n \n export{${routes
144
- .map((node) => (node?.component ? `${node.component},` : ""))
145
- .join("")}};`;
146
-
147
- const parseFileExtention = (ext) => {
148
- if (ext) {
149
- if (ext.includes(".")) return ext;
150
- else return "." + ext;
151
- } else return ".js";
152
- };
153
- fs.writeFileSync(
154
- (configs_directory || page_directory) +
155
- `/_page-properties${parseFileExtention(".js")}`,
156
- prettier.format(_config, { semi: false, parser: "babel" }),
157
- (err) => {
158
- if (err) return console.error(err);
159
- }
160
- );
161
-
162
- fs.writeFileSync(
163
- (configs_directory || page_directory) +
164
- `/_routes${parseFileExtention(".js")}`,
165
- prettier.format(_routes, { semi: false, parser: "babel" }),
166
- (err) => {
167
- if (err) return console.error(err);
168
- }
169
- );
170
- };
171
-
172
- if (isNotThefirstTimeRunning) {
173
- pathMaker();
174
- isNotThefirstTimeRunning = false;
175
- }
176
-
177
- const watcher = chokidar.watch(page_directory, {
178
- ignored: /^\.|\_/,
179
- persistent: !runOnce,
180
- });
181
-
182
- watcher
183
- .on("add", function (path) {
184
- try {
185
- pathMaker();
186
- } catch (e) {
187
- console.log(e);
188
- }
189
- console.log("File", path, "has been added");
190
- })
191
- .on("change", function (path) {
192
- try {
193
- pathMaker();
194
- } catch (e) {
195
- console.log(e);
196
- }
197
- console.log("File", path, "has been changed");
198
- })
199
- .on("unlink", function (path) {
200
- try {
201
- pathMaker();
202
- } catch (e) {
203
- console.log(e);
204
- }
205
- console.log("File", path, "has been removed");
206
- })
207
- .on("error", function (error) {
208
- console.error("Error happened", error);
209
- });
210
- };
211
-
212
- module.exports = { genPath };
package/index.js DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { genPath } = require("./genPath");
4
- const { Command } = require("commander");
5
- const { version, name } = require("./package.json");
6
-
7
- const program = new Command();
8
-
9
- program.storeOptionsAsProperties(name);
10
-
11
- program.version(version, "-v --version", "Output the current version");
12
- program.requiredOption("-i,--input <directory>", "Path to your pages folder");
13
- program.option(
14
- "-b,--build [type]",
15
- "Boolean Option to run the program once. Intended to be used with build commands."
16
- );
17
- program.parse();
18
-
19
- genPath(program.input, program.build);
File without changes
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "declaration": true,
5
- "emitDeclarationOnly": true
6
- }
7
- }