mobiletto-orm-typedef-gen 2.1.31 → 2.1.33

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.
@@ -139,14 +139,26 @@ export const generate = (typeDef, templatePath, opts) => {
139
139
  if (lastSlash === -1 || lastSlash === templatePath.length - 1) {
140
140
  throw new MobilettoOrmError(`invalid template path: ${templatePath}`);
141
141
  }
142
- const endPath = templatePath.substring(0, lastSlash).replace(/^[A-Z0-9/_-]/g, "") + templatePath.substring(lastSlash);
142
+ const endPath = templatePath.substring(0, lastSlash).replace(/[^A-Z0-9_./-]/gi, "") + templatePath.substring(lastSlash);
143
143
  if (endPath !== templatePath) {
144
144
  throw new MobilettoOrmError(`invalid template path: ${templatePath}`);
145
145
  }
146
146
  if (!templatePath.endsWith(".ts.hbs")) {
147
147
  throw new MobilettoOrmError(`invalid template path: ${templatePath}`);
148
148
  }
149
- const template = fs.readFileSync(__dirname + "/" + templatePath).toString("utf8");
149
+ const localTemplate = __dirname + "/" + templatePath;
150
+ let template;
151
+ try {
152
+ template = fs.readFileSync(localTemplate).toString("utf8");
153
+ }
154
+ catch (e) {
155
+ try {
156
+ template = fs.readFileSync(templatePath).toString("utf8");
157
+ }
158
+ catch (e2) {
159
+ throw new MobilettoOrmError(`template path not found: ${templatePath}`);
160
+ }
161
+ }
150
162
  const data = Handlebars.compile(template)(preparedContext);
151
163
  allData = data + allData;
152
164
  }
@@ -1,8 +1,8 @@
1
1
  {
2
- "name": "mobiletto-orm-typedef",
2
+ "name": "mobiletto-orm-typedef-gen",
3
3
  "type": "commonjs",
4
4
  "main": "./index.js",
5
- "homepage": "https://github.com/cobbzilla/mobiletto-orm-typedef",
5
+ "homepage": "https://github.com/cobbzilla/mobiletto-orm-typedef-gen",
6
6
  "author": "Jonathan Cobb <udo9jqld@duck.com> (https://github.com/cobbzilla)",
7
7
  "funding": {
8
8
  "type": "patreon",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/cobbzilla/mobiletto-orm-typedef.git"
13
+ "url": "https://github.com/cobbzilla/mobiletto-orm-typedef-gen.git"
14
14
  },
15
15
  "license": "Apache-2.0"
16
16
  }
@@ -139,14 +139,26 @@ export const generate = (typeDef, templatePath, opts) => {
139
139
  if (lastSlash === -1 || lastSlash === templatePath.length - 1) {
140
140
  throw new MobilettoOrmError(`invalid template path: ${templatePath}`);
141
141
  }
142
- const endPath = templatePath.substring(0, lastSlash).replace(/^[A-Z0-9/_-]/g, "") + templatePath.substring(lastSlash);
142
+ const endPath = templatePath.substring(0, lastSlash).replace(/[^A-Z0-9_./-]/gi, "") + templatePath.substring(lastSlash);
143
143
  if (endPath !== templatePath) {
144
144
  throw new MobilettoOrmError(`invalid template path: ${templatePath}`);
145
145
  }
146
146
  if (!templatePath.endsWith(".ts.hbs")) {
147
147
  throw new MobilettoOrmError(`invalid template path: ${templatePath}`);
148
148
  }
149
- const template = fs.readFileSync(__dirname + "/" + templatePath).toString("utf8");
149
+ const localTemplate = __dirname + "/" + templatePath;
150
+ let template;
151
+ try {
152
+ template = fs.readFileSync(localTemplate).toString("utf8");
153
+ }
154
+ catch (e) {
155
+ try {
156
+ template = fs.readFileSync(templatePath).toString("utf8");
157
+ }
158
+ catch (e2) {
159
+ throw new MobilettoOrmError(`template path not found: ${templatePath}`);
160
+ }
161
+ }
150
162
  const data = Handlebars.compile(template)(preparedContext);
151
163
  allData = data + allData;
152
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiletto-orm-typedef-gen",
3
- "version": "2.1.31",
3
+ "version": "2.1.33",
4
4
  "type": "module",
5
5
  "exports": "./lib/esm/index.js",
6
6
  "description": "generate various files based on mobiletto-orm-typedef definitions",