Skip to content

Commit

Permalink
feat: setup project
Browse files Browse the repository at this point in the history
- Added setup project script which is used to configure a starting point for a dbx-components project
  • Loading branch information
dereekb committed May 17, 2022
1 parent 04c1d9a commit fe2ae88
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/demo-api/src/app/function/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './auth.function';
export * from './init.user.function';
2 changes: 1 addition & 1 deletion apps/demo-api/src/test/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { authorizedUserContextFactory, AuthorizedUserTestContextFixture, Authori
import { JestBuildTestsWithContextFunction, JestTestContextFixture } from '@dereekb/util/test';
import { Module } from '@nestjs/common';
import { DemoApiAppModule } from '../app/app.module';
import { initUserOnCreate } from '../app/function/auth/auth.function';
import { initUserOnCreate } from '../app/function/auth/init.user.function';

// MARK: Demo Api Testing Fixture
@Module({
Expand Down
3 changes: 3 additions & 0 deletions packages/dbx-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
},
"dependencies": {
"tslib": "^2.3.0"
},
"devDependencies": {
"@ngrx/store-devtools": "^13.2.0"
}
}
5 changes: 4 additions & 1 deletion packages/firebase-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@dereekb/firebase-server",
"version": "4.0.1",
"devDependencies": {
"firebase-functions-test": "^2.0.0"
},
"exports": {
".": {
"main": "./src/index.js",
Expand All @@ -12,4 +15,4 @@
"types": "./test/index.d.ts"
}
}
}
}
5 changes: 4 additions & 1 deletion packages/firebase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@dereekb/firebase",
"version": "4.0.1",
"devDependencies": {
"@firebase/rules-unit-testing": "^2.0.0"
},
"exports": {
".": {
"main": "./src/index.js",
Expand All @@ -12,4 +15,4 @@
"types": "./test/index.d.ts"
}
}
}
}
53 changes: 53 additions & 0 deletions packages/rxjs/src/lib/rxjs/map.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { shareReplay, Subject } from 'rxjs';
import { SubscriptionObject } from './../subscription';
import { BehaviorSubject, of } from 'rxjs';
import { cleanup } from './lifecycle';
import { mapKeysIntersectionToArray } from './map';

describe('mapKeysIntersectionToArray()', () => {

let sub: SubscriptionObject;

beforeEach(() => {
sub = new SubscriptionObject();
});

afterEach(() => {
sub.destroy();
});

it('should merge the arrays if both values are present.', (done) => {

let subject = new Subject<string[]>();

const numbersA = [1, 2, 3];
const numbersB = [4, 5, 6];

const obs = of({
'a': numbersA,
'b': numbersB,
}).pipe(
mapKeysIntersectionToArray(subject),
shareReplay(1)
);

sub.subscription = obs.subscribe({
next: (value) => {
expect(value.length).toBe(6);
expect(numbersA).toContain(value[0]);
expect(numbersA).toContain(value[1]);
expect(numbersA).toContain(value[2]);
expect(numbersB).toContain(value[3]);
expect(numbersB).toContain(value[4]);
expect(numbersB).toContain(value[5]);
done();
},
complete: () => {
subject.complete();
}
});

subject.next(['a', 'b']);
});

});
1 change: 0 additions & 1 deletion packages/rxjs/src/lib/rxjs/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Observable } from 'rxjs';
import { asObservable } from '@dereekb/rxjs';
import { map, OperatorFunction, switchMap, shareReplay } from 'rxjs';
import { MapKeysIntersectionObject, mapKeysIntersectionObjectToArray } from "@dereekb/util";
Expand Down
28 changes: 20 additions & 8 deletions setup/setup-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CI_GIT_USER_NAME=ci # git username to use in CI deployme
# - Created a project on firebase. This step is required.
FIREBASE_PROJECT_ID=${1?:'firebase project id is required.'} # example: gethapier
INPUT_CODE_PREFIX=${2:-app} # example: gethapier
FIREBASE_BASE_EMULATORS_PORT=${3:-9100} # example: 9100
PARENT_DIRECTORY=${4:-'../../'} # parent directory to create this project within. Defaults to relative to this script's space within dbx-components.

# - Project Details
NAME=$FIREBASE_PROJECT_ID
Expand Down Expand Up @@ -52,7 +54,6 @@ COMPONENTS_DIST_FOLDER=dist/$COMPONENTS_FOLDER
ANGULAR_COMPONENTS_DIST_FOLDER=$COMPONENTS_DIST_FOLDER/$ANGULAR_COMPONENTS_NAME
FIREBASE_COMPONENTS_DIST_FOLDER=$COMPONENTS_DIST_FOLDER/$FIREBASE_COMPONENTS_NAME

FIREBASE_BASE_EMULATORS_PORT=9100
FIREBASE_EMULATOR_UI_PORT=$FIREBASE_BASE_EMULATORS_PORT
FIREBASE_EMULATOR_HOSTING_PORT=$(expr $FIREBASE_BASE_EMULATORS_PORT + 1)
FIREBASE_EMULATOR_FUNCTIONS_PORT=$(expr $FIREBASE_BASE_EMULATORS_PORT + 2)
Expand All @@ -66,7 +67,6 @@ FIREBASE_EMULATOR_PORT_RANGE="$FIREBASE_EMULATOR_UI_PORT-$FIREBASE_EMULATOR_STOR
ANGULAR_APP_PORT=$(expr $FIREBASE_BASE_EMULATORS_PORT + 10)

# - Setup Details
PARENT_DIRECTORY=../../ # assumes the current directory.

# Log into Firebase
echo "First log into Firebase if you're are not already logged in already."
Expand All @@ -89,7 +89,7 @@ git checkout setup

# remove decorate angular cli
rm decorate-angular-cli.js
npx --yes json -I -f package.json -e "this.scripts.postinstall='ngcc --properties es2015 browser module main';";
npx --yes json -I -f package.json -e "this.scripts={ postinstall: 'ngcc --properties es2015 browser module main', prepare: 'husky install' };";

# Commit the cloud initialization
git add --all
Expand All @@ -99,9 +99,9 @@ git commit -m "init nx-cloud"
nx migrate latest
npm install

if test -f "migration.json"; then # migrate if it is available
rm migrations.json # remove migrations file
if test -f "migrations.json"; then # migrate if it is available
nx migrate --run-migrations
rm migrations.json # remove migrations file
fi

npx --yes json -I -f nx.json -e "this.workspaceLayout = { appsDir: '$APPS_FOLDER', libsDir: '$COMPONENTS_FOLDER' }";
Expand Down Expand Up @@ -167,8 +167,6 @@ git commit -m "added firebase configuration"

# Install npm dependencies
npm i @dereekb/dbx-analytics @dereekb/dbx-web @dereekb/dbx-form @dereekb/firebase @dereekb/firebase-server @dereekb/dbx-firebase --force # TODO: Remove force once possible.
# npm i firebase firebase-admin firebase-functions # main dependencies
# npm i -D @firebase/rules-unit-testing firebase-functions-test firebase-tools # dev dependencies

git add --all
git commit -m "added @dereekb dependencies"
Expand All @@ -181,7 +179,7 @@ sed "s/demo-api/$API_APP_NAME/g" Dockerfile.tmp > Dockerfile
rm Dockerfile.tmp

curl https://raw.githubusercontent.com/dereekb/dbx-components/main/docker-compose.yml -o docker-compose.yml.tmp
sed -e "s/demo-api-server/$API_APP_NAME-server/g" -e "s/dereekb-components/$FIREBASE_PROJECT_ID/g" -e "s/9900-9906/$FIREBASE_EMULATOR_PORT_RANGE/g" docker-compose.yml.tmp > docker-componse.yml
sed -e "s/demo-api-server/$API_APP_NAME-server/g" -e "s/dereekb-components/$FIREBASE_PROJECT_ID/g" -e "s/9900-9906/$FIREBASE_EMULATOR_PORT_RANGE/g" docker-compose.yml.tmp > docker-compose.yml
rm docker-compose.yml.tmp

# download .gitignore
Expand Down Expand Up @@ -232,6 +230,10 @@ git commit -m "added Docker files and other utility files"
npm install -D @jscutlery/semver
curl https://raw.githubusercontent.com/dereekb/dbx-components/main/.commitlintrc.json -o .commitlintrc.json

mkdir .husky
curl https://raw.githubusercontent.com/dereekb/dbx-components/main/.husky/commit-msg -o .husky/commit-msg
npm run prepare

mkdir -p ./.github/workflows
curl https://raw.githubusercontent.com/dereekb/dbx-components/main/.github/workflows/commitlint.yml -o ./.github/workflows/commitlint.yml

Expand Down Expand Up @@ -300,6 +302,9 @@ curl https://raw.githubusercontent.com/dereekb/dbx-components/develop/setup/temp
sed -e "s:FIREBASE_COMPONENTS_DIST_FOLDER:$FIREBASE_COMPONENTS_DIST_FOLDER:g" -e "s:FIREBASE_COMPONENTS_FOLDER:$FIREBASE_COMPONENTS_FOLDER:g" -e "s:FIREBASE_COMPONENTS_NAME:$FIREBASE_COMPONENTS_NAME:g" $FIREBASE_COMPONENTS_FOLDER/project.json.tmp > $FIREBASE_COMPONENTS_FOLDER/project.json
rm $FIREBASE_COMPONENTS_FOLDER/project.json.tmp

# add settings to tsconfig.base.json
npx --yes json -I -f tsconfig.base.json -e "this.compilerOptions={ ...this.compilerOptions, strict: true, allowSyntheticDefaultImports: true, resolveJsonModule: true }";

git add --all
git commit -m "added project configurations"

Expand Down Expand Up @@ -496,3 +501,10 @@ download_api_ts_file "src/app/function/example/example.set.username.ts"

git add --all
git commit -m "setup api"

echo "Performing test build..."
nx build $ANGULAR_APP_NAME
nx build $API_APP_NAME

echo "Completed $ANGULAR_APP_NAME project setup."
echo "Project was created at \"$(pwd)\""
7 changes: 7 additions & 0 deletions setup/templates/apps/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
"lintFilePatterns": ["API_APP_FOLDER/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "./exec-with-emulator.sh 'npx nx run-tests API_APP_NAME'",
"color": true
}
},
"run-tests": {
"executor": "@nrwl/jest:jest",
"outputs": [
Expand Down
6 changes: 3 additions & 3 deletions setup/templates/apps/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
"ANGULAR_APP_FOLDER/src/assets",
"ANGULAR_APP_FOLDER/src/lib"
],
"allowedCommonJsDependencies": ["validator", "date-fns-tz"],
"allowedCommonJsDependencies": ["validator", "date-fns-tz", "@dereekb/browser", "@dereekb/util", "@dereekb/rxjs", "@dereekb/date", "@dereekb/firebase"],
"styles": ["ANGULAR_APP_FOLDER/src/styles.scss"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "3mb"
"maximumWarning": "4mb",
"maximumError": "6mb"
},
{
"type": "anyComponentStyle",
Expand Down
3 changes: 2 additions & 1 deletion setup/templates/components/firebase/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"watch": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"command": "./exec-with-emulator.sh 'npx nx run-tests FIREBASE_COMPONENTS_NAME --watch'"
"command": "./exec-with-emulator.sh 'npx nx run-tests FIREBASE_COMPONENTS_NAME --watch'",
"color": true
}
},
"run-tests": {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"@dereekb/util/test": ["packages/util/test/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
"exclude": ["node_modules", "tmp", "setup"]
}

0 comments on commit fe2ae88

Please sign in to comment.