-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.js
105 lines (84 loc) · 2.67 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict'
var loadPackages = require('./isopacks.js');
var findTypesEntry = require('./types-entry.js');
var Writer = require('./writer.js');
const ProjectContext = require('./tools-imports.js').ProjectContext;
const tropohouse = require('./tools-imports.js').tropohouse;
const path = require('path');
const fs = require('fs');
var appPath = process.cwd();
var writer = new Writer(appPath);
var catalog;
var setupFinished = false;
const oldGetProjectLocalDirectory = ProjectContext.prototype.getProjectLocalDirectory;
// Meteor calls getProjectLocalDirectory at the beginning of every build
ProjectContext.prototype.getProjectLocalDirectory = function () {
catalog = this.projectCatalog;
return oldGetProjectLocalDirectory.apply(this, arguments);
};
let remoteCatalogRoot = (
process.platform == "win32"
) ?
Plugin.convertToOSPath( tropohouse.root )
: tropohouse.root;
const isLinting = process.argv.includes('lint');
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
let filenames = [ 'tsconfig.json' ];
// Meteor has a bug that requires linters to lint any main modules
try {
let content = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf-8')
);
if (content.meteor && content.meteor.mainModule) {
Object.keys(content.meteor.mainModule).forEach(key => {
let modulePath = content.meteor.mainModule[key];
let fileName = path.basename(modulePath);
if (filenames.indexOf(fileName) === -1) {
filenames.push(fileName);
}
});
}
} catch (e) {
}
Plugin.registerLinter({
filenames: filenames
}, () => new Linter());
class Linter {
processFilesForPackage(files) {
var isApp = files[0].getPackageName() === null;
if (!isApp) {
return;
}
if (!catalog) {
// When using the published version of zodern:types
// the catalog will never be available during the initial build
// since this build plugin is loaded too late
}
if (!setupFinished) {
writer.setup();
setupFinished = true;
}
var packages = loadPackages(appPath, catalog, remoteCatalogRoot);
for(var entry of Object.entries(packages)) {
var name = entry[0];
var packagePath = entry[1].path;
var isopack = entry[1].isopack;
var remote = entry[1].remote;
var typesEntry = findTypesEntry(packagePath, isopack, remote);
if (typesEntry) {
writer.addPackage(
name,
packagePath,
typesEntry
);
}
}
writer.writeToDisk();
if (isLinting) {
console.log('');
console.log('[zodern:types] Updated types');
console.log('[zodern:types] Exiting "meteor lint" early');
process.exit(0);
}
}
}