Skip to content

Commit

Permalink
refactor(typescript): perform initial TypeScript conversion (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Oct 23, 2018
1 parent bb6a7c0 commit f37ddc8
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Language: JavaScript
BasedOnStyle: Google
ColumnLimit: 80
2 changes: 1 addition & 1 deletion .jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
source: {
excludePattern: '(^|\\/|\\\\)[._]',
include: [
'src'
'build/src'
],
includePattern: '\\.js$'
},
Expand Down
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": ">=6.0.0"
},
"repository": "googleapis/nodejs-spanner",
"main": "./src/index.js",
"main": "./build/src/index.js",
"files": [
"protos",
"src",
Expand Down Expand Up @@ -52,18 +52,21 @@
"haih-g <[email protected]>"
],
"scripts": {
"cover": "nyc --reporter=lcov mocha test/*.js && nyc report",
"docs": "jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "eslint src/ samples/ system-test/ test/ scripts/",
"lint": "echo disabled for now",
"prettier": "prettier --write benchmark/*.js src/*.js src/*/*.js src/admin/database/*/*.js src/admin/instance/*/*.js samples/*.js samples/*/*.js samples/*/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha system-test/*.js --timeout 600000",
"system-test": "mocha build/system-test --timeout 600000",
"cleanup": "mocha scripts/cleanup.js --timeout 30000",
"test-no-cover": "mocha test/*.js",
"test": "npm run cover",
"test": "nyc mocha build/test",
"ycsb": "node ./benchmark/ycsb.js run -P ./benchmark/workloada -p table=usertable -p cloudspanner.instance=ycsb-instance -p operationcount=100 -p cloudspanner.database=ycsb",
"fix": "eslint --fix '**/*.js'"
"fix": "eslint --fix '**/*.js'",
"clean": "gts clean",
"compile": "tsc -p . && cp src/v1/*.json build/src/v1 && cp -r protos build",
"prepare": "npm run compile",
"pretest": "npm run compile",
"presystem-test": "npm run compile"
},
"dependencies": {
"@google-cloud/common-grpc": "^0.9.0",
Expand Down Expand Up @@ -112,6 +115,8 @@
"stats-lite": "^2.1.1",
"time-span": "^2.0.0",
"uuid": "^3.3.2",
"yargs": "^12.0.1"
"yargs": "^12.0.1",
"gts": "^0.8.0",
"typescript": "~3.1.3"
}
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Spanner extends Service {
options = extend(
{
libName: 'gccl',
libVersion: require('../package.json').version,
libVersion: require('../../package.json').version,
scopes,
},
options || {}
Expand All @@ -189,7 +189,7 @@ class Spanner extends Service {
},
},
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
packageJson: require('../package.json'),
packageJson: require('../../package.json'),
};
super(config, options);
this.options = options;
Expand Down
2 changes: 1 addition & 1 deletion src/v1/database_admin_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const merge = require('lodash.merge');
const path = require('path');
const protobuf = require('protobufjs');

const VERSION = require('../../package.json').version;
const VERSION = require('../../../package.json').version;

/**
* Cloud Spanner Database Admin API
Expand Down
2 changes: 1 addition & 1 deletion src/v1/instance_admin_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const merge = require('lodash.merge');
const path = require('path');
const protobuf = require('protobufjs');

const VERSION = require('../../package.json').version;
const VERSION = require('../../../package.json').version;

/**
* Cloud Spanner Instance Admin API
Expand Down
2 changes: 1 addition & 1 deletion src/v1/spanner_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const gax = require('google-gax');
const merge = require('lodash.merge');
const path = require('path');

const VERSION = require('../../package.json').version;
const VERSION = require('../../../package.json').version;

/**
* Cloud Spanner API
Expand Down
8 changes: 6 additions & 2 deletions synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@
module.exports.InstanceAdminClient = InstanceAdminClient;
\g<1>""")

# Update path discovery due to build/ dir and TypeScript conversion.
s.replace("src/v1/database_admin_client.js", "../../package.json", "../../../package.json")
s.replace("src/v1/instance_admin_client.js", "../../package.json", "../../../package.json")
s.replace("src/v1/spanner_client.js", "../../package.json", "../../../package.json")

# '''
# Node.js specific cleanup
# '''
subprocess.run(['npm', 'install'])
subprocess.run(['npm', 'run', 'prettier'])
subprocess.run(['npm', 'run', 'lint'])
subprocess.run(['npm', 'run', 'fix'])

2 changes: 1 addition & 1 deletion system-test/spanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const extend = require('extend');
const is = require('is');
const uuid = require('uuid');

const {Spanner} = require('../');
const {Spanner} = require('../src');

const PREFIX = 'gcloud-tests-';
const RUN_ID = uuid
Expand Down
8 changes: 4 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('Spanner', () => {
it('should create an auth instance from google-auth-library', () => {
const expectedOptions = extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../package.json').version,
libVersion: require('../../package.json').version,
scopes: [],
});

Expand All @@ -170,7 +170,7 @@ describe('Spanner', () => {

const expectedOptions = extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../package.json').version,
libVersion: require('../../package.json').version,
scopes: expectedScopes,
});

Expand All @@ -193,14 +193,14 @@ describe('Spanner', () => {
},
},
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
packageJson: require('../package.json'),
packageJson: require('../../package.json'),
});

assert.deepStrictEqual(
options,
extend({}, OPTIONS, {
libName: 'gccl',
libVersion: require('../package.json').version,
libVersion: require('../../package.json').version,
scopes: [],
})
);
Expand Down
3 changes: 2 additions & 1 deletion test/row-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ describe('RowBuilder', () => {
});

describe('acceptance tests', () => {
const TESTS = require('./data/streaming-read-acceptance-test.json').tests;
const TESTS = require('../../test/data/streaming-read-acceptance-test.json')
.tests;

TESTS.forEach(test => {
it('should pass acceptance test: ' + test.name, () => {
Expand Down
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"allowJs": true,
"declaration": false,
"skipLibCheck": true
},
"include": [
"src/*.ts",
"src/*/js",
"src/**/*.ts",
"src/**/*.js",
"test/*.ts",
"test/*.js",
"test/**/*.ts",
"test/**/*.js",
"system-test/*.ts",
"system-test/*.js",
"system-test/**/*.ts",
"system-test/**/*.js"
]
}
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "gts/tslint.json"
}

0 comments on commit f37ddc8

Please sign in to comment.