Skip to content

Commit

Permalink
Merge pull request #25 from pipelinit/refactor/separation-of-core-and…
Browse files Browse the repository at this point in the history
…-cli

Split the project into core and cli
  • Loading branch information
oesgalha committed Sep 6, 2021
2 parents eb40a48 + 0c9ce4c commit 897ce95
Show file tree
Hide file tree
Showing 74 changed files with 410 additions and 180 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cov_profile
app.bundle.js
bin/*
!bin/.gitkeep
cli/bin/*
!cli/bin/.gitkeep
core/dist/*
!core/dist/.gitkeep
42 changes: 3 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,6 @@ Pipelinit is built with Deno. To develop, test or build the project, make sure
you have Deno installed. You can check how to install it
[in the official Deno website](https://deno.land/#installation)

### Manual testing

To quickly test the tool in your local environment, install it as a script. In
this project root run:

```
deno install \
--unstable \
--allow-read=. \
--allow-write=. \
pipelinit.ts
```

When you update the code in the repository, just run "pipelinit" again in the
target project to start the CLI with the latest changes.

### Automated testing

To run the project automated tests use:
Expand All @@ -288,27 +272,7 @@ deno coverage cov_profile
| ⚠️ | Clear the content from cov_profile between each test run. Otherwise your coverage data may be incorrect. |
| -- | -------------------------------------------------------------------------------------------------------- |

### Compiling

To generate compiled executables for Linux, Windows, and macOS, run the
following command:

```
deno run --unstable --allow-read --allow-write --allow-net --allow-env --allow-run build.ts
```

This creates one executable per target with the following name pattern:

```
pipelinit-<VERSION>-<TARGET>
```

And the correspondent compressed file:

- .tar.gz for Linux and macOS
- .zip for Widnows

It also generates one executable named just "pipelinit", that uses the native
target (the computer where you ran the build).
### Building

The build script puts those files in the "bin" directory.
For details on how to build the @pipelinit/core package or how to compile the
CLI executable, refer to the README in their respective directories.
51 changes: 51 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Pipelinit CLI

Here is the code for the Pipelinit CLI, to learn more about the project, read
the [README in the project root](../README.md).

## Developmenting and contributing

Pipelinit is built with Deno. To develop, test or build the project, make sure
you have Deno installed. You can check how to install it
[in the official Deno website](https://deno.land/#installation)

### Manual testing

To quickly test the tool in your local environment, install it as a script. In
this project root run:

```
deno install \
--unstable \
--allow-read=. \
--allow-write=. \
pipelinit.ts
```

When you update the code in the repository, just run "pipelinit" again in the
target project to start the CLI with the latest changes.

### Compiling

To generate compiled executables for Linux, Windows, and macOS, run the
following command:

```
deno run --unstable --allow-read --allow-write --allow-net --allow-env --allow-run build.ts
```

This creates one executable per target with the following name pattern:

```
pipelinit-<VERSION>-<TARGET>
```

And the correspondent compressed file:

- .tar.gz for Linux and macOS
- .zip for Widnows

It also generates one executable named just "pipelinit", that uses the native
target (the computer where you ran the build).

The build script puts those files in the "bin" directory.
File renamed without changes.
2 changes: 1 addition & 1 deletion buckets.ts → cli/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
buckets: [
{
name: "templates",
folder: "templates",
folder: "../core/templates",
},
],
output: "app.bundle.js",
Expand Down
14 changes: 8 additions & 6 deletions build.ts → cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { bundle } from "https://deno.land/x/buckets@0.1.0/mod.ts";
import * as esbuild from "https://deno.land/x/esbuild@v0.12.19/mod.js";

import conf from "./buckets.ts";
import { VERSION } from "./src/version.ts";
import { PIPELINIT_VERSION } from "./deps.ts";

const TARGETS = [
"x86_64-unknown-linux-gnu",
Expand Down Expand Up @@ -33,7 +33,7 @@ const compile = async function (target?: string) {
"--target",
target,
"--output",
`bin/pipelinit-${VERSION}-${target}`,
`bin/pipelinit-${PIPELINIT_VERSION}-${target}`,
);
} else {
cmd.push("--output", "bin/pipelinit");
Expand All @@ -53,8 +53,8 @@ const tar = async function (target: string) {
cmd: [
"tar",
"-czf",
`pipelinit-${VERSION}-${target}.tar.gz`,
`pipelinit-${VERSION}-${target}`,
`pipelinit-${PIPELINIT_VERSION}-${target}.tar.gz`,
`pipelinit-${PIPELINIT_VERSION}-${target}`,
],
});

Expand All @@ -70,8 +70,8 @@ const zip = async function (target: string) {
cmd: [
"zip",
"-9",
`pipelinit-${VERSION}-${target}.zip`,
`pipelinit-${VERSION}-${target}.exe`,
`pipelinit-${PIPELINIT_VERSION}-${target}.zip`,
`pipelinit-${PIPELINIT_VERSION}-${target}.exe`,
],
});

Expand All @@ -94,3 +94,5 @@ for (const target of TARGETS) {
await compile(target);
await compress(target);
}

await Deno.remove(conf.output);
4 changes: 3 additions & 1 deletion deps.ts → cli/deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// @/core
export * from "../core/mod.ts";

// std
export {
ensureFile,
Expand All @@ -7,7 +10,6 @@ export {
export { assertEquals } from "https://deno.land/std@0.106.0/testing/asserts.ts";
export { readLines } from "https://deno.land/std@0.106.0/io/mod.ts";
export { join, parse } from "https://deno.land/std@0.106.0/path/mod.ts";
export type { WalkEntry } from "https://deno.land/std@0.106.0/fs/mod.ts";
export * as log from "https://deno.land/std@0.106.0/log/mod.ts";
export {
parse as parseToml,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pipelinit.ts → cli/pipelinit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Command } from "./deps.ts";
import { VERSION } from "./src/version.ts";
import { PIPELINIT_VERSION } from "./deps.ts";
import defaultCommand from "./src/cli/commands/default.ts";

export const PIPELINIT_ROOT = new URL(".", import.meta.url).pathname;

await new Command()
.name("pipelinit")
.version(VERSION)
.version(PIPELINIT_VERSION)
.description("Bootstrap and manage CI pipelines")
.option(
"-d, --debug [debug:boolean]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { platformWriters } from "../../../plugins/platforms/mod.ts";
import { ensureFile, platformWriters } from "../../../deps.ts";

import { GlobalOptions } from "../types.ts";
import { prelude } from "../prelude/mod.ts";
import { introspect } from "../../stack/mod.ts";
import { renderTemplates } from "../../template/mod.ts";
import { prelude } from "../prelude/mod.ts";
import { GlobalOptions } from "../types.ts";
import { outputErrors } from "../../plugin/errors.ts";
import { context } from "../../plugin/mod.ts";
import { ensureFile } from "../../../deps.ts";

import { errorCodes } from "../errors.ts";
import { config } from "../../config/mod.ts";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { colors, log } from "../../../deps.ts";
import { introspectors } from "../../../plugins/mod.ts";
import { introspectors } from "../../../../core/plugins/mod.ts";

/**
* Behaves like the ConsoleHandler, but doesn't change the
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 1 addition & 6 deletions src/plugin/errors.ts → cli/src/plugin/errors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { log } from "../../deps.ts";

interface IntrospectionError {
title: string;
message: string;
}
import { IntrospectionError, log } from "../../deps.ts";

/**
* Holds a list of fatal errors for stack introspection
Expand Down
27 changes: 24 additions & 3 deletions src/plugin/files.ts → cli/src/plugin/files.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expandGlob, fileExists, parseToml, WalkEntry } from "../../deps.ts";
export { readLines } from "../../deps.ts";
import {
expandGlob,
FileEntry,
fileExists,
parseToml,
readLines as stdReadLines,
} from "../../deps.ts";

/**
* Search for the .gitignore file and if it exists use the content
Expand Down Expand Up @@ -38,7 +43,7 @@ export async function includes(glob: string): Promise<boolean> {
*
* Return only files, not directories
*/
export async function* each(glob: string): AsyncIterableIterator<WalkEntry> {
export async function* each(glob: string): AsyncIterableIterator<FileEntry> {
for await (
const file of expandGlob(glob, { exclude: await loadGitignoreExcludes() })
) {
Expand Down Expand Up @@ -67,3 +72,19 @@ export async function readToml(path: string) {
export async function readJSON(path: string) {
return JSON.parse(await Deno.readTextFile(path));
}

/**
* Yields each line of a text file
*/
export async function* readLines(path: string): AsyncIterableIterator<string> {
const fileReader = await Deno.open(path);
for await (const line of stdReadLines(fileReader)) {
yield line;
}
fileReader.close();
return;
}

export async function readText(path: string): Promise<string> {
return await Deno.readTextFile(path);
}
28 changes: 28 additions & 0 deletions cli/src/plugin/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Context, log, PIPELINIT_VERSION, semver } from "../../deps.ts";
import {
each,
includes,
readJSON,
readLines,
readText,
readToml,
} from "./files.ts";
import { errors } from "./errors.ts";

export const context: Context = {
getLogger: log.getLogger,
files: {
each,
includes,
readJSON,
readLines,
readText,
readToml,
},
errors: {
add: errors.add,
},
semver,
suggestDefault: true,
version: PIPELINIT_VERSION,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { log } from "../../deps.ts";
import { introspectors, log, ProjectData } from "../../deps.ts";
import { context } from "../plugin/mod.ts";
import { introspectors, ProjectData } from "../../plugins/stack/mod.ts";

export type Stack = Record<string, ProjectData>;

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions src/template/mod.ts → cli/src/template/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { eta, join, loadBuckets, parse } from "../../deps.ts";
import { RenderedTemplate } from "../platform/plugin.ts";
import { eta, join, loadBuckets, parse, RenderedTemplate } from "../../deps.ts";
import { Stack } from "../stack/mod.ts";
import bucketsConf from "../../buckets.ts";

Expand Down
16 changes: 16 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @pipelinit/core

Stack detection and CI configuration writing from pipelinit

## Developmenting and contributing

### Publishing

To prepare this library to publish at npm, run
```
deno run \
--unstable \
--allow-read \
--allow-write \
--allow-run package.ts
```
6 changes: 6 additions & 0 deletions core/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// std
export { assertEquals } from "https://deno.land/std@0.106.0/testing/asserts.ts";
export { deepMerge } from "https://deno.land/std@0.104.0/collections/mod.ts";

// x/semver
export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts";
Empty file added core/dist/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions core/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./types.ts";
export * from "./version.ts";
export * from "./plugins/mod.ts";
export * from "./templates/mod.ts";
18 changes: 18 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipelinit/core",
"version": "0.1.0-rc.3",
"description": "Stack detection and CI configuration writing from pipelinit",
"exports": "./dist/mod.js",
"types": "./dist/mod.d.ts",
"repository": "https://github.com/pipelinit/pipelinit-cli",
"author": "Pipelinit Developers",
"license": "MIT",
"type": "module",
"private": false,
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"files": [
"dist"
]
}

0 comments on commit 897ce95

Please sign in to comment.