Skip to content

Commit

Permalink
chore: update for geofirestore v4
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Jun 15, 2020
1 parent 85ae7a1 commit 225d12b
Show file tree
Hide file tree
Showing 43 changed files with 12,477 additions and 12,139 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Editor configuration, see http://editorconfig.org
# Editor configuration, see https://editorconfig.org
root = true

[*]
Expand All @@ -8,6 +8,9 @@ indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out

# dependencies
/node_modules

# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json

# IDEs and editors
/.idea
.project
Expand All @@ -23,6 +29,7 @@
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# misc
/.sass-cache
Expand All @@ -40,5 +47,5 @@ Thumbs.db

# Custom
*.log

.firebase
serviceAccountKey.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 11
- 12
sudo: false
install:
- npm install
Expand Down
26 changes: 13 additions & 13 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"projects": {
"spittin-hot-geofirestore": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"styleext": "css"
}
},
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
Expand All @@ -21,7 +17,7 @@
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
Expand All @@ -46,7 +42,6 @@
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
Expand All @@ -55,6 +50,11 @@
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
Expand Down Expand Up @@ -82,8 +82,8 @@
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
Expand All @@ -98,8 +98,9 @@
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
Expand All @@ -119,7 +120,6 @@
}
}
}
}
},
}},
"defaultProject": "spittin-hot-geofirestore"
}
12 changes: 12 additions & 0 deletions browserslist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# You can see what browsers were selected by your queries by running:
# npx browserslist

> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.
12 changes: 6 additions & 6 deletions data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"start:js": "node dist/index.js",
"prepare": "npm run build"
},
"private": true,
"dependencies": {
"firebase-admin": "^8.2.0",
"fs-extra": "^8.1.0",
"geokit": "^0.1.4"
"firebase-admin": "^8.12.1",
"fs-extra": "^9.0.1",
"geokit": "^0.1.5"
},
"private": true,
"devDependencies": {
"ts-node": "^8.3.0",
"typescript": "^3.5.2"
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
}
}
55 changes: 31 additions & 24 deletions data/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
import * as admin from 'firebase-admin';
import { ensureDir, readFileSync, writeFileSync, unlinkSync } from 'fs-extra';
import { join } from 'path';
import { asyncForEach, filter, parse } from './utils';
import * as admin from "firebase-admin";
import { ensureDir, readFileSync, writeFileSync, unlinkSync } from "fs-extra";
import { join } from "path";
import { asyncForEach, filter, parse } from "./utils";

const serviceAccount = require('../serviceAccountKey.json');
const serviceAccount = require("../serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://' + serviceAccount['project_id'] + '.firebaseio.com'
databaseURL: "https://" + serviceAccount["project_id"] + ".firebaseio.com",
});
const collection: FirebaseFirestore.CollectionReference = admin.firestore().collection('restaurants');
const collection: FirebaseFirestore.CollectionReference = admin
.firestore()
.collection("restaurants");

// https://data.austintexas.gov/Health-and-Community-Services/Food-Establishment-Inspection-Scores/ecmv-9xxi
const austin = JSON.parse(readFileSync(join(__dirname, '../', 'cities/austin.json')));
const austin = JSON.parse(
readFileSync(join(__dirname, "../", "cities/austin.json"), "utf8")
);
// https://data.cityofchicago.org/Health-Human-Services/Restaurant/5udb-dr6f/data
const chicago = JSON.parse(readFileSync(join(__dirname, '../', 'cities/chicago.json')));
const chicago = JSON.parse(
readFileSync(join(__dirname, "../", "cities/chicago.json"), "utf8")
);
// https://docs.mongodb.com/getting-started/shell/import-data/
const newYork = JSON.parse(readFileSync(join(__dirname, '../', 'cities/new-york.json')));
const newYork = JSON.parse(
readFileSync(join(__dirname, "../", "cities/new-york.json"), "utf8")
);

const cacheFiles: string[] = [];
const restaurants: any[] = [
...filter(austin),
...filter(chicago),
...filter(newYork)
...filter(newYork),
];
let length = restaurants.length;
const folder = join(__dirname, '../', 'temp');
const folder = join(__dirname, "../", "temp");
console.log(`Inserting ${length} restaurants`);


ensureDir(folder, () => {
ensureDir(folder).then(() => {
while (restaurants.length) {
const temp = restaurants.splice(0, 500);
const path = join(folder, (Date.now() + Math.random() + '.json'));
const path = join(folder, Date.now() + Math.random() + ".json");
writeFileSync(path, JSON.stringify(temp));
cacheFiles.push(path);
}

(async () => {
asyncForEach(cacheFiles, async (path) => {
// @ts-ignore
const batchedData: any[] = parse(JSON.parse(readFileSync(path)));
const batchedData: any[] = parse(JSON.parse(readFileSync(path, "UTF8")));
const batch: FirebaseFirestore.WriteBatch = admin.firestore().batch();
batchedData.forEach((item) => {
const insert = collection.doc();
batch.create(insert, item);
});
await batch.commit()
.then(() => {
length -= batchedData.length;
console.log(`Inserted ${batchedData.length} docs, ${length} docs remaining`);
console.log(`Deleting ${path}`);
unlinkSync(path);
});
await batch.commit().then(() => {
length -= batchedData.length;
console.log(
`Inserted ${batchedData.length} docs, ${length} docs remaining`
);
console.log(`Deleting ${path}`);
unlinkSync(path);
});
});
})();
});
20 changes: 14 additions & 6 deletions data/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as admin from 'firebase-admin';
import { Geokit } from 'geokit';
import * as admin from "firebase-admin";
import { Geokit } from "geokit";

export async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
Expand All @@ -18,11 +18,19 @@ export function filter(unprocessed: any[]): any[] {

export function parse(unprocessed: any[]): any[] {
return unprocessed.map((restaurant: any) => {
restaurant.coordinates = new admin.firestore.GeoPoint(restaurant.coordinates[0], restaurant.coordinates[1]);
restaurant.coordinates = new admin.firestore.GeoPoint(
restaurant.coordinates[0],
restaurant.coordinates[1]
);
return {
g: Geokit.hash({ lat: restaurant.coordinates.latitude, lng: restaurant.coordinates.longitude }),
l: restaurant.coordinates,
d: restaurant
g: {
geohash: Geokit.hash({
lat: restaurant.coordinates.latitude,
lng: restaurant.coordinates.longitude,
}),
geopoint: restaurant.coordinates,
},
...restaurant,
};
});
}
Expand Down
6 changes: 0 additions & 6 deletions database.rules.json

This file was deleted.

8 changes: 6 additions & 2 deletions e2e/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require('jasmine-spec-reporter');

/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
browserName: 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
Expand All @@ -21,7 +25,7 @@ exports.config = {
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
Expand Down
11 changes: 10 additions & 1 deletion e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';

describe('workspace-project App', () => {
let page: AppPage;
Expand All @@ -9,6 +10,14 @@ describe('workspace-project App', () => {

it('should display welcome message', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('Welcome to pwa!');
expect(page.getTitleText()).toEqual('spittin-hot-geofirestore app is running!');
});

afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
level: logging.Level.SEVERE,
} as logging.Entry));
});
});
8 changes: 4 additions & 4 deletions e2e/src/app.po.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { browser, by, element } from 'protractor';

export class AppPage {
navigateTo() {
return browser.get('/');
navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl) as Promise<unknown>;
}

getParagraphText() {
return element(by.css('app-root h1')).getText();
getTitleText(): Promise<string> {
return element(by.css('app-root .content span')).getText() as Promise<string>;
}
}
4 changes: 2 additions & 2 deletions e2e/tsconfig.e2e.json → e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es5",
"types": [
Expand All @@ -10,4 +10,4 @@
"node"
]
}
}
}
3 changes: 0 additions & 3 deletions firestore.indexes.json

This file was deleted.

8 changes: 0 additions & 8 deletions firestore.rules

This file was deleted.

Loading

0 comments on commit 225d12b

Please sign in to comment.