Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: npm workspaces (#231)
Browse files Browse the repository at this point in the history
boweihan authored Sep 6, 2022
1 parent 3e9784d commit 8e200be
Showing 28 changed files with 90,089 additions and 24,479 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ jobs:

- name: Install and Build
run: |
yarn install --frozen-lockfile
yarn build
npm ci
npm run build
- name: Publish
run: yarn run publishToNpm
run: npm run publishToNpm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 5 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -14,18 +14,16 @@ jobs:

- name: Install and Build
run: |
yarn install --frozen-lockfile
yarn build
./packages/components/node_modules/cypress/bin/cypress install
npm ci
npm run build
- name: Run unit tests
run: yarn test
run: npm test

- name: cypress run
- name: Run integration tests
uses: cypress-io/github-action@v2
with:
command: yarn test:cypress-ct
working-directory: packages/components
command: npm run test:integration
# after the test run completes
# store videos and any screenshots
- uses: actions/upload-artifact@v1
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CYPRESS_INSTALL_BINARY=0
puppeteer_skip_chromium_download=true
legacy-peer-deps=true
39 changes: 34 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -2,22 +2,51 @@

### Environment setup

Iot-App-Kit runs on node and uses yarn for package management. Specific versions are required in order to keep builds working with the current monorepo tooling.
Iot-App-Kit runs on node and uses npm for package management. Specific versions are required in order to keep builds working with the current monorepo tooling.

Ensure you have `node` version 16 and `npm` > 8.0.

- Node: any `v16` or higher
- Yarn: any `v1`, but not `v2` or higher
- Npm: `v8.0.0` or higher

### Building Iot-App-Kit

With supported versions of node and yarn installed, you're ready to connect to SiteWise and start building for Iot-App-Kit. You'll need to pull in credentials, specify the SiteWise assets you'd like to connect to, build the project, and then run locally.
With supported versions of node and npm installed, you're ready to connect to SiteWise and start building for Iot-App-Kit. You'll need to pull in credentials, specify the SiteWise assets you'd like to connect to, build the project, and then run locally.

1. Copy a set of AWS JSON formatted credentials to the account with the access to the SiteWise resources you are requesting, at `<rootDir>/packages/components/creds.json`.

2. Alter the file `siteWiseQueries` within `@iot-app-kit/components` to point to valid SiteWise asset properties for the account credentials from the prior step.

3. `yarn bootstrap` installs dependencies and builds the Iot-App-Kit packages. Note: this is different than using `lerna bootstrap`, which installs dependencies but doesn't build the packages.
# Update to node version 16
sudo n 16
```
2. Build project
```bash
cd iot-app-kit/ (root)
npm install
npm run build
```

3. Running build commands for specific packages

```
npm run <command> -w @iot-app-kit/<package>
```

4. Provide credentials
Copy a set of AWS JSON formatted credentials to the account with the access to the SiteWise resources you are requesting, at `<rootDir>/packages/components/creds.json`.

These credentials should not be uploaded to the repository.

5. Point to valid SiteWise resources

Alter the file `siteWiseQueries` within `@iot-app-kit/components` to point to valid SiteWise asset properties for the accounts credentials from the prior step.

6. Test locally

4. `yarn start` will run the project at `localhost:3333`. You should see example IoT App Kit components requesting data from SiteWise.
Run`npm run start` at the project root and then view `localhost:3333`. You should see example IoT App Kit components requesting data from SiteWise.

### Coding guidelines and requirements

13 changes: 0 additions & 13 deletions lerna.json

This file was deleted.

89,957 changes: 89,957 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -7,36 +7,40 @@
"repository": "git@github.com:awslabs/iot-app-kit.git",
"engines": {
"node": ">=16.0.0",
"yarn": ">=1.0.0 <2.0.0"
"npm": ">=8.0.0"
},
"workspaces": {
"packages": [
"packages/*"
"packages/core",
"packages/source-iotsitewise",
"packages/related-table",
"packages/components",
"packages/react-components"
]
},
"scripts": {
"start": "cd packages/components && yarn run start",
"bootstrap": "yarn install && yarn build",
"build": "lerna run build --stream",
"start": "cd packages/components && npm start",
"bootstrap": "npm install && npm run build",
"build": "npm run build -ws",
"clean": "git clean -dxf -e /.idea -e /.vscode -e creds.json",
"fix": "npm-run-all -p fix:eslint fix:stylelint",
"fix:eslint": "eslint --fix --ext .js,.ts,.tsx .",
"fix:stylelint": "stylelint '**/*.css' --fix",
"test": "npm-run-all -p test:unit test:eslint test:stylelint test:git",
"test:eslint": "eslint --ext .js,.ts,.tsx . --max-warnings=37",
"test:integration": "npm run test:integration -ws --if-present",
"test:eslint": "eslint --ext .js,.ts,.tsx . --max-warnings=49",
"test:stylelint": "stylelint '**/*.css' --max-warnings 0",
"test:unit": "lerna run test --stream --concurrency 1",
"test:unit": "npm run test -ws --if-present",
"test:git": "git diff --exit-code",
"pack": "lerna run pack",
"versionup:auto": "lerna version --conventional-commits --no-changelog --no-push --no-git-tag-version --yes",
"versionup:patch": "lerna version patch --conventional-commits --no-changelog --no-push --no-git-tag-version --yes",
"versionup:minor": "lerna version minor --conventional-commits --no-changelog --no-push --no-git-tag-version --yes",
"versionup:major": "lerna version major --conventional-commits --no-changelog --no-push --no-git-tag-version --yes",
"publishToNpm": "lerna publish from-package --no-verify-access --yes"
"pack": "npm pack -ws",
"link": "npm link -ws",
"versionup:patch": "npm version --no-git-tag-version -ws patch",
"versionup:minor": "npm version --no-git-tag-version -ws minor",
"versionup:major": "npm version --no-git-tag-version -ws major",
"publishToNpm": "npm publish -ws"
},
"devDependencies": {
"@babel/core": "^7.6.4",
"@cypress/webpack-preprocessor": "^4.1.1",
"@jest/core": "26.6.3",
"@testing-library/dom": "^7.22.2",
"@testing-library/user-event": "^12.1.1",
@@ -83,8 +87,6 @@
"jest-extended": "^0.11.2",
"jest-matcher-utils": "26.6.2",
"jest-raw-loader": "^1.0.1",
"lerna": "^4.0.0",
"lerna-changelog": "^1.0.1",
"npm-run-all": "^4.1.5",
"query-string": "^6.13.5",
"stylelint": "14.8.2",
7 changes: 5 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -39,8 +39,9 @@
"start": "stencil build --dev --watch --serve",
"test": "stencil test --spec",
"test.watch": "stencil test --spec --watchAll",
"test:cypress-ct": "cypress run-ct",
"test:cypress-ct-dev": "cypress open-ct --env disableSnapshotTests=true"
"test:integration": "./node_modules/.bin/cypress install && ./node_modules/.bin/cypress run-ct",
"test:cypress-ct": "./node_modules/.bin/cypress run-ct",
"test:cypress-ct-dev": "./node_modules/.bin/cypress open-ct --env disableSnapshotTests=true"
},
"peerDependencies": {
"react": ">=16.14.0",
@@ -62,13 +63,15 @@
"@cypress/webpack-dev-server": "^1.8.4",
"@rollup/plugin-replace": "^3.0.0",
"@stencil/router": "^1.0.1",
"@types/chai": "^4.3.3",
"@types/cypress-image-snapshot": "^3.1.6",
"@types/react": ">=16.9.0",
"@types/react-dom": ">=16.9.0",
"@types/uuid": "^8.3.4",
"@vue/cli-plugin-typescript": "^4.5.15",
"@vue/cli-service": "^4.5.15",
"@vue/compiler-dom": "^3.2.26",
"chai": "^4.3.6",
"cypress": "^9.6.1",
"cypress-image-snapshot": "^4.0.1",
"cypress-wait-until": "^1.7.2",
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ export class IotResourceExplorer {
}

expandNode = (node: ITreeNode<SiteWiseAssetResource>) => {
node.hierarchies?.forEach((hierarchy) => {
node.hierarchies?.forEach((hierarchy: any) => {
this.provider.expand(new BranchReference(node.id, hierarchy.id as string));
});
};
@@ -106,7 +106,7 @@ export class IotResourceExplorer {

newItems.forEach(({ id, hierarchies, hasChildren }) => {
if (!this.expandedItems[id] && hasChildren) {
hierarchies?.forEach((hierarchy) => {
hierarchies?.forEach((hierarchy: any) => {
this.provider.expand(new BranchReference(id, hierarchy.id as string));
});

Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ export class IotTreeTable {
this.onSelectionChange(event);
}
},
} as RelatedTableExtendedProps<unknown>;
} as unknown as RelatedTableExtendedProps<unknown>;

ReactDOM.render(React.createElement(RelatedTableWithCollectionHooks, attributes), this.host);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference types="cypress-image-snapshot" />
import { renderChart } from '../../testing/renderChart';
import { mockBatchGetAggregatedOrRawResponse } from '../../testing/mocks/mockGetAggregatedOrRawResponse';
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';
import { ScaleConfig, ScaleType } from '@synchro-charts/core';
import { mockGetAssetModelSummary } from '../../testing/mocks/mockGetAssetModelSummary';
import { expect } from 'chai';

const SECOND_IN_MS = 1000;

Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import {
} from '../../testing/mocks/mockGetAggregatedOrRawResponse';
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';
import { mockGetAssetModelSummary } from '../../testing/mocks/mockGetAssetModelSummary';
import { expect } from 'chai';

const SECOND_IN_MS = 1000;

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { mockBatchGetAggregatedOrRawResponse } from '../../testing/mocks/mockGet
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';
import { ScaleConfig, ScaleType } from '@synchro-charts/core';
import { mockGetAssetModelSummary } from '../../testing/mocks/mockGetAssetModelSummary';
import { expect } from 'chai';

const SECOND_IN_MS = 1000;

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="cypress-wait-until" />
import { renderComponent, testContainerClassName } from './setup';
import {
getTableAscSortedColumnSelector,
@@ -9,6 +10,7 @@ import {
setTableColumnSelectionSelector,
setTableRowSelection,
setTextFilterValue,
clearInputValue,
} from './utils';
import { mocklistAssociatedAssetsResponse } from '../../testing/mocks/data/listAssociatedAssetsResponse';
import { mocklistAssetsResponse } from '../../testing/mocks/data/listAssetsResponse';
@@ -18,34 +20,36 @@ beforeEach(() => {
cy.intercept(`/assets/${mocklistAssetsResponse.assetSummaries?.[0].id}/*`, mocklistAssociatedAssetsResponse);
});

it('sort by name asc', () => {
it('supports tree operations', () => {
renderComponent();

// sort by name asc
cy.get(`.${testContainerClassName}`).should('be.visible');
cy.get(getTableDescSortedColumnSelector()).should('be.contain', 'Asset Name');
setTableColumnSelectionSelector('', 1, true);
cy.get(getTableAscSortedColumnSelector()).should('be.contain', 'Asset Name');
cy.get(getTableRowSelector(1)).should('be.contain', 'Turbine 1');
cy.matchImageSnapshotOnCI('sort by name asc');
});

it('filter by name', () => {
renderComponent();
// reset
setTableColumnSelectionSelector('', 1, false);

// filter by name
cy.get(`.${testContainerClassName}`).should('be.visible');
setTextFilterValue('Turbine', '[placeholder="Filter by name"]');
cy.waitUntil(() => cy.get(getTableRowsSelector()).then((rows) => rows.length === 1));
cy.matchImageSnapshotOnCI('filter by name');
});

it('select row', () => {
renderComponent();
// reset
clearInputValue('[placeholder="Filter by name"]');

// select row
cy.get(`.${testContainerClassName}`).should('be.visible');
setTableRowSelection(2);
cy.get(getTableSelectedRowsSelector()).should('be.contain', 'Turbine 1');
cy.matchImageSnapshotOnCI('select row');
});

it('expand row', () => {
renderComponent();
// expand row
cy.get(`.${testContainerClassName}`).should('be.visible');
cy.get(getTableCellSelector(2, 2)).should('be.contain', 'Turbine 1');
cy.get(getTableCellSelector(2, 2)).then((cell) => {
@@ -54,10 +58,3 @@ it('expand row', () => {
cy.waitUntil(() => cy.get(getTableRowsSelector()).then((rows) => rows.length === 4));
cy.matchImageSnapshotOnCI('expand row');
});

it('expands all nodes', () => {
renderComponent({ propOverrides: { expanded: true } });

cy.contains('Engine 1').should('be.visible');
cy.contains('Engine 2').should('be.visible');
});
Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@ export const getTextFilterSelector = (selector?: string) => wrapper().findTextFi
export const setTextFilterValue = (value: string, selector: string) =>
cy.get(selector).focus().clear().type(value, { delay: 100 });

export const clearInputValue = (selector: string) => cy.get(selector).focus().clear();

export const setTableRowSelection = (rowIndex: number, selector?: string) => {
cy.get(wrapper().findTable(selector).findRowSelectionArea(rowIndex).toSelector()).click();
};
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { mockBatchGetAggregatedOrRawResponse } from '../../testing/mocks/mockGet
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';
import { ScaleConfig, ScaleType } from '@synchro-charts/core';
import { mockGetAssetModelSummary } from '../../testing/mocks/mockGetAssetModelSummary';
import { expect } from 'chai';

const SECOND_IN_MS = 1000;

Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import {
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';
import { COMPARISON_OPERATOR } from '@synchro-charts/core';
import { mockGetAssetModelSummary } from '../../testing/mocks/mockGetAssetModelSummary';
import { expect } from 'chai';

const SECOND_IN_MS = 1000;

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { mockBatchGetAggregatedOrRawResponse } from '../../testing/mocks/mockGet
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';
import { COMPARISON_OPERATOR } from '@synchro-charts/core';
import { mockGetAssetModelSummary } from '../../testing/mocks/mockGetAssetModelSummary';
import { expect } from 'chai';

const SECOND_IN_MS = 1000;

12 changes: 8 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -25,15 +25,15 @@
},
"scripts": {
"clean": "rm -rf dist && rm -rf screenshot",
"build": "yarn run clean && rollup --config rollup.config.js",
"build": "npm run clean && rollup --config rollup.config.js",
"test": "npm-run-all -p test:jest test:typescript",
"test:jest": "TZ=UTC jest --coverage",
"test.watch": "TZ=UTC jest --watchAll",
"test:typescript": "tsc --noEmit",
"copy:license": "cp ../../LICENSE LICENSE",
"copy:notice": "cp ../../NOTICE NOTICE",
"prepack": "yarn run copy:license && yarn run copy:notice",
"pack": "yarn pack"
"prepack": "npm run copy:license && npm run copy:notice",
"pack": "npm pack"
},
"dependencies": {
"@aws-sdk/client-iotsitewise": "^3.87.0",
@@ -60,5 +60,9 @@
"jest": "^27.5.1",
"jest-extended": "^2.0.0",
"ts-jest": "^27.1.3"
}
},
"bugs": {
"url": "https://github.com/awslabs/iot-app-kit/issues"
},
"homepage": "https://github.com/awslabs/iot-app-kit#readme"
}
6 changes: 5 additions & 1 deletion packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -59,5 +59,9 @@
"node_modules",
"dist"
]
}
},
"bugs": {
"url": "https://github.com/awslabs/iot-app-kit/issues"
},
"homepage": "https://github.com/awslabs/iot-app-kit#readme"
}
24 changes: 9 additions & 15 deletions packages/related-table/README.md
Original file line number Diff line number Diff line change
@@ -8,41 +8,35 @@ Presents data in a two-dimensional table format with hierarchical view, arranged
- React and React Hooks >= 16.8.0
- Typescript >= 4.3.0
- AWSUI open source dependencies:
- @awsui/components-react: ^3.0.0
- @awsui/collection-hooks: ^1.0.0
- @awsui/design-tokens: ^3.0.0
- `@awsui/components-react: ^3.0.0`
- `@awsui/collection-hooks: ^1.0.0`
- `@awsui/design-tokens: ^3.0.0`

## Install - Peer dependencies

Add to your package.json:
```json
"dependencies": {
"@iot-app-kit/related-table": "^1.0.0",
"@awsui/collection-hooks": "^1.0.0",
"@awsui/components-react": "^3.0.0",
"@awsui/design-tokens": "^3.0.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"styled-components": "^5.3.0",

```bash
npm i --save @iot-app-kit/related-table @awsui/collection-hooks @awsui/components-react @awsui/design-tokens react react-dom styled-components
```

## Development

### Local Setup

```bash
yarn install
npm install
```

### Storybook

```bash
yarn storybook
npm run storybook
```

### Jest

Jest tests are set up to run with `npm test` or `yarn test`.
Jest tests are set up to run with `npm test`.

### TypeScript

6 changes: 5 additions & 1 deletion packages/related-table/package.json
Original file line number Diff line number Diff line change
@@ -85,5 +85,9 @@
"dependencies": {
"mutationobserver-shim": "^0.3.7",
"uuid": "^8.3.2"
}
},
"bugs": {
"url": "https://github.com/awslabs/iot-app-kit/issues"
},
"homepage": "https://github.com/awslabs/iot-app-kit#readme"
}
4 changes: 2 additions & 2 deletions packages/related-table/src/HOC/withUseTreeCollection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React, { FC } from 'react';
import TextFilter from '@awsui/components-react/text-filter';
import Pagination from '@awsui/components-react/pagination';
import { NonCancelableCustomEvent, TableProps } from '@awsui/components-react';
@@ -15,7 +15,7 @@ export interface RelatedTableExtendedProps<T> extends Omit<RelatedTableProps<T>,
expanded?: boolean;
}

export const withUseTreeCollection = (RelatedTableComp: React.FC<any>) => {
export const withUseTreeCollection = (RelatedTableComp: FC<any>) => {
return (wrapperProps: RelatedTableExtendedProps<any>) => {
const {
items,
Original file line number Diff line number Diff line change
@@ -44,9 +44,11 @@ export const ButtonWithTreeLines = React.memo(function ButtonWithTreeLinesComp<T
return (
<Wrapper height={TABLE_ROW_HEIGHT_PERCENT + WRAPPER_EXTRA_HEIGHT_PERCENT}>
<LeftPad length={leftPadLength}>
{createPrefixLines(node, theme, alwaysExpanded)}
{createToggleButton(props)}
{content}
<>
{createPrefixLines(node, theme, alwaysExpanded)}
{createToggleButton(props)}
{content}
</>
</LeftPad>
</Wrapper>
);
1 change: 1 addition & 0 deletions packages/related-table/src/RelatedTable/RelatedTable.tsx
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ export interface RelatedTableProps<T> extends TableProps<T> {

export function RelatedTable<T>(props: RelatedTableProps<ITreeNode<T>>) {
const { columnDefinitions, items = [], expandChildren, expandColumnPosition = 1, filteringText = '' } = props;

const isFiltering = filteringText !== '';
const zeroBasedColumnPos = expandColumnPosition - 1;
const columns = [...columnDefinitions];
6 changes: 3 additions & 3 deletions packages/source-iotsitewise/package.json
Original file line number Diff line number Diff line change
@@ -26,16 +26,16 @@
},
"scripts": {
"clean": "rm -rf dist && rm -rf screenshot",
"build": "yarn run clean && yarn run build:types && rollup --config rollup.config.js",
"build": "npm run clean && npm run build:types && rollup --config rollup.config.js",
"build:types": "tsc --outDir dist/types --declaration true",
"test": "npm-run-all -p test:jest test:typescript",
"test:jest": "TZ=UTC jest --coverage",
"test.watch": "TZ=UTC jest --watchAll",
"test:typescript": "tsc --noEmit",
"copy:license": "cp ../../LICENSE LICENSE",
"copy:notice": "cp ../../NOTICE NOTICE",
"prepack": "yarn run copy:license && yarn run copy:notice",
"pack": "yarn pack"
"prepack": "npm run copy:license && npm run copy:notice",
"pack": "npm pack"
},
"dependencies": {
"@aws-sdk/client-iotsitewise": "^3.87.0",
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ it('producers can run a finalizer when the last subscriber unsubscribes', (done)
const recorder: SubscriberRecorder<number> = new SubscriberRecorder<number>();

const workerGroup = new RequestProcessorWorkerGroup<string, number>(() => {
let timeoutID: NodeJS.Timer;
let timeoutID: number | NodeJS.Timer;
let counter = 0;
return new Observable<number>((subscriber) => {
timeoutID = setInterval(function incrementer() {
@@ -228,7 +228,7 @@ it('producers can run a finalizer when the last subscriber unsubscribes', (done)
}, 5);
}).pipe(
finalize(() => {
clearInterval(timeoutID);
clearInterval(timeoutID as number);
// the test actually ends here when the timeout is cleared
// if you remove this call to done() the test will hang, timeout and fail
done();
24,382 changes: 0 additions & 24,382 deletions yarn.lock

This file was deleted.

0 comments on commit 8e200be

Please sign in to comment.