Skip to content

Commit cf3e4ff

Browse files
authored
refactor: introduce typescript compiler (#246)
Use TypeScript compiler with the `allowJs` option. With the toolchain in place we can start migrating the files incrementally.
1 parent 6125d25 commit cf3e4ff

File tree

11 files changed

+64
-15
lines changed

11 files changed

+64
-15
lines changed

handwritten/logging/.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Language: JavaScript
2+
BasedOnStyle: Google
3+
ColumnLimit: 80

handwritten/logging/package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
"node": ">=6.0.0"
99
},
1010
"repository": "googleapis/nodejs-logging",
11-
"main": "./src/index.js",
11+
"main": "./build/src/index.js",
1212
"files": [
13-
"protos",
14-
"src",
13+
"build",
1514
"AUTHORS",
1615
"CONTRIBUTORS",
1716
"LICENSE"
@@ -51,16 +50,23 @@
5150
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>"
5251
],
5352
"scripts": {
54-
"cover": "nyc --reporter=lcov mocha test/*.js && nyc report",
55-
"test-no-cover": "mocha test/*.js",
53+
"cover": "nyc --reporter=lcov mocha build/test/*.js && nyc report",
54+
"test-no-cover": "mocha build/test/*.js",
5655
"test": "npm run cover",
5756
"docs": "jsdoc -c .jsdoc.js",
5857
"prettier": "prettier --write src/*.js src/**/*.js test/*.js test/**/*.js samples/*.js samples/**/*.js system-test/*.js system-test/**/*.js",
5958
"publish-module": "node ../../scripts/publish.js logging",
60-
"system-test": "mocha system-test/*.js --timeout 600000",
59+
"system-test": "mocha build/system-test/*.js --timeout 600000",
6160
"samples-test": "cd samples/ && npm test && cd ../",
6261
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
63-
"lint": "eslint src/ samples/ system-test/ test/"
62+
"lint": "eslint samples/",
63+
"check": "echo \"gts check disabled until ts migration is complete\"",
64+
"clean": "gts clean",
65+
"compile": "tsc -p . && cp src/v2/*.json build/src/v2 && cp -r protos build",
66+
"fix": "gts fix",
67+
"prepare": "npm run compile",
68+
"pretest": "npm run compile",
69+
"posttest": "npm run check"
6470
},
6571
"dependencies": {
6672
"@google-cloud/common-grpc": "^0.9.0",
@@ -105,6 +111,8 @@
105111
"prettier": "^1.14.2",
106112
"propprop": "^0.3.1",
107113
"proxyquire": "^2.1.0",
108-
"uuid": "^3.3.2"
114+
"uuid": "^3.3.2",
115+
"gts": "^0.8.0",
116+
"typescript": "~3.1.0"
109117
}
110118
}

handwritten/logging/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const pumpify = require('pumpify');
2828
const streamEvents = require('stream-events');
2929
const through = require('through2');
3030

31-
const PKG = require('../package.json');
31+
const PKG = require('../../package.json');
3232
const v2 = require('./v2');
3333

3434
const {Entry} = require('./entry');

handwritten/logging/src/v2/config_service_v2_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const gax = require('google-gax');
1919
const merge = require('lodash.merge');
2020
const path = require('path');
2121

22-
const VERSION = require('../../package.json').version;
22+
const VERSION = require('../../../package.json').version;
2323

2424
/**
2525
* Service for configuring sinks used to export log entries outside of

handwritten/logging/src/v2/logging_service_v2_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const merge = require('lodash.merge');
2020
const path = require('path');
2121
const protobuf = require('protobufjs');
2222

23-
const VERSION = require('../../package.json').version;
23+
const VERSION = require('../../../package.json').version;
2424

2525
/**
2626
* Service for ingesting and querying logs.

handwritten/logging/src/v2/metrics_service_v2_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const gax = require('google-gax');
1919
const merge = require('lodash.merge');
2020
const path = require('path');
2121

22-
const VERSION = require('../../package.json').version;
22+
const VERSION = require('../../../package.json').version;
2323

2424
/**
2525
* Service for configuring logs-based metrics.

handwritten/logging/synth.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434

3535
s.copy(v2_library, excludes=["src/index.js", "README.md", "package.json"])
3636

37+
s.replace(
38+
"src/v2/config_service_v2_client.js", "../../package.json", "../../../package.json"
39+
)
40+
s.replace(
41+
"src/v2/logging_service_v2_client.js", "../../package.json", "../../../package.json"
42+
)
43+
s.replace(
44+
"src/v2/metrics_service_v2_client.js", "../../package.json", "../../../package.json"
45+
)
46+
47+
3748
templates = common_templates.node_library()
3849
s.copy(templates)
3950

handwritten/logging/system-test/logging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const PubSub = require('@google-cloud/pubsub');
2727
const {Storage} = require('@google-cloud/storage');
2828
const uuid = require('uuid');
2929

30-
const {Logging} = require('../');
30+
const {Logging} = require('../src/index');
3131

3232
// block all attempts to chat with the metadata server (kokoro runs on GCE)
3333
nock('http://metadata.google.internal')

handwritten/logging/test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const proxyquire = require('proxyquire');
2323
const through = require('through2');
2424
const {util} = require('@google-cloud/common-grpc');
2525
const {v2} = require('../src');
26-
const PKG = require('../package.json');
26+
const PKG = require('../../package.json');
2727

2828
let extended = false;
2929
const fakePaginator = {
@@ -108,7 +108,7 @@ describe('Logging', () => {
108108
const PROJECT_ID = 'project-id';
109109

110110
before(() => {
111-
Logging = proxyquire('../', {
111+
Logging = proxyquire('../../', {
112112
'@google-cloud/common-grpc': {
113113
util: fakeUtil,
114114
},

handwritten/logging/tsconfig.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"extends": "./node_modules/gts/tsconfig-google.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"outDir": "build",
6+
"allowJs": true,
7+
"declaration": false,
8+
"skipLibCheck": true
9+
},
10+
"include": [
11+
"src/*.ts",
12+
"src/*/js",
13+
"src/**/*.ts",
14+
"src/**/*.js",
15+
"test/*.ts",
16+
"test/*.js",
17+
"test/**/*.ts",
18+
"test/**/*.js",
19+
"system-test/*.ts",
20+
"system-test/*.js",
21+
"system-test/**/*.ts",
22+
"system-test/**/*.js"
23+
]
24+
}

0 commit comments

Comments
 (0)