Skip to content

Commit

Permalink
Merge pull request #2 from bitovi/mvp
Browse files Browse the repository at this point in the history
[FE-145] MVP
  • Loading branch information
christopherjbaker authored Jun 25, 2024
2 parents 32c2456 + 8aff8af commit fe8b12f
Show file tree
Hide file tree
Showing 46 changed files with 18,461 additions and 1,014 deletions.
4 changes: 4 additions & 0 deletions .depcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ignores:
- "@types/*"
- "@oclif/plugin-*"
- ts-node
32 changes: 32 additions & 0 deletions .eslintrc.cjs
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",
],
},
],
},
}
53 changes: 53 additions & 0 deletions .github/workflows/example-basic-react.yml
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
122 changes: 122 additions & 0 deletions .github/workflows/verify-and-publish.yml
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 }}
36 changes: 14 additions & 22 deletions .gitignore
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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/README.md
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"trailingComma": "all"
}
81 changes: 80 additions & 1 deletion README.md
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 -->
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/transpile-only --no-warnings=ExperimentalWarning

import { execute } from "@oclif/core"

await execute({ dir: import.meta.url, development: true })
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
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: 2 additions & 0 deletions examples/basic-react/.depcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignores:
- "@types/*"
1 change: 1 addition & 0 deletions examples/basic-react/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_OPTIMIZELY_SDK_KEY=your-optimizely-sdk-key
Loading

0 comments on commit fe8b12f

Please sign in to comment.