@next2d/vite-plugin-next2d-auto-loader 3.0.5 → 3.0.7

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/dist/index.js +183 -178
  2. package/package.json +4 -1
package/dist/index.js CHANGED
@@ -25,200 +25,200 @@ let $cachePackages = "";
25
25
  */
26
26
  const EOL = "\n";
27
27
  /**
28
- * @return {object}
28
+ * @description 指定されたパスのファイルタイプを返却します。
29
+ * Returns the file type of the specified path.
30
+ *
31
+ * @param {string} path
32
+ * @return {string}
29
33
  * @method
30
- * @public
31
34
  */
32
- export default function autoLoader() {
33
- /**
34
- * @description 指定されたパスのファイルタイプを返却します。
35
- * Returns the file type of the specified path.
36
- *
37
- * @param {string} path
38
- * @return {string}
39
- * @method
40
- */
41
- const getFileType = (path) => {
42
- try {
43
- const stat = fs.statSync(path);
44
- switch (true) {
45
- case stat.isFile():
46
- return "file";
47
- case stat.isDirectory():
48
- return "directory";
49
- default:
50
- return "unknown";
51
- }
52
- }
53
- catch (error) {
54
- console.error(error);
55
- return "unknown";
35
+ const getFileType = (path) => {
36
+ try {
37
+ const stat = fs.statSync(path);
38
+ switch (true) {
39
+ case stat.isFile():
40
+ return "file";
41
+ case stat.isDirectory():
42
+ return "directory";
43
+ default:
44
+ return "unknown";
56
45
  }
57
- };
58
- /**
59
- * @description 指定されたディレクトリパス内のファイルパスリストを返却します。
60
- * Returns a list of file paths in the specified directory path.
61
- *
62
- * @param {string} dir_path
63
- * @return {string[]}
64
- * @method
65
- */
66
- const getFilePathList = (dir_path) => {
67
- const files = [];
68
- const paths = fs.readdirSync(dir_path);
69
- for (let idx = 0; idx < paths.length; ++idx) {
70
- const path = `${dir_path}/${paths[idx]}`;
71
- switch (getFileType(path)) {
72
- case "file":
73
- files.push(path);
74
- break;
75
- case "directory":
76
- files.push(...getFilePathList(path));
77
- break;
78
- default:
79
- break;
80
- }
46
+ }
47
+ catch (error) {
48
+ console.error(error);
49
+ return "unknown";
50
+ }
51
+ };
52
+ /**
53
+ * @description 指定されたディレクトリパス内のファイルパスリストを返却します。
54
+ * Returns a list of file paths in the specified directory path.
55
+ *
56
+ * @param {string} dir_path
57
+ * @return {string[]}
58
+ * @method
59
+ */
60
+ const getFilePathList = (dir_path) => {
61
+ const files = [];
62
+ const paths = fs.readdirSync(dir_path);
63
+ for (let idx = 0; idx < paths.length; ++idx) {
64
+ const path = `${dir_path}/${paths[idx]}`;
65
+ switch (getFileType(path)) {
66
+ case "file":
67
+ files.push(path);
68
+ break;
69
+ case "directory":
70
+ files.push(...getFilePathList(path));
71
+ break;
72
+ default:
73
+ break;
81
74
  }
82
- return files;
75
+ }
76
+ return files;
77
+ };
78
+ /**
79
+ * @description config ディレクトリのjsonファイルを読み込み、Config.[ts|js]を生成します。
80
+ * Reads JSON files from the config directory and generates Config.[ts|js].
81
+ *
82
+ * @return {void}
83
+ * @method
84
+ */
85
+ const buildConfig = () => {
86
+ const configDir = `${process.cwd()}/src/config`;
87
+ const environment = process.env.NEXT2D_EBUILD_ENVIRONMENT || "local";
88
+ const platform = process.env.NEXT2D_TARGET_PLATFORM || "web";
89
+ const config = {
90
+ "platform": platform,
91
+ "stage": {},
92
+ "routing": {}
83
93
  };
84
- /**
85
- * @description config ディレクトリのjsonファイルを読み込み、Config.[ts|js]を生成します。
86
- * Reads JSON files from the config directory and generates Config.[ts|js].
87
- *
88
- * @return {void}
89
- * @method
90
- */
91
- const buildConfig = () => {
92
- const configDir = `${process.cwd()}/src/config`;
93
- const environment = process.env.NEXT2D_EBUILD_ENVIRONMENT || "local";
94
- const platform = process.env.NEXT2D_TARGET_PLATFORM || "web";
95
- const config = {
96
- "platform": platform,
97
- "stage": {},
98
- "routing": {}
99
- };
100
- // load config.json
101
- const configPath = `${configDir}/config.json`;
102
- if (fs.existsSync(configPath)) {
103
- const configObject = JSON.parse(fs.readFileSync(configPath, { "encoding": "utf8" }));
104
- if (environment in configObject) {
105
- Object.assign(config, configObject[environment]);
106
- }
107
- if (configObject.all) {
108
- Object.assign(config, configObject.all);
109
- }
94
+ // load config.json
95
+ const configPath = `${configDir}/config.json`;
96
+ if (fs.existsSync(configPath)) {
97
+ const configObject = JSON.parse(fs.readFileSync(configPath, { "encoding": "utf8" }));
98
+ if (environment in configObject) {
99
+ Object.assign(config, configObject[environment]);
110
100
  }
111
- // load stage.json
112
- const stagePath = `${configDir}/stage.json`;
113
- if (fs.existsSync(stagePath)) {
114
- Object.assign(config.stage, JSON.parse(fs.readFileSync(stagePath, { "encoding": "utf8" })));
101
+ if (configObject.all) {
102
+ Object.assign(config, configObject.all);
115
103
  }
116
- // load routing.json
117
- const routingPath = `${configDir}/routing.json`;
118
- if (fs.existsSync(routingPath)) {
119
- Object.assign(config.routing, JSON.parse(fs.readFileSync(routingPath, { "encoding": "utf8" })));
120
- }
121
- const regexp = new RegExp(/{{(.*?)}}/, "g");
122
- let configString = JSON.stringify(config, null, 4);
123
- const values = configString.match(regexp);
124
- if (values) {
125
- for (let idx = 0; idx < values.length; ++idx) {
126
- const value = values[idx];
127
- const names = value
128
- .replace(/\{|\{|\}|\}/g, "")
129
- .replace(/\s+/g, "")
130
- .split(".");
131
- if (!names.length) {
132
- continue;
133
- }
134
- let configValue = config;
135
- for (let idx = 0; idx < names.length; ++idx) {
136
- const name = names[idx];
137
- if (name in configValue) {
138
- configValue = configValue[name];
139
- }
140
- }
141
- if (config === configValue) {
142
- continue;
104
+ }
105
+ // load stage.json
106
+ const stagePath = `${configDir}/stage.json`;
107
+ if (fs.existsSync(stagePath)) {
108
+ Object.assign(config.stage, JSON.parse(fs.readFileSync(stagePath, { "encoding": "utf8" })));
109
+ }
110
+ // load routing.json
111
+ const routingPath = `${configDir}/routing.json`;
112
+ if (fs.existsSync(routingPath)) {
113
+ Object.assign(config.routing, JSON.parse(fs.readFileSync(routingPath, { "encoding": "utf8" })));
114
+ }
115
+ const regexp = new RegExp(/{{(.*?)}}/, "g");
116
+ let configString = JSON.stringify(config, null, 4);
117
+ const values = configString.match(regexp);
118
+ if (values) {
119
+ for (let idx = 0; idx < values.length; ++idx) {
120
+ const value = values[idx];
121
+ const names = value
122
+ .replace(/\{|\{|\}|\}/g, "")
123
+ .replace(/\s+/g, "")
124
+ .split(".");
125
+ if (!names.length) {
126
+ continue;
127
+ }
128
+ let configValue = config;
129
+ for (let idx = 0; idx < names.length; ++idx) {
130
+ const name = names[idx];
131
+ if (name in configValue) {
132
+ configValue = configValue[name];
143
133
  }
144
- configString = configString.replace(value, configValue);
145
134
  }
135
+ if (config === configValue) {
136
+ continue;
137
+ }
138
+ configString = configString.replace(value, configValue);
146
139
  }
147
- if ($cacheConfig !== configString) {
148
- // cache update
149
- $cacheConfig = configString;
150
- const source = `const config = ${configString};
140
+ }
141
+ if ($cacheConfig !== configString) {
142
+ // cache update
143
+ $cacheConfig = configString;
144
+ const source = `const config = ${configString};
151
145
  export { config };`;
152
- fs.writeFileSync(`${configDir}/Config.${ext}`, source);
146
+ fs.writeFileSync(`${configDir}/Config.${ext}`, source);
147
+ }
148
+ };
149
+ /**
150
+ * @description view、 model ディレクトリ配下のファイルを読み込み、Package.[ts|js]を生成します。
151
+ * Reads files under the view and model directories and generates Package.[ts|js].
152
+ *
153
+ * @return {void}
154
+ * @method
155
+ */
156
+ const buildPackage = () => {
157
+ const dir = process.cwd();
158
+ const filePaths = getFilePathList(`${dir}/src`);
159
+ let imports = "";
160
+ let packages = `[${EOL}`;
161
+ for (let idx = 0; idx < filePaths.length; ++idx) {
162
+ const filePath = filePaths[idx];
163
+ // ts, js 以外はスキップ
164
+ if (filePath.indexOf(`.${ext}`) === -1) {
165
+ continue;
153
166
  }
154
- };
155
- /**
156
- * @description view、 model ディレクトリ配下のファイルを読み込み、Package.[ts|js]を生成します。
157
- * Reads files under the view and model directories and generates Package.[ts|js].
158
- *
159
- * @return {void}
160
- * @method
161
- */
162
- const buildPackage = () => {
163
- const dir = process.cwd();
164
- const filePaths = getFilePathList(`${dir}/src`);
165
- let imports = "";
166
- let packages = `[${EOL}`;
167
- for (let idx = 0; idx < filePaths.length; ++idx) {
168
- const filePath = filePaths[idx];
169
- // ts, js 以外はスキップ
170
- if (filePath.indexOf(`.${ext}`) === -1) {
167
+ const js = fs.readFileSync(filePath, { "encoding": "utf-8" });
168
+ const lines = js.split("\n");
169
+ const path = filePath.replace(`${dir}/`, "");
170
+ for (let idx = 0; idx < lines.length; ++idx) {
171
+ const line = lines[idx];
172
+ // クラス定義以外はスキップ
173
+ if (line.indexOf("export class ") === -1) {
171
174
  continue;
172
175
  }
173
- const js = fs.readFileSync(filePath, { "encoding": "utf-8" });
174
- const lines = js.split("\n");
175
- const path = filePath.replace(`${dir}/`, "");
176
- for (let idx = 0; idx < lines.length; ++idx) {
177
- const line = lines[idx];
178
- // クラス定義以外はスキップ
179
- if (line.indexOf("export class ") === -1) {
180
- continue;
181
- }
182
- const name = line.split(" ")[2];
183
- switch (true) {
184
- case path.indexOf("src/view/") > -1:
185
- imports += `import { ${name} } from "@/${path.split("src/")[1].split(`.${ext}`)[0]}";${EOL}`;
186
- packages += ` ["${name}", ${name}],${EOL}`;
187
- break;
188
- case path.indexOf("src/model/") > -1:
189
- {
190
- const key = filePath
191
- .split("src/model/")[1]
192
- .split("/")
193
- .join(".")
194
- .slice(0, -3);
195
- const asName = filePath
196
- .split("src/model/")[1]
197
- .split("/")
198
- .join("_")
199
- .slice(0, -3);
200
- imports += `import { ${name} as ${asName} } from "@/${path.split("src/")[1].split(`.${ext}`)[0]}";${EOL}`;
201
- packages += ` ["${key}", ${asName}],${EOL}`;
202
- }
203
- break;
204
- default:
205
- break;
206
- }
207
- break;
176
+ const name = line.split(" ")[2];
177
+ switch (true) {
178
+ case path.indexOf("src/view/") > -1:
179
+ imports += `import { ${name} } from "@/${path.split("src/")[1].split(`.${ext}`)[0]}";${EOL}`;
180
+ packages += ` ["${name}", ${name}],${EOL}`;
181
+ break;
182
+ case path.indexOf("src/model/") > -1:
183
+ {
184
+ const key = filePath
185
+ .split("src/model/")[1]
186
+ .split("/")
187
+ .join(".")
188
+ .slice(0, -3);
189
+ const asName = filePath
190
+ .split("src/model/")[1]
191
+ .split("/")
192
+ .join("_")
193
+ .slice(0, -3);
194
+ imports += `import { ${name} as ${asName} } from "@/${path.split("src/")[1].split(`.${ext}`)[0]}";${EOL}`;
195
+ packages += ` ["${key}", ${asName}],${EOL}`;
196
+ }
197
+ break;
198
+ default:
199
+ break;
208
200
  }
201
+ break;
209
202
  }
210
- packages = packages.slice(0, -2);
211
- packages += `${EOL}]`;
212
- let source = `${imports}${EOL}`;
213
- source += ext === "ts"
214
- ? `const packages: Array<Array<string | Function>> = ${packages};${EOL}`
215
- : `const packages = ${packages};${EOL}`;
216
- source += "export { packages };";
217
- if ($cachePackages !== source) {
218
- $cachePackages = source;
219
- fs.writeFileSync(`${dir}/src/Packages.${ext}`, source);
220
- }
221
- };
203
+ }
204
+ packages = packages.slice(0, -2);
205
+ packages += `${EOL}]`;
206
+ let source = `${imports}${EOL}`;
207
+ source += ext === "ts"
208
+ ? `const packages: Array<Array<string | Function>> = ${packages};${EOL}`
209
+ : `const packages = ${packages};${EOL}`;
210
+ source += "export { packages };";
211
+ if ($cachePackages !== source) {
212
+ $cachePackages = source;
213
+ fs.writeFileSync(`${dir}/src/Packages.${ext}`, source);
214
+ }
215
+ };
216
+ /**
217
+ * @return {object}
218
+ * @method
219
+ * @public
220
+ */
221
+ export default function autoLoader() {
222
222
  return {
223
223
  "name": "vite-plugin-next2d-auto-loader",
224
224
  "buildStart": {
@@ -241,3 +241,8 @@ export { config };`;
241
241
  }
242
242
  };
243
243
  }
244
+ const execute = () => {
245
+ buildConfig();
246
+ buildPackage();
247
+ };
248
+ execute();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@next2d/vite-plugin-next2d-auto-loader",
3
3
  "description": "Next2D Framework vite TypeScript Auto Loader plugin.",
4
- "version": "3.0.5",
4
+ "version": "3.0.7",
5
5
  "homepage": "https://next2d.app",
6
6
  "bugs": "https://github.com/Next2D/vite-plugin-next2d-auto-loader/issues",
7
7
  "author": "Toshiyuki Ienaga<ienaga@next2d.app>",
@@ -23,6 +23,9 @@
23
23
  "lint": "eslint src/**/*.ts",
24
24
  "release": "tsc"
25
25
  },
26
+ "bin": {
27
+ "@next2d/vite-plugin-next2d-auto-loader": "dist/index.js"
28
+ },
26
29
  "repository": {
27
30
  "type": "git",
28
31
  "url": "git+https://github.com/Next2D/vite-plugin-next2d-auto-loader.git"