Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ocliff version and migrate almost all files to ts #80

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@
"eslint:recommended",
"plugin:prettier/recommended",
"prettier",
"plugin:jest/recommended",
"plugin:jest/style",
"plugin:@typescript-eslint/recommended"
],
"plugins": ["prettier", "@typescript-eslint"],
"settings": {
"jest": {
"version": 26
}
},
"rules": {
"no-return-await": "error",
"unicorn/filename-case": "off",
Expand Down Expand Up @@ -56,6 +49,7 @@
"unicorn/consistent-function-scoping": "off",
"unicorn/prefer-top-level-await": "off",
"no-promise-executor-return": "off",
"node/no-extraneous-require": "off"
"node/no-extraneous-require": "off",
"node/shebang": "off"
}
}
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand All @@ -49,7 +49,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand All @@ -70,7 +70,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand All @@ -91,7 +91,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package-lock.json
.envrc
.env
.greenframe
oclif.manifest.json

.pnp.*
.yarn/*
Expand Down
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.2.3.cjs
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typecheck: ## Typecheck the project
yarn typecheck

build: clean-dist ## Create tarballs of CLI
yarn build && yarn set version classic && npx oclif pack tarballs -t $(BUILD_TARGETS)
yarn oclif pack tarballs -t $(BUILD_TARGETS)
$(MAKE) generate-wsl-cli

generate-wsl-cli: ## Generate WSL version of CLI
Expand All @@ -33,19 +33,19 @@ generate-wsl-cli: ## Generate WSL version of CLI
sed -i 's/linux/wsl/g' ./dist/greenframe-v$(PACKAGE_VERSION)-$(SHORT_HASH)-wsl-x64-buildmanifest

upload: ## Upload tarballs to S3 bucket
npx oclif upload tarballs -t $(DEPLOY_TARGETS)
yarn oclif upload tarballs -t $(DEPLOY_TARGETS)

promote-staging: ## Publish uploaded tarballs on a staging channel
npx oclif promote --version $(PACKAGE_VERSION) --sha $(SHORT_HASH) --channel staging -t $(DEPLOY_TARGETS) && yarn set version stable
yarn oclif promote --version $(PACKAGE_VERSION) --sha $(SHORT_HASH) --channel staging -t $(DEPLOY_TARGETS)

promote-prerelease: ## Publish uploaded tarballs on a prerelease channel
npx oclif promote --version $(PACKAGE_VERSION) --sha $(SHORT_HASH) --channel prerelease -t $(DEPLOY_TARGETS) && yarn set version stable
yarn oclif promote --version $(PACKAGE_VERSION) --sha $(SHORT_HASH) --channel prerelease -t $(DEPLOY_TARGETS)

upload-installation-scripts: ## Publish on the bucket installion bash scripts
yarn upload-installation-scripts

promote-production: upload-installation-scripts ## Publish uploaded tarballs on a stable channel
npx oclif promote --version $(PACKAGE_VERSION) --sha $(SHORT_HASH) -t $(DEPLOY_TARGETS) && yarn set version stable
yarn oclif promote --version $(PACKAGE_VERSION) --sha $(SHORT_HASH) -t $(DEPLOY_TARGETS)

test: test-unit test-e2e ## Launch all tests

Expand Down
119 changes: 86 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ This means that the lowest hanging fruit for optimizing the emissions of a web p

<!-- commands -->
* [`greenframe analyze [BASEURL] [SCENARIO]`](#greenframe-analyze-baseurl-scenario)
* [`greenframe autocomplete [SHELL]`](#greenframe-autocomplete-shell)
* [`greenframe help [COMMAND]`](#greenframe-help-command)
* [`greenframe kube-config`](#greenframe-kube-config)
* [`greenframe open [BASEURL] [SCENARIO]`](#greenframe-open-baseurl-scenario)
* [`greenframe open [BASEURL] [SCENARIOS]`](#greenframe-open-baseurl-scenarios)
* [`greenframe update [CHANNEL]`](#greenframe-update-channel)

## `greenframe analyze [BASEURL] [SCENARIO]`
Expand All @@ -246,32 +248,83 @@ ARGUMENTS
SCENARIO Path to your GreenFrame scenario

FLAGS
-C, --configFile=<value> Path to config file
-E, --envFile=<value> File of environment vars
-K, --kubeConfig=<value> Path to kubernetes client config file
-a, --useAdblock Use an adblocker during analysis
-b, --branchName=<value> Pass branch name manually
-c, --commitMessage=<value> Pass commit message manually
-e, --envVar=<value>... List of environment vars to read in the scenarios
-i, --ignoreHTTPSErrors Ignore HTTPS errors during analysis
-p, --projectName=<value> Project name
-s, --samples=<value> Number of runs done for the score computation
-t, --threshold=<value> Consumption threshold
--commitId=<value> Pass commit id manually
--containers=<value> Pass containers manually
--databaseContainers=<value> Pass database containers manually
--dockerdHost=<value> Docker daemon host
--dockerdPort=<value> Docker daemon port
--kubeContainers=<value> Pass kubebernetes containers manually
--kubeDatabaseContainers=<value> Pass kubebernetes database containers manually
--locale Set greenframe browser locale
--timezoneId Set greenframe browser timezoneId
-C, --configFile=<value> Path to config file
-E, --envFile=<value> File of environment vars
-K, --kubeConfig=<value> Path to kubernetes client config file
-a, --useAdblock Use an adblocker during analysis
-b, --branchName=<value> Pass branch name manually
-c, --commitMessage=<value> Pass commit message manually
-e, --envVar=<value>... List of environment vars to read in the scenarios
-i, --ignoreHTTPSErrors Ignore HTTPS errors during analysis
-p, --projectName=<value> Project name
-s, --samples=<value> Number of runs done for the score computation
-t, --threshold=<value> Consumption threshold
--commitId=<value> Pass commit id manually
--containers=<value> Pass containers manually
--databaseContainers=<value> Pass database containers manually
--dockerdHost=<value> Docker daemon host
--dockerdPort=<value> Docker daemon port
--kubeContainers=<value> Pass kubebernetes containers manually
--kubeDatabaseContainers=<value> Pass kubebernetes database containers manually
--locale Set greenframe browser locale
--timezoneId Set greenframe browser timezoneId

DESCRIPTION
Create an analysis on GreenFrame server.
```

_See code: [dist/commands/analyze.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/analyze.ts)_
_See code: [src/commands/analyze.ts](https://github.com/marmelab/greenframe-cli/blob/v2.0.0/src/commands/analyze.ts)_

## `greenframe autocomplete [SHELL]`

Display autocomplete installation instructions.

```
USAGE
$ greenframe autocomplete [SHELL] [-r]

ARGUMENTS
SHELL (zsh|bash|powershell) Shell type

FLAGS
-r, --refresh-cache Refresh cache (ignores displaying instructions)

DESCRIPTION
Display autocomplete installation instructions.

EXAMPLES
$ greenframe autocomplete

$ greenframe autocomplete bash

$ greenframe autocomplete zsh

$ greenframe autocomplete powershell

$ greenframe autocomplete --refresh-cache
```

_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v3.0.13/src/commands/autocomplete/index.ts)_

## `greenframe help [COMMAND]`

Display help for greenframe.

```
USAGE
$ greenframe help [COMMAND...] [-n]

ARGUMENTS
COMMAND... Command to show help for.

FLAGS
-n, --nested-commands Include all nested commands in the output.

DESCRIPTION
Display help for greenframe.
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.18/src/commands/help.ts)_

## `greenframe kube-config`

Expand All @@ -292,34 +345,34 @@ DESCRIPTION
greenframe kube-config
```

_See code: [dist/commands/kube-config.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/kube-config.ts)_
_See code: [src/commands/kube-config.ts](https://github.com/marmelab/greenframe-cli/blob/v2.0.0/src/commands/kube-config.ts)_

## `greenframe open [BASEURL] [SCENARIO]`
## `greenframe open [BASEURL] [SCENARIOS]`

Open browser to develop your GreenFrame scenario

```
USAGE
$ greenframe open [BASEURL] [SCENARIO] [-C <value>] [-a] [--ignoreHTTPSErrors] [--locale] [--timezoneId]
$ greenframe open [BASEURL] [SCENARIOS] [-C <value>] [-a] [--ignoreHTTPSErrors] [--locale] [--timezoneId]

ARGUMENTS
BASEURL Your baseURL website
SCENARIO Path to your GreenFrame scenario
BASEURL Your baseURL website
SCENARIOS Path to your GreenFrame scenario

FLAGS
-C, --configFile=<value> Path to config file
-a, --useAdblock Use an adblocker during analysis
--ignoreHTTPSErrors Ignore HTTPS errors during analysis
--locale Set greenframe browser locale
--timezoneId Set greenframe browser timezoneId
--ignoreHTTPSErrors Ignore HTTPS errors during analysis
--locale Set greenframe browser locale
--timezoneId Set greenframe browser timezoneId

DESCRIPTION
Open browser to develop your GreenFrame scenario
...
greenframe analyze ./yourScenario.js https://greenframe.io
```

_See code: [dist/commands/open.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/open.ts)_
_See code: [src/commands/open.ts](https://github.com/marmelab/greenframe-cli/blob/v2.0.0/src/commands/open.ts)_

## `greenframe update [CHANNEL]`

Expand All @@ -338,7 +391,7 @@ DESCRIPTION
greenframe update
```

_See code: [dist/commands/update.ts](https://github.com/marmelab/greenframe-cli/blob/v1.7.0/dist/commands/update.ts)_
_See code: [src/commands/update.ts](https://github.com/marmelab/greenframe-cli/blob/v2.0.0/src/commands/update.ts)_
<!-- commandsstop -->

## Development
Expand All @@ -358,7 +411,7 @@ $ yarn build
Then you can run the CLI:

```sh
$ ./bin/run analyze https://greenframe.io ./src/examples/visit.js
$ ./bin/run analyze https://greenframe.io ./src/examples/visit.cjs
```

While developing, instead of running `yarn build` each time you make a change, you can watch for changes and automatically recompile with:
Expand Down
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
5 changes: 5 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning

import { execute } from '@oclif/core';

await execute({ development: true, dir: import.meta.url });
4 changes: 2 additions & 2 deletions bin/run
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

const oclif = require('@oclif/core');
import { execute } from '@oclif/core';

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'));
await execute({ dir: import.meta.url });
5 changes: 5 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import { execute } from '@oclif/core';

await execute({ dir: import.meta.url });
2 changes: 1 addition & 1 deletion e2e/.greenframe.fullstack.broken.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../../src/examples/greenframe.js'
scenario: '../../src/examples/greenframe.cjs'
baseURL: 'https://greenframe.io'
samples: 2
projectName: 'GreenFrame'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.fullstack.k8s.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../src/examples/greenframe.js'
scenario: '../src/examples/greenframe.cjs'
baseURL: 'https://greenframe.io'
samples: 2
projectName: 'GreenFrame'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.fullstack.multiple.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
scenarios:
- path: '../src/examples/greenframe.js'
- path: '../src/examples/greenframe.cjs'
name: 'Scenario 1'
threshold: 0.1
- path: '../src/examples/greenframe2.js'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.fullstack.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../src/examples/greenframe.js'
scenario: '../src/examples/greenframe.cjs'
baseURL: 'https://greenframe.io'
samples: 2
projectName: 'GreenFrame'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.adblock.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../../src/examples/greenframe.js'
scenario: '../../src/examples/greenframe.cjs'
baseURL: 'https://greenframe.io'
samples: 2
projectName: 'GreenFrame'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../../src/examples/marmelab.en.js'
scenario: '../../src/examples/marmelab.en.cjs'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
Expand Down
5 changes: 5 additions & 0 deletions e2e/.greenframe.single.esm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scenario: '../../src/examples/marmelab.mjs'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
useAdblock: true
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.fr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scenario: '../../src/examples/marmelab.fr.js'
scenario: '../../src/examples/marmelab.fr.cjs'
baseURL: 'https://marmelab.com'
samples: 2
projectName: 'Marmelab'
Expand Down
2 changes: 1 addition & 1 deletion e2e/.greenframe.single.multiple.distant.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
scenarios:
- path: '../src/examples/greenframe.js'
- path: '../src/examples/greenframe.cjs'
name: 'Scenario 1'
threshold: 0.1
- path: '../src/examples/greenframe2.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable jest/no-conditional-expect */
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
import { exec as execThen } from 'node:child_process';
import { promisify } from 'node:util';
import { describe, expect, it } from 'vitest';
const exec = promisify(execThen);

const BASE_COMMAND = `GREENFRAME_SECRET_TOKEN=API_TOKEN API_URL=http://localhost:3006 ./bin/run analyze`;

// we need to setup a mock greenframe.io environment to enable this test
// eslint-disable-next-line jest/no-disabled-tests

describe.skip('[GREENFRAME.IO] greenframe analyze', () => {
describe('single page', () => {
describe('local analysis', () => {
Expand Down
Loading
Loading