dts-gen 0.6.1 → 0.7.1

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.
@@ -18,17 +18,17 @@ const path_1 = require("path");
18
18
  const url_1 = require("url");
19
19
  const names_1 = require("./names");
20
20
  function writeDefinitelyTypedPackage(indexDtsContent, packageName, overwrite) {
21
- const dtName = names_1.getDTName(packageName);
22
- const packageDir = path_1.join("types", dtName);
21
+ const dtName = (0, names_1.getDTName)(packageName);
22
+ const packageDir = (0, path_1.join)("types", dtName);
23
23
  // Check for overwrite
24
24
  if (!overwrite) {
25
- if (fs_1.existsSync(packageDir)) {
25
+ if ((0, fs_1.existsSync)(packageDir)) {
26
26
  console.log(`Directory ${packageDir} already exists and --overwrite was not specified; exiting.`);
27
27
  process.exit(2);
28
28
  }
29
29
  }
30
- if (!fs_1.existsSync(packageDir)) {
31
- fs_1.mkdirSync(packageDir);
30
+ if (!(0, fs_1.existsSync)(packageDir)) {
31
+ (0, fs_1.mkdirSync)(packageDir);
32
32
  }
33
33
  run(indexDtsContent, packageName, dtName, packageDir).catch(e => {
34
34
  console.error(e);
@@ -39,17 +39,37 @@ exports.default = writeDefinitelyTypedPackage;
39
39
  function run(indexDtsContent, packageName, dtName, packageDir) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  const files = [
42
- ["index.d.ts", yield getIndex(indexDtsContent, packageName)],
42
+ ["index.d.ts", indexDtsContent],
43
43
  [`${dtName}-tests.ts`, ""],
44
44
  ["tsconfig.json", `${JSON.stringify(getTSConfig(dtName), undefined, 4)}\n`],
45
+ ["package.json", `${JSON.stringify(yield getPackageJson(dtName, packageName), undefined, 4)}\n`],
45
46
  ["tslint.json", '{ "extends": "@definitelytyped/dtslint/dt.json" }\n'],
46
47
  ];
47
48
  for (const [name, text] of files) {
48
- fs_1.writeFileSync(path_1.join(packageDir, name), text, "utf-8");
49
+ (0, fs_1.writeFileSync)((0, path_1.join)(packageDir, name), text, "utf-8");
49
50
  }
50
51
  });
51
52
  }
52
- function getIndex(content, packageName) {
53
+ function getTSConfig(dtName) {
54
+ return {
55
+ compilerOptions: {
56
+ module: "commonjs",
57
+ lib: ["es6"],
58
+ noImplicitAny: true,
59
+ noImplicitThis: true,
60
+ strictFunctionTypes: true,
61
+ strictNullChecks: true,
62
+ types: [],
63
+ noEmit: true,
64
+ forceConsistentCasingInFileNames: true,
65
+ },
66
+ files: [
67
+ "index.d.ts",
68
+ `${dtName}-tests.ts`,
69
+ ],
70
+ };
71
+ }
72
+ function getPackageJson(dtName, packageName) {
53
73
  var _a, _b, _c;
54
74
  return __awaiter(this, void 0, void 0, function* () {
55
75
  let version = "x.x";
@@ -69,7 +89,7 @@ function getIndex(content, packageName) {
69
89
  }
70
90
  let authorName = 'My Self';
71
91
  try {
72
- const globalGitConfig = parseGitConfig.sync({ cwd: os_1.homedir(), path: '.gitconfig' });
92
+ const globalGitConfig = parseGitConfig.sync({ cwd: (0, os_1.homedir)(), path: '.gitconfig' });
73
93
  if (globalGitConfig.user && globalGitConfig.user.name) {
74
94
  authorName = globalGitConfig.user.name;
75
95
  }
@@ -79,9 +99,9 @@ function getIndex(content, packageName) {
79
99
  }
80
100
  let authorUserName = 'me';
81
101
  try {
82
- const repoGitConfig = parseGitConfig.sync({ path: path_1.join('.git', 'config') });
102
+ const repoGitConfig = parseGitConfig.sync({ path: (0, path_1.join)('.git', 'config') });
83
103
  if (repoGitConfig['remote "origin"'] && repoGitConfig['remote "origin"'].url) {
84
- const url = url_1.parse(repoGitConfig['remote "origin"'].url);
104
+ const url = (0, url_1.parse)(repoGitConfig['remote "origin"'].url);
85
105
  if (url.hostname === 'github.com' && url.pathname) {
86
106
  authorUserName = url.pathname.split('/')[1] || authorUserName;
87
107
  }
@@ -93,43 +113,26 @@ function getIndex(content, packageName) {
93
113
  catch (e) {
94
114
  console.warn(`Warning: Could not retrieve author's user name: ${e.message}`);
95
115
  }
96
- const authorUrl = url_1.format({
97
- protocol: 'https',
98
- hostname: 'github.com',
99
- pathname: authorUserName,
100
- });
101
- return `// Type definitions for ${packageName} ${version}
102
- // Project: ${project}
103
- // Definitions by: ${authorName} <${authorUrl}>
104
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
105
-
106
- ${content}`;
116
+ return {
117
+ private: true,
118
+ name: `@types/${dtName}`,
119
+ version: `${version}.0.99999`,
120
+ projects: [project],
121
+ devDependencies: {
122
+ [`@types/${dtName}`]: "workspace:."
123
+ },
124
+ contributors: [
125
+ {
126
+ name: authorName,
127
+ githubUsername: authorUserName
128
+ }
129
+ ]
130
+ };
107
131
  });
108
132
  }
109
- function getTSConfig(dtName) {
110
- return {
111
- compilerOptions: {
112
- module: "commonjs",
113
- lib: ["es6"],
114
- noImplicitAny: true,
115
- noImplicitThis: true,
116
- strictFunctionTypes: true,
117
- strictNullChecks: true,
118
- baseUrl: "../",
119
- typeRoots: ["../"],
120
- types: [],
121
- noEmit: true,
122
- forceConsistentCasingInFileNames: true,
123
- },
124
- files: [
125
- "index.d.ts",
126
- `${dtName}-tests.ts`,
127
- ],
128
- };
129
- }
130
133
  function loadString(url) {
131
134
  return new Promise((resolve, reject) => {
132
- https_1.get(url, res => {
135
+ (0, https_1.get)(url, res => {
133
136
  if (res.statusCode !== 200) {
134
137
  return reject(new Error(`HTTP Error ${res.statusCode}: ${http_1.STATUS_CODES[res.statusCode || 500]} for ${url}`));
135
138
  }
package/bin/lib/index.js CHANGED
@@ -13,29 +13,29 @@ const builtins = {
13
13
  };
14
14
  function forceAsIdentifier(s) {
15
15
  // TODO: Make this more comprehensive
16
- return names_1.getDTName(s.replace(/-/g, '_'));
16
+ return (0, names_1.getDTName)(s.replace(/-/g, '_'));
17
17
  }
18
18
  function getValueTypes(value) {
19
19
  if (typeof value === 'object') {
20
20
  // Objects can't be callable, so no need to check for class / function
21
- return 4 /* Object */;
21
+ return 4 /* ValueTypes.Object */;
22
22
  }
23
23
  else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
24
- return 8 /* Primitive */;
24
+ return 8 /* ValueTypes.Primitive */;
25
25
  }
26
26
  else if (value === null || value === undefined) {
27
- return 16 /* NullOrUndefined */;
27
+ return 16 /* ValueTypes.NullOrUndefined */;
28
28
  }
29
29
  else if (typeof value === 'function') {
30
30
  if (isClasslike(value)) {
31
- return 1 /* Class */ | (hasCloduleProperties(value) ? 4 /* Object */ : 0 /* None */);
31
+ return 1 /* ValueTypes.Class */ | (hasCloduleProperties(value) ? 4 /* ValueTypes.Object */ : 0 /* ValueTypes.None */);
32
32
  }
33
33
  else {
34
- return 2 /* Function */ | (hasFunduleProperties(value) ? 4 /* Object */ : 0 /* None */);
34
+ return 2 /* ValueTypes.Function */ | (hasFunduleProperties(value) ? 4 /* ValueTypes.Object */ : 0 /* ValueTypes.None */);
35
35
  }
36
36
  }
37
37
  else {
38
- return 32 /* Unknown */;
38
+ return 32 /* ValueTypes.Unknown */;
39
39
  }
40
40
  }
41
41
  // A class has clodule properties if it has any classes. Anything else can be written with 'static'
@@ -183,11 +183,11 @@ function getTopLevelDeclarations(name, obj) {
183
183
  // If anything in here is classlike or functionlike, write it as a namespace.
184
184
  // Otherwise, write as a 'const'
185
185
  const keys = getKeysOfObject(obj);
186
- let constituentTypes = 0 /* None */;
186
+ let constituentTypes = 0 /* ValueTypes.None */;
187
187
  for (const k of keys) {
188
188
  constituentTypes = constituentTypes | getValueTypes(obj[k]);
189
189
  }
190
- if (constituentTypes & (1 /* Class */ | 2 /* Function */)) {
190
+ if (constituentTypes & (1 /* ValueTypes.Class */ | 2 /* ValueTypes.Function */)) {
191
191
  const ns = dom.create.namespace(name);
192
192
  for (const k of keys) {
193
193
  const decls = getTopLevelDeclarations(k, obj[k]);
package/bin/lib/run.js CHANGED
@@ -90,7 +90,7 @@ try {
90
90
  throw new Error('Internal error, please log a bug with the commandline you specified');
91
91
  }
92
92
  if (args.dt) {
93
- definitely_typed_1.default(result, name, !!args.overwrite);
93
+ (0, definitely_typed_1.default)(result, name, !!args.overwrite);
94
94
  }
95
95
  else if (args.stdout) {
96
96
  console.log(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dts-gen",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "TypeScript Definition File Generator",
5
5
  "main": "bin/lib/index.js",
6
6
  "bin": {