@snowtop/ent 0.0.27 → 0.0.28-alpha

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.
@@ -10,7 +10,7 @@ interface classResult {
10
10
  class: classInfo;
11
11
  file: file;
12
12
  }
13
- export declare function parseCustomInput(filePath: string, opts?: Options): PathResult;
13
+ export declare function parseCustomImports(filePath: string, opts?: Options): PathResult;
14
14
  export declare function findTSConfigFile(filePath: string): string | null;
15
15
  export interface importInfo {
16
16
  name: string;
package/imports/index.js CHANGED
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.findTSConfigFile = exports.parseCustomInput = void 0;
25
+ exports.findTSConfigFile = exports.parseCustomImports = void 0;
26
26
  const glob_1 = __importDefault(require("glob"));
27
27
  const typescript_1 = __importDefault(require("typescript"));
28
28
  const json5_1 = __importDefault(require("json5"));
@@ -42,10 +42,9 @@ function getFiles(filePath, opts) {
42
42
  }
43
43
  return files;
44
44
  }
45
- function parseCustomInput(filePath, opts) {
45
+ function parseCustomImports(filePath, opts) {
46
46
  const files = getFiles(filePath, opts);
47
47
  const options = readCompilerOptions(filePath);
48
- // classMap
49
48
  let classMap = new Map();
50
49
  files.forEach((file) => {
51
50
  const sourceFile = typescript_1.default.createSourceFile(file, fs.readFileSync(file).toString(), options.target || typescript_1.default.ScriptTarget.ES2015);
@@ -77,7 +76,7 @@ function parseCustomInput(filePath, opts) {
77
76
  },
78
77
  };
79
78
  }
80
- exports.parseCustomInput = parseCustomInput;
79
+ exports.parseCustomImports = parseCustomImports;
81
80
  function findTSConfigFile(filePath) {
82
81
  while (filePath != "/") {
83
82
  let configPath = `${filePath}/tsconfig.json`;
@@ -95,7 +94,6 @@ function readCompilerOptions(filePath) {
95
94
  if (!configPath) {
96
95
  return {};
97
96
  }
98
- const root = path.join(filePath, "..");
99
97
  let json = {};
100
98
  try {
101
99
  json = json5_1.default.parse(fs.readFileSync(configPath, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.0.27",
3
+ "version": "0.0.28-alpha",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -52,7 +52,17 @@ async function readInputs() {
52
52
  });
53
53
  });
54
54
  }
55
- async function captureCustom(filePath) {
55
+ async function captureCustom(filePath, filesCsv) {
56
+ if (filesCsv !== undefined) {
57
+ let files = filesCsv.split(",");
58
+ for (let i = 0; i < files.length; i++) {
59
+ // TODO fix. we have "src" in the path we get here
60
+ files[i] = path.join(filePath, "..", files[i]);
61
+ }
62
+ await requireFiles(files);
63
+ return;
64
+ }
65
+ // TODO delete all of this eventually
56
66
  // TODO configurable paths eventually
57
67
  // for now only files that are in the include path of the roots are allowed
58
68
  const rootFiles = [
@@ -81,18 +91,28 @@ async function captureCustom(filePath) {
81
91
  ignore: ignore,
82
92
  });
83
93
  const files = rootFiles.concat(customGQLResolvers, customGQLMutations);
84
- //console.log(files);
85
- let promises = [];
86
- files.forEach((file) => {
94
+ await requireFiles(files);
95
+ }
96
+ async function requireFiles(files) {
97
+ await Promise.all(files.map(async (file) => {
87
98
  if (fs.existsSync(file)) {
88
- promises.push(require(file));
99
+ try {
100
+ await require(file);
101
+ }
102
+ catch (e) {
103
+ throw new Error(`${e.message} loading ${file}`);
104
+ }
105
+ }
106
+ else {
107
+ throw new Error(`file ${file} doesn't exist`);
89
108
  }
109
+ })).catch((err) => {
110
+ throw new Error(err);
90
111
  });
91
- await Promise.all(promises);
92
112
  }
93
113
  async function parseImports(filePath) {
94
114
  // only do graphql files...
95
- return (0, imports_1.parseCustomInput)(path.join(filePath, "graphql"), {
115
+ return (0, imports_1.parseCustomImports)(path.join(filePath, "graphql"), {
96
116
  ignore: ["**/generated/**", "**/tests/**"],
97
117
  });
98
118
  }
@@ -126,7 +146,7 @@ async function main() {
126
146
  GQLCapture.enable(true);
127
147
  const [inputsRead, _, imports] = await Promise.all([
128
148
  readInputs(),
129
- captureCustom(options.path),
149
+ captureCustom(options.path, options.files),
130
150
  parseImports(options.path),
131
151
  ]);
132
152
  const { nodes, nodesMap } = inputsRead;