-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bitovi/mvp
[FE-145] MVP
- Loading branch information
Showing
46 changed files
with
18,461 additions
and
1,014 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ignores: | ||
- "@types/*" | ||
- "@oclif/plugin-*" | ||
- ts-node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module.exports = { | ||
root: true, | ||
extends: "@bitovi/eslint-config/node", | ||
ignorePatterns: ["dist"], | ||
rules: { | ||
"@typescript-eslint/consistent-type-imports": [ | ||
"error", | ||
{ | ||
prefer: "no-type-imports", | ||
fixStyle: "inline-type-imports", | ||
}, | ||
], | ||
"import/order": [ | ||
"error", | ||
{ | ||
"newlines-between": "always", | ||
alphabetize: { | ||
order: "asc", | ||
caseInsensitive: true, | ||
}, | ||
groups: [ | ||
"builtin", | ||
"external", | ||
"internal", | ||
"parent", | ||
"sibling", | ||
"index", | ||
], | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Example - Basic React | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
verify: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./examples/basic-react | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ".nvmrc" | ||
|
||
- name: Build core | ||
working-directory: ./ | ||
run: | | ||
npm ci | ||
npm run build | ||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Typecheck | ||
run: npm run typecheck | ||
- name: ESLint | ||
run: npm run eslint | ||
- name: Prettier | ||
run: npm run prettier | ||
- name: depcheck | ||
run: npm run depcheck | ||
|
||
# - name: Test | ||
# run: npm run test | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
# Can't do this since we don't have a real account to test against | ||
# - name: Sync OptimizelyAsCode | ||
# # A real project should only sync when publishing | ||
# # if: github.event_name == 'workflow_dispatch' | ||
# env: | ||
# OPTIMIZELY_ACCESS_TOKEN: my-optimizely-access-token | ||
# OPTIMIZELY_PROJECT_ID: my-optimizely-project-id | ||
# run: npm run optimizely-as-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
name: Verify and Publish | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
inputs: | ||
segment: | ||
description: "The version segment to increment: major, minor, patch, or prerelease." | ||
required: true | ||
preId: | ||
description: 'Appended to the prerelease segment. (default: "")' | ||
|
||
jobs: | ||
verify: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ".nvmrc" | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Typecheck | ||
run: npm run typecheck | ||
- name: ESLint | ||
run: npm run eslint | ||
- name: Prettier | ||
run: npm run prettier | ||
- name: depcheck | ||
run: npm run depcheck | ||
|
||
# - name: Test | ||
# run: npm run test | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Upload publish artifacts | ||
if: github.event_name == 'workflow_dispatch' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: publish | ||
path: | | ||
/dist | ||
/oclif.manifest.json | ||
publish: | ||
if: github.event_name == 'workflow_dispatch' | ||
needs: verify | ||
|
||
concurrency: | ||
group: "publish" | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ".nvmrc" | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Download publish artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: my-artifact | ||
|
||
- name: Determine Tag | ||
id: tag | ||
shell: bash | ||
run: | | ||
if [[ ${{ github.event.inputs.segment }} == pre* ]]; then | ||
echo "tag=next" >> $GITHUB_OUTPUT | ||
else | ||
echo "tag=latest" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Increment Version | ||
shell: bash | ||
run: | | ||
git config --local user.email "Workflow: ${{ github.workflow }}[bot]" | ||
git config --local user.name "${{ github.workflow }}[bot]@workflow" | ||
if [[ ${{ github.event.inputs.segment }} == pre* ]]; then | ||
if [[ -n "${{ github.event.inputs.preId }}" ]]; then | ||
PREID_CMD="--preid ${{ github.event.inputs.preId }}" | ||
fi | ||
fi | ||
npm version ${{ github.event.inputs.segment }} $PREID_CMD | ||
VERSION="$(cat package.json | jq -r '.version')" | ||
echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
git commit --all --message "Publish ${{ github.workflow }} v$VERSION" | ||
git tag "v$VERSION" | ||
- name: Push Tag | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ github.ref }} | ||
tags: true | ||
|
||
- name: Publish to NPM Registry | ||
uses: JS-DevTools/npm-publish@v2 | ||
with: | ||
token: ${{ secrets.NPM_TOKEN }} | ||
access: public | ||
tag: ${{ steps.tag.outputs.tag }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
# Environment | ||
/.env | ||
/.env.* | ||
!/.env.example | ||
|
||
# Artifacts | ||
/node_modules/ | ||
/dist/ | ||
/oclif.manifest.json | ||
|
||
# Cache and Logs | ||
npm-debug.* | ||
*.tsbuildinfo | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"semi": false, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,81 @@ | ||
# optimizely-as-code | ||
optimizely-as-code | ||
================== | ||
|
||
optimizely-as-code | ||
|
||
<!-- toc --> | ||
* [Configuring your project](#configuring-your-project) | ||
* [Usage in React](#usage-in-react) | ||
* [CLI Commands](#cli-commands) | ||
<!-- tocstop --> | ||
|
||
# Configuring your project | ||
|
||
```shell | ||
npm install optimizely-as-code | ||
``` | ||
|
||
Add to `package.json` | ||
```json | ||
{ | ||
"scripts": { | ||
"optimizely-as-code": "optimizely-as-code sync", | ||
}, | ||
} | ||
``` | ||
|
||
Create `optimizely-as-code/features.json`. | ||
|
||
Create `optimizely-as-code/events.json`. | ||
|
||
Create `optimizely-as-code/experiments.json`. | ||
|
||
# Usage in React | ||
|
||
```jsx | ||
import { createInstance, OACProvider, useDecision } from "optimizely-as-code/react" | ||
|
||
const optimizelyClient = createInstance({ | ||
sdkKey: "<your-optimizely-sdk-key>", | ||
}) | ||
|
||
const App: React.FC = () => { | ||
return ( | ||
<OACProvider optimizely={optimizelyClient} user={{ id: "<unique-user-id>" }}> | ||
<Child /> | ||
</OACProvider> | ||
) | ||
} | ||
|
||
const Child: React.FC = () => { | ||
const [foobar] = useDecision("foobar") | ||
|
||
return ( | ||
<div> | ||
<p>hello {foobar.enabled ? "foo" : "bar"}</p> | ||
</div> | ||
) | ||
} | ||
``` | ||
|
||
# CLI Commands | ||
|
||
<!-- commands --> | ||
* [`optimizely-as-code sync`](#optimizely-as-code-sync) | ||
|
||
## `optimizely-as-code sync` | ||
|
||
Push local features to Optimizely. | ||
|
||
``` | ||
USAGE | ||
$ optimizely-as-code sync --accessToken <value> --projectId <value> [--dry-run] | ||
FLAGS | ||
--accessToken=<value> (required) Your Optimizely access token. Can also be provided via the environment variable | ||
OPTIMIZELY_ACCESS_TOKEN. | ||
--dry-run Output what changes would be made without actually making the changes. | ||
--projectId=<value> (required) Your Optimizely Project Id. Can also be provided via the environment variable | ||
OPTIMIZELY_PROJECT_ID. | ||
``` | ||
<!-- commandsstop --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env -S node --loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning | ||
|
||
import { execute } from "@oclif/core" | ||
|
||
await execute({ dir: import.meta.url, development: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\run" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ignores: | ||
- "@types/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_OPTIMIZELY_SDK_KEY=your-optimizely-sdk-key |
Oops, something went wrong.