Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hanakla committed Mar 16, 2022
1 parent 4147021 commit 725121b
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 223 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
sudo systemctl restart ssh
ssh localhost "uname"
# - name: Testing @fluer/lys
# run: |
# cd packages/lys
# yarn test --coverage --verbose
- name: Testing rowen
run: |
cd packages/testings
yarn test
# build-lint:
# strategy:
Expand Down
151 changes: 0 additions & 151 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,154 +50,3 @@ An SSH deployment script kit, inspired by shipit.
await rowen.fetch();
await rowen.deploy();
```

## Presets

### presets.releases

Manage releases presets, likes `shipit-deploy`.

#### Usage

```ts
// rowen.config.ts
import { presets } from "rowen";

export default rowenConfig(() => {
return {
// ... options
flows: async (rowen) => {
rowen.on.caughtError(releases.caughtError());

rowen.on.beforeFetch(
releases.beforeFetch({
sourceDir: "./",
keepReleases: 2,
})
);

rowen.on.buildStep(async ($) => {
// building scripts write your own
});

rowen.on.syncStep(releases.syncStep());
},
};
});
```

#### Options on `releases.beforeFetch`

- _`sourceDir: string`_ Default `"."`. Copying directory path on local
- _`keepReleases: number`_ Default `10`. Number of past releases to keep on remote
- _`releasesPath: string`_ Default `"./releases"`. Directory path where all releases are located
- _`enableShared: boolean`_ Default `true`. If enabled, creates a `shared` directory to place files shared between releases

#### Remote directory structure

`presets.releases` makes directory structure likes below on remotes.

```
- deployToDir/
- releases/
- [releaseId]
- shared/
```

## More details

### Rowen context

If deploy context/status you want, it can be get via `$.ctx` method.

```ts
rowenConfig(async () => {
return {
// ...options,
flows: (rowen) => {
rowen.on.beforeFetch(async ($) => {
const context = $.ctx(Rowen.ctx);
const releaseContext = $.ctx(presets.releases.ctx);
});
},
};
});
```

### Extend Rowen

Rowen can be extend by your own, supports custom events and contexts.

#### Custom events example

```ts
// rowen.config.ts
import { externalTask } from "./external-task.ts";}

export default rowenConfig(() => {
return {
// ...options,
flows: async rowen => {
rowen.on.beforeFetch(async ($) => {
// emit events
await rowen.emit("startDeploy", $, arg2);

const exteranlCtx = $.ctx(externalTask.ctx);
console.log(externalCtx); // => { status: "sokosoko fine" }
});

rowen.on.startDeploy(($, arg2) => {
// startDeploy events
});
}
}
})

//

declare module "@hanakla/rowen" {
export interface ExtendedRowenEvents {
startDeploy: [PilotLight, Arg2];
}
```
#### Custom context example
```ts
// externalTask.ts

const ctx = Symbol();
export const externalTask = {
// Expose context key as unique symbol
ctx: ctx as typeof ctx,
beforeFetch: ($: PilotLight, arg2: Arg2) => {
$.ctx.set(externalTask.ctx, { status: "sokosoko fine" });
},
};

declare module "@hanakla/rowen" {
export interface ExtendedRowenContexts {
[externalTask.ctx]: { status: string };
}
}
```
```ts
// rowen.config.ts
import { externalTask } from "./externalTask.ts";

export default rowenConfig(() => {
return {
// ...options,
flows: async (rowen) => {
rowen.on.beforeFetch(externalTask.beforeFetch);

rowen.on.beforeFetch(async ($) => {
// Get context by `externalTask.ctx`
const exteranlCtx = $.ctx(externalTask.ctx);
console.log(externalCtx); // => { status: "sokosoko fine" }
});
},
};
});
```
77 changes: 77 additions & 0 deletions docs/extending.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Extend Rowen

Rowen can be extend by your own, supports custom events and contexts.

## Custom events example

```ts
// rowen.config.ts
import { externalTask } from "./external-task.ts";}

export default rowenConfig(() => {
return {
// ...options,
flows: async rowen => {
rowen.on.beforeFetch(async ($) => {
// emit events
await rowen.emit("startDeploy", $, arg2);

const exteranlCtx = $.ctx(externalTask.ctx);
console.log(externalCtx); // => { status: "sokosoko fine" }
});

rowen.on.startDeploy(($, arg2) => {
// startDeploy events
});
}
}
})

//

declare module "@hanakla/rowen" {
export interface ExtendedRowenEvents {
startDeploy: [PilotLight, Arg2];
}
```
## Custom context example
```ts
// externalTask.ts

const ctx = Symbol();
export const externalTask = {
// Expose context key as unique symbol
ctx: ctx as typeof ctx,
beforeFetch: ($: PilotLight, arg2: Arg2) => {
$.ctx.set(externalTask.ctx, { status: "sokosoko fine" });
},
};

declare module "@hanakla/rowen" {
export interface ExtendedRowenContexts {
[externalTask.ctx]: { status: string };
}
}
```
```ts
// rowen.config.ts
import { externalTask } from "./externalTask.ts";

export default rowenConfig(() => {
return {
// ...options,
flows: async (rowen) => {
rowen.on.beforeFetch(externalTask.beforeFetch);

rowen.on.beforeFetch(async ($) => {
// Get context by `externalTask.ctx`
const exteranlCtx = $.ctx(externalTask.ctx);
console.log(externalCtx); // => { status: "sokosoko fine" }
});
},
};
});
```
17 changes: 17 additions & 0 deletions docs/get-contexts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### How to get deployment context / options

If deploy context/status you want, it can be get via `$.ctx` method.

```ts
rowenConfig(async () => {
return {
// ...options,
flows: (rowen) => {
rowen.on.beforeFetch(async ($) => {
const context = $.ctx(Rowen.ctx);
const releaseContext = $.ctx(presets.releases.ctx);
});
},
};
});
```
6 changes: 6 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Rowen docs

- [How to get deployment context / options](./get-contexts.md)
- [Presets](./presets.md)
- [Scripting to remotes](./scripting-to-remotes.md)
- [Extending rowen](./extending.md)
52 changes: 52 additions & 0 deletions docs/presets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Presets

## `presets.releases`

Manage releases presets, likes `shipit-deploy`.

### Usage

```ts
// rowen.config.ts
import { presets } from "rowen";

export default rowenConfig(() => {
return {
// ... options
flows: async (rowen) => {
rowen.on.caughtError(releases.caughtError());

rowen.on.beforeFetch(
releases.beforeFetch({
sourceDir: "./",
keepReleases: 2,
})
);

rowen.on.buildStep(async ($) => {
// building scripts write your own
});

rowen.on.syncStep(releases.syncStep());
},
};
});
```

### Options on `releases.beforeFetch`

- _`sourceDir: string`_ Default `"."`. Copying directory path on local
- _`keepReleases: number`_ Default `10`. Number of past releases to keep on remote
- _`releasesPath: string`_ Default `"./releases"`. Directory path where all releases are located
- _`enableShared: boolean`_ Default `true`. If enabled, creates a `shared` directory to place files shared between releases

### Remote directory structure

`presets.releases` makes directory structure likes below on remotes.

```
- deployToDir/
- releases/
- [releaseId]
- shared/
```
9 changes: 9 additions & 0 deletions docs/scripting-to-remotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Scripting to remotes

```ts
import Rowen from "rowen";

Rowen.script({ env: "staging", verbose: true }, ($) => {
$.remote`hostname`;
});
```
2 changes: 1 addition & 1 deletion pkgs/example/rowen.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import { presets, rowenConfig } from "@hanakla/rowen";

export default rowenConfig((): Promise<RowenConfig> => {
export default rowenConfig(async (): Promise<RowenConfig> => {
return {
default: {
deployTo: "/home/hanakla/rowen-test",
Expand Down
Loading

0 comments on commit 725121b

Please sign in to comment.