Skip to content

Commit

Permalink
feat: changes and updates (#5)
Browse files Browse the repository at this point in the history
* feat: changes and updates

* fix: sublime-cli version workflows

* chore: update sublime-cli to fix manifest bug

* feat: bootGlobals function and build options changes

* feat: test changeset snapshot build

* chore: updating changeset messages for snapshot

* fix: changeset yarn prefix

* fix: changeset versions

* feat: reconfigure actions

* feat: changeset config updates

* chore: changeset

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
miguelramos and github-actions[bot] authored Sep 22, 2022
1 parent f0ee7da commit aa0ce9a
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 95 deletions.
6 changes: 4 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
"ignore": [],
"useCalculatedVersion": true,
"prereleaseTemplate": "{commit}-{tag}"
}
8 changes: 8 additions & 0 deletions .changeset/nasty-zebras-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@websublime/ws-essential': minor
'@websublime/ws-globals': minor
---

Globals

Globals are two essential store links Environment and Registry. Environment to provide config/options and registry for particular components data.
4 changes: 2 additions & 2 deletions .github/workflows/artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
env:
NODE_ENV: "production"
run: |
wget https://github.com/websublime/sublime-cli/releases/download/v0.1.6/sublime-v0.1.6-linux-amd64.tar.gz
tar -xf sublime-v0.1.6-linux-amd64.tar.gz sublime
wget https://github.com/websublime/sublime-cli/releases/download/v0.1.8/sublime-v0.1.8-linux-amd64.tar.gz
tar -xf sublime-v0.1.8-linux-amd64.tar.gz sublime
chmod +x sublime
./sublime action --type tag --env "$NODE_ENV"
14 changes: 1 addition & 13 deletions .github/workflows/feature.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Deploy Feature artifacts
name: Build Features

on:
push:
Expand Down Expand Up @@ -33,15 +33,3 @@ jobs:

- name: Build
run: yarn build

- name: Test echo
run: |
git --no-pager diff --name-only origin/main HEAD
git rev-list --objects --all --count
- name: Artifacts
run: |
wget https://github.com/websublime/sublime-cli/releases/download/v0.1.6/sublime-v0.1.6-linux-amd64.tar.gz
tar -xf sublime-v0.1.6-linux-amd64.tar.gz sublime
chmod +x sublime
./sublime action --type branch --env "$NODE_ENV"
63 changes: 63 additions & 0 deletions .github/workflows/snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and Create Snapshots

on:
push:
branches:
- 'releases/snapshots'

env:
CI: true
NODE_ENV: "develop"

jobs:
feat-artifacts:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'

- name: Install dependencies
run: yarn

- name: Build
run: yarn build

- name: Artifacts
run: |
wget https://github.com/websublime/sublime-cli/releases/download/v0.1.8/sublime-v0.1.8-linux-amd64.tar.gz
tar -xf sublime-v0.1.8-linux-amd64.tar.gz sublime
chmod +x sublime
./sublime action --type branch --env "$NODE_ENV"
rm -rf sublime-v0.1.8-linux-amd64.tar.gz
rm -rf sublime
- name: Setup CI Git User
run: |
git config --global user.name "miguelramos"
git config --global user.email "[email protected]"
cat << EOF > "$HOME/.npmrc"
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN
@websublime:registry=https://npm.pkg.github.com
EOF
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Create Snapshot
uses: changesets/action@v1
with:
version: yarn changeset version --snapshot SNAPSHOT
publish: yarn changeset publish --no-git-tag --snapshot
title: "chore(snapshot): Packages snapshots"
commit: "chore(snapshot): releasing snapshot preview"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.GH_TOKEN }}
2 changes: 1 addition & 1 deletion packages/ws-essential/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

### Minor Changes

- [#1](https://github.com/websublime/sublime-sdk/pull/1) [`1a4e884`](https://github.com/websublime/sublime-sdk/commit/1a4e884656bdee9d8afe6819dbd3de2e3b535acb) Thanks [@miguelramos](https://github.com/miguelramos)! - Essential store with dispatchers and subscribers
- [#1](https://github.com/websublime/sublime-sdk/pull/1) [`1a4e884`](https://github.com/websublime/sublime-sdk/commit/1a4e884656bdee9d8afe6819dbd3de2e3b535acb) Thanks [@miguelramos](https://github.com/miguelramos)! - Essential store with dispatchers and subscribers
11 changes: 8 additions & 3 deletions packages/ws-essential/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import path from 'node:path';

import replace from '@rollup/plugin-replace';
import { workspacesAlias } from '@websublime/vite';
//import { workspacesAlias } from '@websublime/vite';
import postcss from 'rollup-plugin-postcss';
import { defineConfig } from 'vite';

import { version } from './package.json';

module.exports = defineConfig({
esbuild: {
minifyIdentifiers: false,
minifyWhitespace: true,
minifySyntax: true
},
define: {
Version: JSON.stringify(version),
global: 'globalThis',
Expand Down Expand Up @@ -61,8 +66,8 @@ module.exports = defineConfig({
}),
postcss({
inject: false
}),
workspacesAlias(['../../'], ['vite'])
})
//workspacesAlias(['../../'], ['vite'])
],
optimizeDeps: {
include: ['@reduxjs/toolkit', 'redux']
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-globals/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

### Minor Changes

- [#3](https://github.com/websublime/sublime-sdk/pull/3) [`4469fe9`](https://github.com/websublime/sublime-sdk/commit/4469fe94ae97a40105fb3e913e630a731876056f) Thanks [@miguelramos](https://github.com/miguelramos)! - Globals and links registry creation
- [#3](https://github.com/websublime/sublime-sdk/pull/3) [`4469fe9`](https://github.com/websublime/sublime-sdk/commit/4469fe94ae97a40105fb3e913e630a731876056f) Thanks [@miguelramos](https://github.com/miguelramos)! - Globals and links registry creation
66 changes: 11 additions & 55 deletions packages/ws-globals/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Globals

Essential is a redux toolkit for window or node. Essential as a diferent approach to use redux, the concept is OOP.
Globals create and initiate essential redux, register environement on store and creates a registry for packages/components.

# Table of contents

Expand All @@ -11,69 +11,25 @@ Essential is a redux toolkit for window or node. Essential as a diferent approac

# Usage

The concept is to create a "Link" that will operate your redux actions/reducers. Every entry on the root state is connected to this link and the link instance is the responsable to produce changes on that slice state. Let's go by example. Let's took an example of publish messages. Let's create the Link first:
Two main entries are added to the essential store: Environment and Registry. The links IDS are:

```
import { PayloadAction, EssentialLink } from '@websublime/ws-essential';
const BarLinkID = { key: Symbol('NAMESPACE-MESSAGES') };
type BarState = { message: string };
type BarDispatchers = {
publish: (payload: string) => void;
};
class BarLink extends EssentialLink<BarState> {
get initialState() {
return { message: '' };
}
protected definedActions() {
return {
publish: this.publish
};
}
private publish(state: BarState, action: PayloadAction<string>) {
state.message = action.payload;
}
}
Environment: EnvironmentLinkID
Registry: RegistryLinkID
```

Every link should have a unique and singleton id as seen on ```BarLinkID```, this will be used to identify your link, also your entry on root state redux. Also we type the state of our link and the dispatchers that will be public available. The ```get initialState()``` getter defines your initail/default state. Mutations to state are only allowed inside the reducer. The ```definedActions``` method is an hook where you should define your actions mapping the internal method that will be used as reducer/trigger. Like we see it on the above class, example:
They are export on package to be consumed as npm if you need to subscribe. Environment is initiated and search on global scope (window) for the entries in window.environment.

```
protected definedActions() {
return {
publish: this.publish
```ts
interface Window {
environment: {
apiUrl: string;
env: string;
};
}
private publish(state: BarState, action) {
state.message = action.payload;
}
```

It means, action ```publish``` will be created and the reducer ```this.publish``` will be used to change state. Also the typing ```<string>``` in action means that ```action.payload``` will be string type. Now our Link class is ready to be part of the store.

```
import { useStore, PayloadAction } from '@websublime/ws-essential';
const store = useStore();
store.addLink(new BarLink(BarLinkID));
store.subscribe(BarLinkID, (state: BarState, action: PayloadAction<string>) => {
console.log(state.message);
});
const dispacther = store.getDispatchers<BarDispatchers>(BarLinkID);
dispacther.publish('Hello World');
```

The ```store``` is a empty redux store, ready to accept links on it. Add your new slice state to the store by adding a link like: ```store.addLink(new BarLink(BarLinkID))```, now you can subscribe to changes that happen on that namespace and also get the dispatchers to make changes on the namespace state.

Provide this values if you want or defaults will be used.


[(Back to top)](#table-of-contents)
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-globals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@websublime/vite": "0.0.1",
"@websublime/ws-essential": "^0.2.0",
"@websublime/ws-essential": "0.2.0",
"@microsoft/api-documenter": "^7.17.15",
"@microsoft/api-extractor": "^7.24.1",
"@types/jest": "^27.0.1",
Expand Down
28 changes: 26 additions & 2 deletions packages/ws-globals/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,44 @@
*/
import { EssentialLink, PayloadAction } from '@websublime/ws-essential';

import { version } from './version';

/**
* Environment link ID
* @public
*/
export const EnvironmentLinkID = { key: Symbol('environment') };

type EnvironmentLinkState = {
env: string;
api: string | undefined;
version: string;
};

/**
* Environment dispatchers
* @public
*/
export type EnvironmentDispatchers = {
setApiUrl: (value: string) => void;
setEnvironment: (value: string) => void;
setOption: <AnyValue = Record<string, unknown>>(value: AnyValue) => void;
};

export class EnvironmentLink extends EssentialLink<EnvironmentLinkState> {
get initialState() {
return {
api: undefined,
env: 'production'
env: 'production',
version
};
}

protected definedActions() {
return {
setApiUrl: this.setApiUrl,
setEnvironment: this.setEnvironment
setEnvironment: this.setEnvironment,
setOption: this.setOption
};
}

Expand All @@ -46,4 +60,14 @@ export class EnvironmentLink extends EssentialLink<EnvironmentLinkState> {
) {
state.api = action.payload;
}

private setOption(
state: EnvironmentLinkState,
payload: PayloadAction<Record<string, unknown>>
) {
state = {
...state,
...payload
};
}
}
25 changes: 13 additions & 12 deletions packages/ws-globals/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ import {
} from './environment';
import { RegistryLink, RegistryLinkID } from './registry';

type Environment = {
apiUrl: string;
env: string;
};

declare global {
interface Window {
environment: {
apiUrl: string;
env: string;
};
}
var environment: Environment;
}

const initializeEnvironment = () => {
const initializeEnvironment = (environment: Environment) => {
// eslint-disable-next-line unicorn/prevent-abbreviations
const { apiUrl, env = 'production' } = window.environment || {};
const { apiUrl, env = 'production' } = {
...global.environment,
...environment
};

const store = useStore({
devTools: env !== 'production'
Expand All @@ -45,13 +48,11 @@ const initializeRegistry = () => {
store.addLink(new RegistryLink(RegistryLinkID));
};

const boot = () => {
initializeEnvironment();
export const bootGlobals = (environment: Environment = {} as Environment) => {
initializeEnvironment(environment);
initializeRegistry();
};

boot();

export { RegistryLinkID } from './registry';
export { EnvironmentLinkID } from './environment';

Expand Down
8 changes: 8 additions & 0 deletions packages/ws-globals/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
import { EssentialLink, PayloadAction } from '@websublime/ws-essential';

/**
* Registry link ID
* @public
*/
export const RegistryLinkID = { key: Symbol('registry') };

type RegistryLinkState = {
Expand All @@ -14,6 +18,10 @@ type RegistryLinkState = {
};
};

/**
* Registry dispatchers
* @public
*/
export type RegistryDispatchers = {
add: (value: Record<string, { id: string }>) => void;
};
Expand Down
Loading

0 comments on commit aa0ce9a

Please sign in to comment.