pepr 0.1.41 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +3 -2
- package/dist/src/cli/index.js +2 -4
- package/dist/src/cli/init/templates/data.json +1 -0
- package/dist/src/cli/init/templates/pepr.code-snippets.json +21 -0
- package/dist/src/cli/init/templates/prettierrc.json +13 -0
- package/dist/src/cli/init/templates/samples.json +45 -0
- package/dist/src/cli/init/templates.d.ts +31 -24
- package/dist/src/cli/init/templates.js +35 -228
- package/hack/build-template-data.js +23 -0
- package/package.json +3 -2
- package/tsconfig.build.json +2 -2
package/dist/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=18.0.0"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.1.
|
|
12
|
+
"version": "0.1.42",
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
15
|
"pepr": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"
|
|
27
|
+
"prebuild": "rm -fr dist/* && node hack/build-template-data.js",
|
|
28
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
29
|
"test": "npm run build && ava && node dist/cli.js -V",
|
|
29
30
|
"lint": "npx eslint src",
|
|
30
31
|
"lint:fix": "npm run lint -- --fix",
|
package/dist/src/cli/index.js
CHANGED
|
@@ -8,12 +8,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
const package_json_1 = require("../../package.json");
|
|
9
9
|
const banner_1 = require("./banner");
|
|
10
10
|
const build_1 = __importDefault(require("./build"));
|
|
11
|
-
const capability_1 = __importDefault(require("./capability"));
|
|
12
11
|
const deploy_1 = __importDefault(require("./deploy"));
|
|
13
12
|
const dev_1 = __importDefault(require("./dev"));
|
|
14
13
|
const init_1 = __importDefault(require("./init"));
|
|
15
14
|
const root_1 = require("./root");
|
|
16
|
-
const test_1 = __importDefault(require("./test"));
|
|
17
15
|
const program = new root_1.RootCmd();
|
|
18
16
|
program
|
|
19
17
|
.version(package_json_1.version)
|
|
@@ -29,6 +27,6 @@ program
|
|
|
29
27
|
(0, deploy_1.default)(program);
|
|
30
28
|
(0, dev_1.default)(program);
|
|
31
29
|
// @todo: finish/re-evaluate these commands
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// test(program);
|
|
31
|
+
// capability(program);
|
|
34
32
|
program.parse();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "gitignore": "# Ignore node_modules and Pepr build artifacts\nnode_modules\ndist\ninsecure*\n", "readme": "# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a Kubernetes tranformation system\nwritten in Typescript.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from \"./capabilities/hello-pepr\";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n├── package.json\n├── pepr.ts\n└── capabilities\n ├── example-one.ts\n ├── example-three.ts\n └── example-two.ts\n```\n", "peprTS": "import { PeprModule } from \"pepr\";\nimport { HelloPepr } from \"./capabilities/hello-pepr\";\nimport cfg from \"./package.json\";\n\n/**\n * This is the main entrypoint for the Pepr module. It is the file that is run when the module is started.\n * This is where you register your configurations and capabilities with the module.\n */\nnew PeprModule(cfg, [\n // \"HelloPepr\" is a demo capability that is included with Pepr. You can remove it if you want.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n", "helloPeprTS": "import { Capability, a } from \"pepr\";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you can run `pepr dev` or `npm start` and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: \"hello-pepr\",\n description: \"A simple example capability to show how things work.\",\n namespaces: [\"pepr-demo\"],\n});\n\n// Use the 'When' function to create a new Capability Action\nconst { When } = HelloPepr;\n\n/**\n * This is a single Capability Action. They can be in the same file or imported from other files.\n * In this exmaple, when a ConfigMap is created with the name `example-1`, we add a label and annotation.\n *\n * Equivelant to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName(\"example-1\")\n .Then(request => {\n request.SetLabel(\"pepr\", \"was-here\").SetAnnotation(\"pepr.dev\", \"annotations-work-too\");\n });\n\n/**\n * This Capabiility Action does the exact same changes for example-2, except this time it uses the `.ThenSet()` feature.\n * You can stack multiple `.Then()` calls, but only a single `.ThenSet()`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName(\"example-2\")\n .ThenSet({\n metadata: {\n labels: {\n pepr: \"was-here\",\n },\n annotations: {\n \"pepr.dev\": \"annotations-work-too\",\n },\n },\n });\n\n/**\n * This Capability Action combines different styles. Unlike the previous actions, this one will look for any ConfigMap\n * in the `pepr-demo` namespace that has the label `change=by-label` during either CREATE or UPDATE. Note that all\n * conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`, are ANDs so all conditions must be true\n * for the request to be procssed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel(\"change\", \"by-label\")\n .Then(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s reuest\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data[\"username\"] = username;\n cm.data[\"uid\"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation(\"pepr.dev\", \"making-waves\");\n });\n" }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Create a new Pepr capability": {
|
|
3
|
+
"prefix": "create pepr capability",
|
|
4
|
+
"body": [
|
|
5
|
+
"import { Capability, a } from 'pepr';",
|
|
6
|
+
"",
|
|
7
|
+
"export const ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/} = new Capability({",
|
|
8
|
+
"\tname: '${TM_FILENAME_BASE}',",
|
|
9
|
+
"\tdescription: '${1:A brief description of this capability.}',",
|
|
10
|
+
"\tnamespaces: [${2:}],",
|
|
11
|
+
"});",
|
|
12
|
+
"",
|
|
13
|
+
"// Use the 'When' function to create a new Capability Action",
|
|
14
|
+
"const { When } = ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/};",
|
|
15
|
+
"",
|
|
16
|
+
"// When(a.<Kind>).Is<Event>().Then(change => change.<changes>",
|
|
17
|
+
"When(${3:})"
|
|
18
|
+
],
|
|
19
|
+
"description": "Creates a new Pepr capability with a specified description, and optional namespaces, and adds a When statement for the specified value."
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"arrowParens": "avoid",
|
|
3
|
+
"bracketSameLine": false,
|
|
4
|
+
"bracketSpacing": true,
|
|
5
|
+
"embeddedLanguageFormatting": "auto",
|
|
6
|
+
"insertPragma": false,
|
|
7
|
+
"printWidth": 80,
|
|
8
|
+
"quoteProps": "as-needed",
|
|
9
|
+
"requirePragma": false,
|
|
10
|
+
"semi": true,
|
|
11
|
+
"tabWidth": 2,
|
|
12
|
+
"useTabs": false
|
|
13
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"apiVersion": "v1",
|
|
4
|
+
"kind": "Namespace",
|
|
5
|
+
"metadata": {
|
|
6
|
+
"name": "pepr-demo"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"apiVersion": "v1",
|
|
11
|
+
"kind": "ConfigMap",
|
|
12
|
+
"metadata": {
|
|
13
|
+
"name": "example-1",
|
|
14
|
+
"namespace": "pepr-demo"
|
|
15
|
+
},
|
|
16
|
+
"data": {
|
|
17
|
+
"key": "ex-1-val"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"apiVersion": "v1",
|
|
22
|
+
"kind": "ConfigMap",
|
|
23
|
+
"metadata": {
|
|
24
|
+
"name": "example-2",
|
|
25
|
+
"namespace": "pepr-demo"
|
|
26
|
+
},
|
|
27
|
+
"data": {
|
|
28
|
+
"key": "ex-2-val"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"apiVersion": "v1",
|
|
33
|
+
"kind": "ConfigMap",
|
|
34
|
+
"metadata": {
|
|
35
|
+
"name": "example-3",
|
|
36
|
+
"namespace": "pepr-demo",
|
|
37
|
+
"labels": {
|
|
38
|
+
"change": "by-label"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"data": {
|
|
42
|
+
"key": "ex-3-val"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { InitOptions } from "./walkthrough";
|
|
2
|
-
export declare function genPeprTS(): {
|
|
3
|
-
path: string;
|
|
4
|
-
data: string;
|
|
5
|
-
};
|
|
6
2
|
export declare function genPkgJSON(opts: InitOptions): {
|
|
7
3
|
data: {
|
|
8
4
|
name: string;
|
|
@@ -20,6 +16,7 @@ export declare function genPkgJSON(opts: InitOptions): {
|
|
|
20
16
|
};
|
|
21
17
|
};
|
|
22
18
|
scripts: {
|
|
19
|
+
"k3d-setup": string;
|
|
23
20
|
build: string;
|
|
24
21
|
start: string;
|
|
25
22
|
};
|
|
@@ -33,6 +30,36 @@ export declare function genPkgJSON(opts: InitOptions): {
|
|
|
33
30
|
path: string;
|
|
34
31
|
print: string;
|
|
35
32
|
};
|
|
33
|
+
export declare function genPeprTS(): {
|
|
34
|
+
path: string;
|
|
35
|
+
data: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const readme: {
|
|
38
|
+
path: string;
|
|
39
|
+
data: string;
|
|
40
|
+
};
|
|
41
|
+
export declare const helloPeprTS: {
|
|
42
|
+
path: string;
|
|
43
|
+
data: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const gitIgnore: {
|
|
46
|
+
path: string;
|
|
47
|
+
data: string;
|
|
48
|
+
};
|
|
49
|
+
export declare const samplesYaml: {
|
|
50
|
+
path: string;
|
|
51
|
+
data: string;
|
|
52
|
+
};
|
|
53
|
+
export declare const snippet: {
|
|
54
|
+
path: string;
|
|
55
|
+
data: {
|
|
56
|
+
"Create a new Pepr capability": {
|
|
57
|
+
prefix: string;
|
|
58
|
+
body: string[];
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
36
63
|
export declare const tsConfig: {
|
|
37
64
|
path: string;
|
|
38
65
|
data: {
|
|
@@ -48,10 +75,6 @@ export declare const tsConfig: {
|
|
|
48
75
|
include: string[];
|
|
49
76
|
};
|
|
50
77
|
};
|
|
51
|
-
export declare const gitIgnore: {
|
|
52
|
-
path: string;
|
|
53
|
-
data: string;
|
|
54
|
-
};
|
|
55
78
|
export declare const prettierRC: {
|
|
56
79
|
path: string;
|
|
57
80
|
data: {
|
|
@@ -68,19 +91,3 @@ export declare const prettierRC: {
|
|
|
68
91
|
useTabs: boolean;
|
|
69
92
|
};
|
|
70
93
|
};
|
|
71
|
-
export declare const readme: {
|
|
72
|
-
path: string;
|
|
73
|
-
data: string;
|
|
74
|
-
};
|
|
75
|
-
export declare const samplesYaml: {
|
|
76
|
-
path: string;
|
|
77
|
-
data: string;
|
|
78
|
-
};
|
|
79
|
-
export declare const helloPeprTS: {
|
|
80
|
-
path: string;
|
|
81
|
-
data: string;
|
|
82
|
-
};
|
|
83
|
-
export declare const snippet: {
|
|
84
|
-
path: string;
|
|
85
|
-
data: string;
|
|
86
|
-
};
|
|
@@ -1,34 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
4
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
8
|
+
exports.prettierRC = exports.tsConfig = exports.snippet = exports.samplesYaml = exports.gitIgnore = exports.helloPeprTS = exports.readme = exports.genPeprTS = exports.genPkgJSON = void 0;
|
|
6
9
|
const client_node_1 = require("@kubernetes/client-node");
|
|
7
10
|
const util_1 = require("util");
|
|
8
11
|
const uuid_1 = require("uuid");
|
|
9
12
|
const package_json_1 = require("../../../package.json");
|
|
13
|
+
const data_json_1 = __importDefault(require("./templates/data.json"));
|
|
14
|
+
const pepr_code_snippets_json_1 = __importDefault(require("./templates/pepr.code-snippets.json"));
|
|
15
|
+
const prettierrc_json_1 = __importDefault(require("./templates/prettierrc.json"));
|
|
16
|
+
const samples_json_1 = __importDefault(require("./templates/samples.json"));
|
|
17
|
+
const tsconfig_json_1 = __importDefault(require("./templates/tsconfig.json"));
|
|
10
18
|
const utils_1 = require("./utils");
|
|
11
|
-
function genPeprTS() {
|
|
12
|
-
return {
|
|
13
|
-
path: "pepr.ts",
|
|
14
|
-
data: `import { PeprModule } from "pepr";
|
|
15
|
-
import cfg from "./package.json";
|
|
16
|
-
import { HelloPepr } from "./capabilities/hello-pepr";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* This is the main entrypoint for the Pepr module. It is the file that is run when the module is started.
|
|
20
|
-
* This is where you register your configurations and capabilities with the module.
|
|
21
|
-
*/
|
|
22
|
-
new PeprModule(cfg, [
|
|
23
|
-
// "HelloPepr" is a demo capability that is included with Pepr. You can remove it if you want.
|
|
24
|
-
HelloPepr,
|
|
25
|
-
|
|
26
|
-
// Your additional capabilities go here
|
|
27
|
-
]);
|
|
28
|
-
`,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.genPeprTS = genPeprTS;
|
|
32
19
|
function genPkgJSON(opts) {
|
|
33
20
|
// Generate a random UUID for the module based on the module name
|
|
34
21
|
const uuid = (0, uuid_1.v5)(opts.name, (0, uuid_1.v4)());
|
|
@@ -52,6 +39,7 @@ function genPkgJSON(opts) {
|
|
|
52
39
|
},
|
|
53
40
|
},
|
|
54
41
|
scripts: {
|
|
42
|
+
"k3d-setup": package_json_1.scripts["e2e-dev-setup"],
|
|
55
43
|
build: "pepr build",
|
|
56
44
|
start: "pepr dev",
|
|
57
45
|
},
|
|
@@ -69,219 +57,38 @@ function genPkgJSON(opts) {
|
|
|
69
57
|
};
|
|
70
58
|
}
|
|
71
59
|
exports.genPkgJSON = genPkgJSON;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
function genPeprTS() {
|
|
61
|
+
return {
|
|
62
|
+
path: "pepr.ts",
|
|
63
|
+
data: data_json_1.default.peprTS,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.genPeprTS = genPeprTS;
|
|
67
|
+
exports.readme = {
|
|
68
|
+
path: "README.md",
|
|
69
|
+
data: data_json_1.default.readme,
|
|
70
|
+
};
|
|
71
|
+
exports.helloPeprTS = {
|
|
72
|
+
path: "hello-pepr.ts",
|
|
73
|
+
data: data_json_1.default.helloPeprTS,
|
|
86
74
|
};
|
|
87
75
|
exports.gitIgnore = {
|
|
88
76
|
path: ".gitignore",
|
|
89
|
-
data:
|
|
90
|
-
node_modules
|
|
91
|
-
dist
|
|
92
|
-
insecure*
|
|
93
|
-
`,
|
|
94
|
-
};
|
|
95
|
-
exports.prettierRC = {
|
|
96
|
-
path: ".prettierrc",
|
|
97
|
-
data: {
|
|
98
|
-
arrowParens: "avoid",
|
|
99
|
-
bracketSameLine: false,
|
|
100
|
-
bracketSpacing: true,
|
|
101
|
-
embeddedLanguageFormatting: "auto",
|
|
102
|
-
insertPragma: false,
|
|
103
|
-
printWidth: 80,
|
|
104
|
-
quoteProps: "as-needed",
|
|
105
|
-
requirePragma: false,
|
|
106
|
-
semi: true,
|
|
107
|
-
tabWidth: 2,
|
|
108
|
-
useTabs: false,
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
exports.readme = {
|
|
112
|
-
path: "README.md",
|
|
113
|
-
data: `# Pepr Module
|
|
114
|
-
|
|
115
|
-
This is a Pepr module. It is a module that can be used with the [Pepr]() framework.
|
|
116
|
-
|
|
117
|
-
The \`capabilities\` directory contains all the capabilities for this module. By default,
|
|
118
|
-
a capability is a single typescript file in the format of \`capability-name.ts\` that is
|
|
119
|
-
imported in the root \`pepr.ts\` file as \`import { HelloPepr } from "./capabilities/hello-pepr";\`.
|
|
120
|
-
Because this is typescript, you can organize this however you choose, e.g. creating a sub-folder
|
|
121
|
-
per-capability or common logic in shared files or folders.
|
|
122
|
-
|
|
123
|
-
Example Structure:
|
|
124
|
-
|
|
125
|
-
\`\`\`
|
|
126
|
-
Module Root
|
|
127
|
-
├── package.json
|
|
128
|
-
├── pepr.ts
|
|
129
|
-
└── capabilities
|
|
130
|
-
├── example-one.ts
|
|
131
|
-
├── example-three.ts
|
|
132
|
-
└── example-two.ts
|
|
133
|
-
\`\`\`
|
|
134
|
-
`,
|
|
77
|
+
data: data_json_1.default.gitignore,
|
|
135
78
|
};
|
|
136
79
|
exports.samplesYaml = {
|
|
137
80
|
path: "hello-pepr.samples.yaml",
|
|
138
|
-
data:
|
|
139
|
-
{
|
|
140
|
-
apiVersion: "v1",
|
|
141
|
-
kind: "Namespace",
|
|
142
|
-
metadata: {
|
|
143
|
-
name: "pepr-demo",
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
apiVersion: "v1",
|
|
148
|
-
kind: "ConfigMap",
|
|
149
|
-
metadata: {
|
|
150
|
-
name: "example-1",
|
|
151
|
-
namespace: "pepr-demo",
|
|
152
|
-
},
|
|
153
|
-
data: {
|
|
154
|
-
key: "ex-1-val",
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
apiVersion: "v1",
|
|
159
|
-
kind: "ConfigMap",
|
|
160
|
-
metadata: {
|
|
161
|
-
name: "example-2",
|
|
162
|
-
namespace: "pepr-demo",
|
|
163
|
-
},
|
|
164
|
-
data: {
|
|
165
|
-
key: "ex-2-val",
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
apiVersion: "v1",
|
|
170
|
-
kind: "ConfigMap",
|
|
171
|
-
metadata: {
|
|
172
|
-
name: "example-3",
|
|
173
|
-
namespace: "pepr-demo",
|
|
174
|
-
labels: {
|
|
175
|
-
change: "by-label",
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
data: {
|
|
179
|
-
key: "ex-3-val",
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
]
|
|
183
|
-
.map(r => (0, client_node_1.dumpYaml)(r, { noRefs: true }))
|
|
184
|
-
.join("---\n"),
|
|
185
|
-
};
|
|
186
|
-
exports.helloPeprTS = {
|
|
187
|
-
path: "hello-pepr.ts",
|
|
188
|
-
data: `import { Capability, a } from "pepr";
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* The HelloPepr is an example capability to demonstrate some general concepts of Pepr.
|
|
192
|
-
* To test this capability you can run \`pepr dev\` and then run the following command:
|
|
193
|
-
* \`kubectl apply -f capabilities/hello-pepr.samples.yaml\`
|
|
194
|
-
*/
|
|
195
|
-
export const HelloPepr = new Capability({
|
|
196
|
-
name: "hello-pepr",
|
|
197
|
-
description: "A simple example capability to show how things work.",
|
|
198
|
-
namespaces: ["pepr-demo"],
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Use the 'When' function to create a new Capability Action
|
|
202
|
-
const { When } = HelloPepr;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* This is a single Capability Action. They can be in the same file or put imported from other files.
|
|
206
|
-
* In this exmaple, when a ConfigMap is created with the name \`example-1\`, then add a label and annotation.
|
|
207
|
-
*
|
|
208
|
-
* Equivelant to manually running:
|
|
209
|
-
* \`kubectl label configmap example-1 pepr=was-here\`
|
|
210
|
-
* \`kubectl annotate configmap example-1 pepr.dev=annotations-work-too\`
|
|
211
|
-
*/
|
|
212
|
-
When(a.ConfigMap)
|
|
213
|
-
.IsCreated()
|
|
214
|
-
.WithName("example-1")
|
|
215
|
-
.Then(request =>
|
|
216
|
-
request
|
|
217
|
-
.SetLabel("pepr", "was-here")
|
|
218
|
-
.SetAnnotation("pepr.dev", "annotations-work-too")
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* This Capabiility Action does the exact same changes for example-2, except this time it uses the \`.ThenSet()\` feature.
|
|
223
|
-
* You can stack multiple \`.Then()\` calls, but only a single \`.ThenSet()\`
|
|
224
|
-
*/
|
|
225
|
-
When(a.ConfigMap)
|
|
226
|
-
.IsCreated()
|
|
227
|
-
.WithName("example-2")
|
|
228
|
-
.ThenSet({
|
|
229
|
-
metadata: {
|
|
230
|
-
labels: {
|
|
231
|
-
pepr: "was-here",
|
|
232
|
-
},
|
|
233
|
-
annotations: {
|
|
234
|
-
"pepr.dev": "annotations-work-too",
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* This Capability Action combines different styles. Unlike the previous actions, this one will look for any ConfigMap
|
|
241
|
-
* in the \`pepr-demo\` namespace that has the label \`change=by-label\` during either CREATE or UPDATE. Note that all
|
|
242
|
-
* conditions added such as \`WithName()\`, \`WithLabel()\`, \`InNamespace()\`, are ANDs so all conditions must be true
|
|
243
|
-
* for the request to be procssed.
|
|
244
|
-
*/
|
|
245
|
-
When(a.ConfigMap)
|
|
246
|
-
.IsCreatedOrUpdated()
|
|
247
|
-
.WithLabel("change", "by-label")
|
|
248
|
-
.Then(request => {
|
|
249
|
-
// The K8s object e are going to mutate
|
|
250
|
-
const cm = request.Raw;
|
|
251
|
-
|
|
252
|
-
// Get the username and uid of the K8s reuest
|
|
253
|
-
const { username, uid } = request.Request.userInfo;
|
|
254
|
-
|
|
255
|
-
// Store some data about the request in the configmap
|
|
256
|
-
cm.data["username"] = username;
|
|
257
|
-
cm.data["uid"] = uid;
|
|
258
|
-
|
|
259
|
-
// You can still mix other ways of making changes too
|
|
260
|
-
request.SetAnnotation("pepr.dev", "making-waves");
|
|
261
|
-
});
|
|
262
|
-
`,
|
|
81
|
+
data: samples_json_1.default.map(r => (0, client_node_1.dumpYaml)(r, { noRefs: true })).join("---\n"),
|
|
263
82
|
};
|
|
264
83
|
exports.snippet = {
|
|
265
84
|
path: "pepr.code-snippets",
|
|
266
|
-
data:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
"
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
"\\tnamespaces: [$\{2:}],",
|
|
276
|
-
"});",
|
|
277
|
-
"",
|
|
278
|
-
"// Use the 'When' function to create a new Capability Action",
|
|
279
|
-
"const { When } = $\{TM_FILENAME_BASE/(.*)/$\{1:/pascalcase}/};",
|
|
280
|
-
"",
|
|
281
|
-
"// When(a.<Kind>).Is<Event>().Then(change => change.<changes>",
|
|
282
|
-
"When($\{3:})"
|
|
283
|
-
],
|
|
284
|
-
"description": "Creates a new Pepr capability with a specified description, and optional namespaces, and adds a When statement for the specified value."
|
|
285
|
-
}
|
|
286
|
-
}`,
|
|
85
|
+
data: pepr_code_snippets_json_1.default,
|
|
86
|
+
};
|
|
87
|
+
exports.tsConfig = {
|
|
88
|
+
path: "tsconfig.json",
|
|
89
|
+
data: tsconfig_json_1.default,
|
|
90
|
+
};
|
|
91
|
+
exports.prettierRC = {
|
|
92
|
+
path: ".prettierrc",
|
|
93
|
+
data: prettierrc_json_1.default,
|
|
287
94
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// This is a helper script to collect the contents of the template files before building the CLI
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const baseDir = path.join(__dirname, "..", "src", "cli", "init", "templates");
|
|
8
|
+
|
|
9
|
+
// Read the text file
|
|
10
|
+
const gitignore = fs.readFileSync(path.join(baseDir, "gitignore"), "utf8");
|
|
11
|
+
const readme = fs.readFileSync(path.join(baseDir, "README.md"), "utf8");
|
|
12
|
+
const peprTS = fs.readFileSync(path.join(baseDir, "pepr.ts"), "utf8");
|
|
13
|
+
const helloPeprTS = fs.readFileSync(path.join(baseDir, "hello-pepr.ts"), "utf8");
|
|
14
|
+
|
|
15
|
+
fs.writeFileSync(
|
|
16
|
+
path.join(baseDir, "data.json"),
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
gitignore,
|
|
19
|
+
readme,
|
|
20
|
+
peprTS,
|
|
21
|
+
helloPeprTS,
|
|
22
|
+
})
|
|
23
|
+
);
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=18.0.0"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.1.
|
|
12
|
+
"version": "0.1.42",
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
15
|
"pepr": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"
|
|
27
|
+
"prebuild": "rm -fr dist/* && node hack/build-template-data.js",
|
|
28
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
29
|
"test": "npm run build && ava && node dist/cli.js -V",
|
|
29
30
|
"lint": "npx eslint src",
|
|
30
31
|
"lint:fix": "npm run lint -- --fix",
|
package/tsconfig.build.json
CHANGED