@financial-times/n-myft-ui 33.1.0 → 33.1.1-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/.circleci/config.yml +98 -179
  2. package/.toolkitrc.yml +31 -0
  3. package/.toolkitstate/ci.json +6 -0
  4. package/README.md +29 -4
  5. package/components/unread-articles-indicator/initialise-feed-start-time.js +1 -1
  6. package/karma.conf.js +1 -0
  7. package/package.json +23 -8
  8. package/scripts/build-demo.sh +53 -0
  9. package/scripts/deploy-gh-pages.sh +5 -2
  10. package/scripts/make-static-demo.sh +6 -2
  11. package/scripts/transpile-jsx.sh +3 -0
  12. package/toolkit/demoScripts/.toolkitrc.yml +0 -0
  13. package/toolkit/demoScripts/index.js +77 -0
  14. package/toolkit/karma/.toolkitrc.yml +0 -0
  15. package/toolkit/karma/index.js +16 -0
  16. package/.circleci/shared-helpers/.github/settings.yml +0 -1
  17. package/.circleci/shared-helpers/CODEOWNERS +0 -3
  18. package/.circleci/shared-helpers/Makefile +0 -5
  19. package/.circleci/shared-helpers/README.md +0 -72
  20. package/.circleci/shared-helpers/helper-check-service-ready +0 -37
  21. package/.circleci/shared-helpers/helper-configure-awscli +0 -20
  22. package/.circleci/shared-helpers/helper-generate-build-state-artifacts +0 -29
  23. package/.circleci/shared-helpers/helper-install-awscli +0 -14
  24. package/.circleci/shared-helpers/helper-install-puppeteer-deps +0 -25
  25. package/.circleci/shared-helpers/helper-npm-install-peer-deps +0 -40
  26. package/.circleci/shared-helpers/helper-npm-store-auth-token +0 -14
  27. package/.circleci/shared-helpers/helper-npm-update +0 -26
  28. package/.circleci/shared-helpers/helper-npm-version-and-publish-public +0 -19
  29. package/.circleci/shared-helpers/helper-publish-github-pages +0 -43
  30. package/.circleci/shared-helpers/helper-setup-heroku-cli +0 -46
  31. package/.circleci/shared-helpers/helper-setup-s3-upload +0 -17
  32. package/.circleci/shared-helpers/helper-upload-assets-to-s3 +0 -69
  33. package/.circleci/shared-helpers/helper.example +0 -13
  34. package/.circleci/shared-helpers/secret-squirrel.js +0 -25
  35. package/Makefile +0 -48
  36. package/build-state/npm-shrinkwrap.json +0 -52417
@@ -1,213 +1,132 @@
1
- # generator: n-circle2-cli
2
- # template: component
3
-
4
- references:
5
- container_config_node: &container_config_node
6
- working_directory: ~/project/build
7
- docker:
8
- - image: cimg/node:<< parameters.node-version >>-browsers
9
- parameters:
10
- node-version:
11
- default: "18.18"
12
- type: string
13
-
14
- workspace_root: &workspace_root ~/project
15
-
16
- attach_workspace: &attach_workspace
17
- attach_workspace:
18
- at: *workspace_root
19
-
20
- npm_cache_keys: &npm_cache_keys
21
- keys:
22
- - v8-dependency-npm-{{ checksum "package-lock.json" }}-
23
- - v8-dependency-npm-{{ checksum "package-lock.json" }}
24
- - v8-dependency-npm-
25
-
26
- cache_npm_cache: &cache_npm_cache
27
- save_cache:
28
- key: v8-dependency-npm-{{ checksum "package-lock.json" }}-{{ epoch }}
29
- paths:
30
- - ./node_modules/
31
-
32
- restore_npm_cache: &restore_npm_cache
33
- restore_cache:
34
- <<: *npm_cache_keys
35
-
36
- filters_ignore_gh_pages: &filters_ignore_gh_pages
37
- branches:
38
- ignore: gh_pages
39
-
40
- filters_only_main: &filters_only_main
41
- branches:
42
- only: main
43
-
44
- filters_ignore_main: &filters_ignore_main
45
- branches:
46
- ignore: main
47
-
48
- filters_ignore_tags: &filters_ignore_tags
49
- tags:
50
- ignore: /.*/
51
-
52
- filters_version_tag: &filters_version_tag
53
- tags:
54
- only:
55
- - /^v?\d+\.\d+\.\d+(?:-beta\.\d+)?$/
56
- branches:
57
- ignore: /.*/
58
-
59
1
  version: 2.1
60
-
61
2
  orbs:
62
- node: circleci/node@4.6.0
63
-
3
+ tool-kit: financial-times/dotcom-tool-kit@5
4
+ executors:
5
+ node:
6
+ docker:
7
+ - image: cimg/node:18.17-browsers
64
8
  jobs:
65
- build:
66
- <<: *container_config_node
67
- steps:
68
- - checkout
69
- - node/install-npm:
70
- version: "^7"
71
- - run:
72
- name: Checkout next-ci-shared-helpers
73
- command: git clone --depth 1
74
- git@github.com:Financial-Times/next-ci-shared-helpers.git --branch
75
- unpin-heroku .circleci/shared-helpers
76
- - *restore_npm_cache
77
- - run:
78
- name: Install project dependencies
79
- command: make install
80
- - run:
81
- name: Transpile JSX to JS
82
- command: make transpile-jsx
83
- - run:
84
- name: shared-helper / generate-build-state-artifacts
85
- command: .circleci/shared-helpers/helper-generate-build-state-artifacts
86
- when: always
87
- - *cache_npm_cache
88
- - store_artifacts:
89
- path: build-state
90
- destination: build-state
91
- - persist_to_workspace:
92
- root: *workspace_root
93
- paths:
94
- - build
95
-
96
- test:
97
- <<: *container_config_node
98
- parallelism: 1
99
- steps:
100
- - *attach_workspace
101
- - run:
102
- name: Run tests
103
- command: make test
104
- environment:
105
- JEST_JUNIT_OUTPUT: test-results/jest/results.xml
106
- MOCHA_FILE: test-results/mocha/results.xml
107
- - store_test_results:
108
- path: test-results
109
- - store_artifacts:
110
- path: test-results
111
- destination: test-results
112
-
113
- publish:
114
- <<: *container_config_node
115
- steps:
116
- - *attach_workspace
117
- - run:
118
- name: shared-helper / npm-store-auth-token
119
- command: .circleci/shared-helpers/helper-npm-store-auth-token
120
- - run: npx snyk monitor --org=customer-products
121
- --project-name=Financial-Times/n-myft-ui
122
- - run:
123
- name: shared-helper / npm-version-and-publish-public
124
- command: .circleci/shared-helpers/helper-npm-version-and-publish-public
125
-
126
- deploy:
127
- <<: *container_config_node
9
+ deploy-gh-pages:
10
+ docker:
11
+ - image: cimg/base:stable
128
12
  steps:
129
- - *attach_workspace
13
+ - tool-kit/attach-workspace
130
14
  - add_ssh_keys:
131
15
  fingerprints:
132
16
  - "83:b5:09:e4:e5:2e:74:35:c1:1b:99:73:e3:dc:b8:6f"
133
17
  - run:
134
18
  name: Publish GitHub Pages
135
19
  command: ./scripts/deploy-gh-pages.sh
136
-
20
+ checkout:
21
+ docker:
22
+ - image: cimg/base:stable
23
+ steps:
24
+ - checkout
25
+ - tool-kit/persist-workspace:
26
+ path: .
137
27
  workflows:
138
- version: 2
139
- build-test-deploy:
28
+ tool-kit:
29
+ when:
30
+ not:
31
+ equal:
32
+ - scheduled_pipeline
33
+ - << pipeline.trigger_source >>
140
34
  jobs:
141
- - build:
35
+ - deploy-gh-pages:
36
+ requires:
37
+ - tool-kit/test-node
142
38
  filters:
143
- <<: *filters_ignore_tags
144
- <<: *filters_ignore_gh_pages
145
- name: build-v<< matrix.node-version >>
146
- matrix:
147
- parameters:
148
- node-version: [ "16.20", "18.18" ]
149
- - test:
39
+ tags:
40
+ only: /^v\d+\.\d+\.\d+(-.+)?/
41
+ branches:
42
+ ignore: /.*/
43
+ - checkout:
150
44
  filters:
151
- <<: *filters_ignore_tags
45
+ tags:
46
+ only: /^v\d+\.\d+\.\d+(-.+)?/
47
+ - waiting-for-approval:
48
+ type: approval
49
+ filters:
50
+ branches:
51
+ only: /(^renovate-.*|^nori/.*)/
52
+ - tool-kit/setup:
53
+ name: tool-kit/setup-<< matrix.executor >>
152
54
  requires:
153
- - build-v<< matrix.node-version >>
154
- name: test-v<< matrix.node-version >>
55
+ - checkout
56
+ - waiting-for-approval
155
57
  matrix:
156
58
  parameters:
157
- node-version: [ "16.20", "18.18" ]
158
- - deploy:
59
+ executor:
60
+ - node
159
61
  filters:
160
- <<: *filters_only_main
62
+ tags:
63
+ only: /^v\d+\.\d+\.\d+(-.+)?/
64
+ - tool-kit/build:
65
+ name: tool-kit/build-<< matrix.executor >>
161
66
  requires:
162
- - build-v18.18
163
- build-test-publish:
164
- jobs:
165
- - build:
166
- filters:
167
- <<: *filters_version_tag
168
- <<: *filters_ignore_gh_pages
169
- name: build-v<< matrix.node-version >>
67
+ - tool-kit/setup-<< matrix.executor >>
170
68
  matrix:
171
69
  parameters:
172
- node-version: [ "16.20", "18.18" ]
173
- - test:
70
+ executor:
71
+ - node
174
72
  filters:
175
- <<: *filters_version_tag
73
+ tags:
74
+ only: /^v\d+\.\d+\.\d+(-.+)?/
75
+ - tool-kit/test:
76
+ name: tool-kit/test-<< matrix.executor >>
176
77
  requires:
177
- - build-v<< matrix.node-version >>
178
- name: test-v<< matrix.node-version >>
78
+ - tool-kit/build-<< matrix.executor >>
179
79
  matrix:
180
80
  parameters:
181
- node-version: [ "16.20", "18.18" ]
182
- - publish:
183
- context: npm-publish-token
81
+ executor:
82
+ - node
184
83
  filters:
185
- <<: *filters_version_tag
84
+ tags:
85
+ only: /^v\d+\.\d+\.\d+(-.+)?/
86
+ - tool-kit/publish-tag:
186
87
  requires:
187
- - test-v18.18
188
-
189
- nightly:
190
- triggers:
191
- - schedule:
192
- cron: "0 0 * * *"
88
+ - deploy-gh-pages
89
+ - tool-kit/test-node
90
+ name: tool-kit/publish-tag-node
91
+ executor: node
193
92
  filters:
194
- <<: *filters_only_main
93
+ tags:
94
+ only: /^v\d+\.\d+\.\d+(-.+)?/
95
+ branches:
96
+ ignore: /.*/
97
+ context: npm-publish-token
98
+ nightly:
99
+ when:
100
+ and:
101
+ - equal:
102
+ - scheduled_pipeline
103
+ - << pipeline.trigger_source >>
104
+ - equal:
105
+ - nightly
106
+ - << pipeline.schedule.name >>
195
107
  jobs:
196
- - build:
197
- context: next-nightly-build
198
- name: build-v<< matrix.node-version >>
108
+ - checkout
109
+ - tool-kit/setup:
110
+ name: tool-kit/setup-<< matrix.executor >>
111
+ requires:
112
+ - checkout
113
+ matrix:
114
+ parameters:
115
+ executor:
116
+ - node
117
+ - tool-kit/build:
118
+ name: tool-kit/build-<< matrix.executor >>
119
+ requires:
120
+ - tool-kit/setup-<< matrix.executor >>
199
121
  matrix:
200
122
  parameters:
201
- node-version: [ "16.20", "18.18" ]
202
- - test:
123
+ executor:
124
+ - node
125
+ - tool-kit/test:
126
+ name: tool-kit/test-<< matrix.executor >>
203
127
  requires:
204
- - build-v<< matrix.node-version >>
205
- context: next-nightly-build
206
- name: test-v<< matrix.node-version >>
128
+ - tool-kit/build-<< matrix.executor >>
207
129
  matrix:
208
130
  parameters:
209
- node-version: [ "16.20", "18.18" ]
210
-
211
- notify:
212
- webhooks:
213
- - url: https://ft-next-webhooks.herokuapp.com/circleci2-workflow
131
+ executor:
132
+ - node
package/.toolkitrc.yml ADDED
@@ -0,0 +1,31 @@
1
+ plugins:
2
+ - "@dotcom-tool-kit/component"
3
+ - "@dotcom-tool-kit/mocha"
4
+ - "@dotcom-tool-kit/eslint"
5
+ - "@dotcom-tool-kit/pa11y"
6
+ - "@dotcom-tool-kit/lint-staged-npm"
7
+ - "./toolkit/karma"
8
+ - "./toolkit/demoScripts"
9
+ hooks:
10
+ build:local:
11
+ - TranspileJsx
12
+ build:ci:
13
+ - TranspileJsx
14
+ build:demo:
15
+ - DemoBuilder
16
+ test:local:
17
+ - Eslint
18
+ - Karma
19
+ test:ci:
20
+ - Karma
21
+ - DemoBuilder
22
+ - RunPa11yCi
23
+ options:
24
+ "@dotcom-tool-kit/circleci":
25
+ nodeVersion: "18.17-browsers"
26
+ "@dotcom-tool-kit/eslint": {
27
+ files: "{,!(public)/**/}*.js"
28
+ }
29
+ '@dotcom-tool-kit/vault':
30
+ team: next
31
+ app: n-myft-ui
@@ -0,0 +1,6 @@
1
+ {
2
+ "branch": "",
3
+ "repo": "n-myft-ui",
4
+ "version": "91ee5ff8640103b67627901115e219f2cf07fc04",
5
+ "tag": "v33.1.1-alpha.4"
6
+ }
package/README.md CHANGED
@@ -32,14 +32,39 @@ If you are making a major change, you will need to update the package.json files
32
32
  ## Running locally
33
33
 
34
34
  ```
35
- make install
36
- make build
37
- make transpile-jsx
38
- make demo
35
+ npm install
36
+ npm run build
37
+ npm run demo
39
38
  ```
40
39
 
41
40
  View the demo on `localhost:5005`
42
41
 
42
+
43
+ ## Demo tasks
44
+ ```
45
+ npm run demo-build
46
+ ```
47
+ This task will build the demo and place it in the `demo/dist` folder.
48
+ ```
49
+ npm run demo
50
+ ```
51
+ This task will run a express server on localhost:5005 serving the builded demo.(it calls demo-build internally).
52
+ ```
53
+ npm run static-demo
54
+ ```
55
+ This tasks will start a Node.js application located in the "demos/app" directory as a background process,
56
+ waits for 10 seconds, fetches content from "http://localhost:5005", adjusts the links in the retrieved content,
57
+ saves it as "index.html" in the "public" directory, moves all files from the "public" directory to the current directory,
58
+ and finally terminates the Node.js process.
59
+ This is to prepare it to be uploaded to gh static page.
60
+
43
61
  ## Unstable versions
44
62
 
45
63
  v24, v25, v26 has JSX migration code. They are not stable therefore v27 is released. It is to remove JSX and rollback to handlebars. Please use ^v27.
64
+
65
+ # RunPa11yCi task
66
+ The default Pa11y plugin is configured to run against a deployed review app on heroku.
67
+ In cases where the project is an npm component without a deployed environment like this project, this task allows for local server setup prior to running Pa11y tests.
68
+ The RunPa11yCi task is a custom task class designed to automate the process of running Pa11y accessibility tests against a local server instance that runs the demo. It utilizes Node.js child processes to manage both the server and Pa11y processes,
69
+ ensuring proper execution and cleanup.
70
+
@@ -31,7 +31,7 @@ const determineFeedStartTime = (userId, now, previousFeedStartTime) => {
31
31
 
32
32
  return fetchUserLastVisitedAt(userId)
33
33
  .then((userLastVisitedAt) =>
34
- isToday(userLastVisitedAt) ? userLastVisitedAt : Promise.reject()
34
+ isToday(userLastVisitedAt) ? userLastVisitedAt : Promise.reject(new Error('No last visited user data today'))
35
35
  )
36
36
  .catch(() => startOfDay(now));
37
37
  };
package/karma.conf.js CHANGED
@@ -39,6 +39,7 @@ module.exports = function (karma) {
39
39
  'test/**/*.spec.js': ['webpack', 'sourcemap']
40
40
  },
41
41
  webpack: {
42
+ mode: 'development',
42
43
  resolve: {
43
44
  modules: ['node_modules'],
44
45
  descriptionFiles: ['package.json'],
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@financial-times/n-myft-ui",
3
- "version": "33.1.0",
3
+ "version": "33.1.1-alpha.4",
4
4
  "description": "Client side component for interaction with myft",
5
5
  "main": "server.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
7
+ "sass": "sass demos/src/demo.scss public/main.css --load-path node_modules",
8
+ "test": "dotcom-tool-kit test:local",
8
9
  "commit": "commit-wizard",
9
- "prepare": "npx snyk protect || npx snyk protect -d || true"
10
+ "prepare": "npx snyk protect || npx snyk protect -d || true",
11
+ "build": "dotcom-tool-kit build:local",
12
+ "start": "dotcom-tool-kit run:local",
13
+ "demo-build": "dotcom-tool-kit build:demo -- demo-build",
14
+ "demo": "dotcom-tool-kit build:demo -- demo",
15
+ "static-demo": "dotcom-tool-kit build:demo -- static-demo",
16
+ "deploy-gh": "dotcom-tool-kit deploy:gh-pages"
10
17
  },
11
18
  "repository": {
12
19
  "type": "git",
@@ -19,13 +26,19 @@
19
26
  },
20
27
  "homepage": "https://github.com/Financial-Times/n-myft-ui#readme",
21
28
  "devDependencies": {
29
+ "@dotcom-tool-kit/component": "^4.1.2",
30
+ "@dotcom-tool-kit/doppler": "^1.1.0",
31
+ "@dotcom-tool-kit/eslint": "^3.2.0",
32
+ "@dotcom-tool-kit/lint-staged-npm": "^3.2.0",
33
+ "@dotcom-tool-kit/mocha": "^3.2.0",
34
+ "@dotcom-tool-kit/pa11y": "^0.5.2",
22
35
  "@financial-times/dotcom-build-base": "^8.2.1",
23
36
  "@financial-times/dotcom-build-code-splitting": "^8.2.1",
24
37
  "@financial-times/dotcom-build-js": "^8.2.1",
25
38
  "@financial-times/dotcom-build-sass": "^8.2.1",
26
39
  "@financial-times/dotcom-server-handlebars": "^8.2.1",
40
+ "@financial-times/eslint-config-next": "^7.1.0",
27
41
  "@financial-times/n-express": "^28.0.3",
28
- "@financial-times/n-gage": "^9.0.1",
29
42
  "ascii-table": "0.0.9",
30
43
  "autoprefixer": "9.7.0",
31
44
  "aws-sdk-mock": "4.5.0",
@@ -47,7 +60,7 @@
47
60
  "check-engine": "^1.12.0",
48
61
  "css-loader": "^0.23.1",
49
62
  "denodeify": "^1.2.1",
50
- "eslint": "6.5.1",
63
+ "dotcom-tool-kit": "^3.4.4",
51
64
  "eslint-plugin-react": "^7.33.2",
52
65
  "extract-css-block-webpack-plugin": "^1.3.0",
53
66
  "fetch-mock": "^5.0.3",
@@ -131,9 +144,11 @@
131
144
  },
132
145
  "husky": {
133
146
  "hooks": {
134
- "commit-msg": "node_modules/.bin/secret-squirrel-commitmsg",
135
- "pre-commit": "node_modules/.bin/secret-squirrel",
136
- "pre-push": "make verify -j3"
147
+ "commit-msg": "dotcom-tool-kit git:commitmsg",
148
+ "pre-commit": "dotcom-tool-kit git:precommit"
137
149
  }
150
+ },
151
+ "lint-staged": {
152
+ "**/*.js": "dotcom-tool-kit format:staged test:staged --"
138
153
  }
139
154
  }
@@ -0,0 +1,53 @@
1
+ #!/bin/bash
2
+
3
+ chmod +x $0
4
+
5
+ # Define the demo-build function
6
+ demo-build() {
7
+ # Remove existing directory
8
+ rm -rf node_modules/@financial-times/n-myft-ui
9
+ # Create necessary directories
10
+ mkdir -p node_modules/@financial-times/n-myft-ui/myft
11
+ # Copy components to the corresponding directory
12
+ cp -r components node_modules/@financial-times/n-myft-ui/components/
13
+ # Compile SCSS file to CSS
14
+ sass demos/src/demo.scss public/main.css --load-path node_modules
15
+ # Indicate that build is complete
16
+ echo "Demo build completed."
17
+ }
18
+
19
+ # Define the demo function
20
+ demo() {
21
+ # Build the demo
22
+ demo-build
23
+ # Run the Node.js application
24
+ node demos/app
25
+ }
26
+
27
+ # Define the static-demo function
28
+ static-demo() {
29
+ # Build the demo
30
+ demo-build
31
+ # Execute the shell script to generate the static demo
32
+ scripts/make-static-demo.sh
33
+ }
34
+
35
+ # Check the first argument passed to the script
36
+ case "$1" in
37
+ demo-build)
38
+ demo-build
39
+ ;;
40
+ demo)
41
+ demo
42
+ ;;
43
+ static-demo)
44
+ static-demo
45
+ ;;
46
+ *)
47
+ # If the argument does not match any of the above options, display an error message
48
+ echo "Usage: $0 {demo-build|demo|static-demo}"
49
+ exit 1
50
+ ;;
51
+ esac
52
+
53
+ exit 0
@@ -1,13 +1,16 @@
1
1
  git config --global user.email "$GITHUB_EMAIL"
2
2
  git config --global user.name "$GITHUB_NAME"
3
3
 
4
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5
+ echo "script dir: $SCRIPT_DIR"
6
+
4
7
  # hackily remove all identities, and later force the specific identity
5
8
  # otherwise git keeps using the wrong boi
6
9
  ssh-add -D
7
10
 
8
11
  git --version
9
12
 
10
- export GIT_SSH="`pwd`/scripts/ssh.sh"
13
+ export GIT_SSH="$SCRIPT_DIR/ssh.sh"
11
14
 
12
15
  git clone $CIRCLE_REPOSITORY_URL honk --single-branch
13
16
 
@@ -18,7 +21,7 @@ git checkout -b gh-pages
18
21
  mv ../node_modules .
19
22
  cp ../scripts/* scripts/
20
23
 
21
- make static-demo
24
+ ./make-static-demo.sh
22
25
 
23
26
  git add -A .
24
27
 
@@ -1,6 +1,10 @@
1
1
  #!/bin/sh
2
2
 
3
- node demos/app &
3
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4
+ PUBLIC_DIR="$SCRIPT_DIR/../public"
5
+
6
+
7
+ node "$SCRIPT_DIR/../demos/app" &
4
8
 
5
9
  pid="$!"
6
10
 
@@ -8,6 +12,6 @@ sleep 10
8
12
 
9
13
  curl http://localhost:5005 | sed 's#/public/main.css#main.css#' | sed 's#href="/"#href="index.html"#' > public/index.html
10
14
 
11
- mv public/* .
15
+ mv "$PUBLIC_DIR"/* .
12
16
 
13
17
  kill $pid
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ chmod +x "$0"
3
+ npx cross-env BABEL_ENV=custom babel components/jsx --out-dir dist --extensions .jsx
File without changes
@@ -0,0 +1,77 @@
1
+ const { Task, Hook } = require('@dotcom-tool-kit/types');
2
+ const { spawn } = require('child_process');
3
+ const { hookFork, waitOnExit } = require('@dotcom-tool-kit/logger');
4
+
5
+ class ShExcutor extends Task {
6
+ async executeCommand (command, scriptPath, args = []) {
7
+ if (!command) {
8
+ throw new Error('Invalid command');
9
+ }
10
+
11
+ this.logger.info(`running sh script: ${command}`);
12
+ const deployChild = spawn(scriptPath, args, { shell: true });
13
+ hookFork(this.logger, command, deployChild);
14
+ return waitOnExit(command, deployChild);
15
+ }
16
+ }
17
+
18
+ class DemoBuilder extends ShExcutor {
19
+ async run () {
20
+ let command = process.argv[4];
21
+ if (!['demo-build', 'demo', 'static-demo'].includes(command)) {
22
+ command = 'demo-build';
23
+ }
24
+
25
+ return this.executeCommand(`build-demo: ${command}`, 'scripts/build-demo.sh', [command]);
26
+ }
27
+ }
28
+
29
+ class TranspileJsx extends ShExcutor {
30
+ async run () {
31
+ return this.executeCommand('transpile-jsx', 'scripts/transpile-jsx.sh');
32
+ }
33
+ }
34
+
35
+ class RunPa11yCi extends Task {
36
+ async run () {
37
+ let serverProcess;
38
+
39
+ const serverStartedPromise = new Promise((resolve, reject) => {
40
+ serverProcess = spawn('node', ['demos/app.js']);
41
+ hookFork(this.logger, 'server', serverProcess);
42
+
43
+ serverProcess.stdout.on('data', data => {
44
+ const message = data.toString();
45
+ if (message.includes('event: "EXPRESS_START"')) {
46
+ this.logger.info('Server started successfully.');
47
+ resolve();
48
+ }
49
+ });
50
+
51
+ serverProcess.on('error', error => {
52
+ reject(error);
53
+ });
54
+ });
55
+
56
+ await serverStartedPromise;
57
+
58
+ const pa11yProcess = spawn('pa11y-ci', ['--config', '.pa11yci.js']);
59
+ hookFork(this.logger, 'pa11y', pa11yProcess);
60
+
61
+ await waitOnExit('pa11y', pa11yProcess);
62
+
63
+ serverProcess.kill('SIGINT');
64
+ this.logger.info('Server and related processes stopped.');
65
+ }
66
+ }
67
+ class buildDemo extends Hook {
68
+ async check () {
69
+ return true;
70
+ }
71
+ }
72
+
73
+ exports.hooks = {
74
+ 'build:demo': buildDemo,
75
+ };
76
+
77
+ exports.tasks = [ DemoBuilder, TranspileJsx, RunPa11yCi ];
File without changes
@@ -0,0 +1,16 @@
1
+ const { Task } = require('@dotcom-tool-kit/types');
2
+ const { spawn } = require('child_process');
3
+ const { hookFork, waitOnExit } = require('@dotcom-tool-kit/logger');
4
+ const karmaCLIPath = require.resolve('karma/bin/karma');
5
+
6
+ class Karma extends Task {
7
+ async run () {
8
+ const args = ['start', 'karma.conf.js'];
9
+ this.logger.info(`running karma ${args.join(' ')}`);
10
+ const child = spawn(karmaCLIPath, args);
11
+ hookFork(this.logger, 'karma', child);
12
+ return waitOnExit('karma', child);
13
+ }
14
+ }
15
+
16
+ exports.tasks = [ Karma ];