@spinnaker/pluginsdk 0.1.0
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/LICENSE.txt +203 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
- package/pluginconfig/README.md +2 -0
- package/pluginconfig/eslintrc.js +4 -0
- package/pluginconfig/huskyrc.js +5 -0
- package/pluginconfig/prettierrc.js +5 -0
- package/pluginconfig/rollup.config.js +1 -0
- package/pluginconfig/tsconfig.json +18 -0
- package/scaffold/.eslintrc.js +1 -0
- package/scaffold/.lintstagedrc.json +4 -0
- package/scaffold/package.json +21 -0
- package/scaffold/rollup.config.js +6 -0
- package/scaffold/scaffold-deck.gradle +1 -0
- package/scaffold/scaffold.prettierrc.js +1 -0
- package/scaffold/scaffold.tsconfig.json +7 -0
- package/scaffold/src/WidgetizeStage.less +2 -0
- package/scaffold/src/WidgetizeStage.tsx +75 -0
- package/scaffold/src/index.ts +6 -0
- package/scripts/check-plugin/asserters/assertFileExists.js +13 -0
- package/scripts/check-plugin/asserters/assertJavascriptFile.js +28 -0
- package/scripts/check-plugin/asserters/assertJsonFile.js +23 -0
- package/scripts/check-plugin/linters/index.js +9 -0
- package/scripts/check-plugin/linters/lint.eslintrc.js +13 -0
- package/scripts/check-plugin/linters/lint.lintstagedrc.json.js +7 -0
- package/scripts/check-plugin/linters/lint.package.json.js +67 -0
- package/scripts/check-plugin/linters/lint.prettierrc.js +13 -0
- package/scripts/check-plugin/linters/lint.rollup.config.js +13 -0
- package/scripts/check-plugin/linters/lint.tsconfig.json.js +19 -0
- package/scripts/check-plugin.js +107 -0
- package/scripts/dev-proxy/certs.js +75 -0
- package/scripts/dev-proxy/livereload.js +54 -0
- package/scripts/dev-proxy/server.js +111 -0
- package/scripts/husky-install.sh +41 -0
- package/scripts/pluginsdkdir.js +3 -0
- package/scripts/restore-scaffold-file.js +19 -0
- package/scripts/scaffold.js +79 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2014 Netflix
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spinnaker/pluginsdk",
|
|
3
|
+
"description": "Provides blessed opinions (rollup, code format, lint) and packages (react, etc) to plugin developers",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "npx shx rm -rf dist",
|
|
10
|
+
"build": "spinnaker-scripts build",
|
|
11
|
+
"watch": "spinnaker-scripts start",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"check-plugin": "scripts/check-plugin.js",
|
|
16
|
+
"dev-proxy": "scripts/dev-proxy/server.js",
|
|
17
|
+
"husky-install": "scripts/husky-install.sh",
|
|
18
|
+
"restore-scaffold-file": "scripts/restore-scaffold-file.js",
|
|
19
|
+
"scaffold": "scripts/scaffold.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@spinnaker/scripts": "^0.2.0",
|
|
23
|
+
"check-peer-dependencies": "^4.0.0",
|
|
24
|
+
"chokidar": "^3.5.1",
|
|
25
|
+
"express": "^4.17.1",
|
|
26
|
+
"http-proxy-middleware": "^1.0.6",
|
|
27
|
+
"husky": "^6.0.0",
|
|
28
|
+
"lint-staged": "^10.5.4",
|
|
29
|
+
"lodash": "^4.17.20",
|
|
30
|
+
"readline-sync": "^1.4.10",
|
|
31
|
+
"selfsigned": "^1.10.11",
|
|
32
|
+
"strip-json-comments": "^3.1.1",
|
|
33
|
+
"ws": "^7.4.3",
|
|
34
|
+
"yargs": "^16.2.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@spinnaker/core": "0.0.549",
|
|
38
|
+
"@types/yargs": "^16.0.0",
|
|
39
|
+
"typescript": "4.3.5"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"scaffold",
|
|
44
|
+
"scripts",
|
|
45
|
+
"pluginconfig"
|
|
46
|
+
],
|
|
47
|
+
"gitHead": "5b8914288d87ce58b67de4720ebc623b18a3be3e"
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@spinnaker/scripts/config/rollup.config.base.plugin');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowSyntheticDefaultImports": true,
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
6
|
+
"inlineSources": true,
|
|
7
|
+
"inlineSourceMap": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"jsx": "react",
|
|
11
|
+
"lib": ["es2017", "dom", "ES2018.Promise"],
|
|
12
|
+
"module": "esnext",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"noImplicitAny": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"target": "es2017"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@spinnaker/pluginsdk/pluginconfig/eslintrc');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "spinnaker-deck-plugin-scaffold",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"module": "build/dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "npx shx rm -rf build",
|
|
8
|
+
"develop": "npm run clean && run-p watch proxy",
|
|
9
|
+
"build": "npm run clean && NODE_ENV=production rollup -c",
|
|
10
|
+
"lint": "eslint --ext js,jsx,ts,tsx src",
|
|
11
|
+
"postinstall": "check-plugin && check-peer-dependencies || true",
|
|
12
|
+
"prepare": "husky-install",
|
|
13
|
+
"prettier": "prettier --write 'src/**/*.{js,jsx,ts,tsx,html,css,less,json}'",
|
|
14
|
+
"proxy": "dev-proxy",
|
|
15
|
+
"watch": "rollup -c -w --no-watch.clearScreen"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@spinnaker/pluginsdk": "latest"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
apply plugin: "io.spinnaker.plugin.ui-extension"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@spinnaker/pluginsdk/pluginconfig/prettierrc.js');
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ExecutionDetailsTasks,
|
|
5
|
+
FormikFormField,
|
|
6
|
+
FormikStageConfig,
|
|
7
|
+
FormValidator,
|
|
8
|
+
HelpField,
|
|
9
|
+
IFormikStageConfigInjectedProps,
|
|
10
|
+
IStage,
|
|
11
|
+
IStageConfigProps,
|
|
12
|
+
IStageTypeConfig,
|
|
13
|
+
NumberInput,
|
|
14
|
+
TextInput,
|
|
15
|
+
Validators,
|
|
16
|
+
} from '@spinnaker/core';
|
|
17
|
+
|
|
18
|
+
import './WidgetizeStage.less';
|
|
19
|
+
|
|
20
|
+
/** An example stage config using the FormikStageConfig component */
|
|
21
|
+
export function WidgetizeStageConfig(props: IStageConfigProps) {
|
|
22
|
+
return (
|
|
23
|
+
<div className="WidgetizeStageConfig">
|
|
24
|
+
<FormikStageConfig
|
|
25
|
+
{...props}
|
|
26
|
+
validate={validate}
|
|
27
|
+
onChange={props.updateStage}
|
|
28
|
+
render={(props) => <WidgetizeStageForm {...props} />}
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function WidgetizeStageForm(props: IFormikStageConfigInjectedProps) {
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<FormikFormField
|
|
38
|
+
name="instanceCount"
|
|
39
|
+
label="Instance Count"
|
|
40
|
+
help={<HelpField content="The number of instances to widgetize" />}
|
|
41
|
+
input={(props) => <NumberInput {...props} />}
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
<FormikFormField
|
|
45
|
+
name="user.email"
|
|
46
|
+
label="User Email"
|
|
47
|
+
help={<HelpField content="The email address of the user performing the widgetize operation" />}
|
|
48
|
+
input={(props) => <TextInput {...props} />}
|
|
49
|
+
/>
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Example validation */
|
|
55
|
+
export function validate(stageConfig: IStage) {
|
|
56
|
+
const validator = new FormValidator(stageConfig);
|
|
57
|
+
|
|
58
|
+
validator
|
|
59
|
+
.field('count')
|
|
60
|
+
.required()
|
|
61
|
+
.withValidators((value, label) => (value < 10 ? `${label} must be > 10` : undefined));
|
|
62
|
+
|
|
63
|
+
validator.field('user.email', 'Email').required().withValidators(Validators.emailValue('Invalid email'));
|
|
64
|
+
|
|
65
|
+
return validator.validateForm();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const widgetizeStage: IStageTypeConfig = {
|
|
69
|
+
key: 'widgetize',
|
|
70
|
+
label: 'Widgetize',
|
|
71
|
+
description: 'Widgetize the froobulator.',
|
|
72
|
+
component: WidgetizeStageConfig,
|
|
73
|
+
executionDetailsSections: [ExecutionDetailsTasks],
|
|
74
|
+
validateFn: validate,
|
|
75
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
const assertFileExists = (report, filename, pristineFilename = filename) => {
|
|
4
|
+
const ok = fs.existsSync(filename);
|
|
5
|
+
const resolution = {
|
|
6
|
+
description: `restore ${filename} from scaffold defaults`,
|
|
7
|
+
command: `npx restore-scaffold-file ${filename}`,
|
|
8
|
+
};
|
|
9
|
+
report(`${filename} does not exist`, ok, resolution);
|
|
10
|
+
return ok;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = { assertFileExists };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const pluginsdkdir = require('../../pluginsdkdir');
|
|
4
|
+
const { assertFileExists } = require('./assertFileExists');
|
|
5
|
+
|
|
6
|
+
function assertJavascriptFile(report, filename, pristineFilename, name, requireString) {
|
|
7
|
+
const exists = assertFileExists(report, filename, pristineFilename);
|
|
8
|
+
|
|
9
|
+
if (exists) {
|
|
10
|
+
// packages/pluginsdk/scaffold/${pristineFilename}
|
|
11
|
+
const pristinePath = path.resolve(pluginsdkdir, 'scaffold', pristineFilename);
|
|
12
|
+
const pristineFile = fs.readFileSync(pristinePath).toString();
|
|
13
|
+
const pluginFile = fs.readFileSync(filename).toString();
|
|
14
|
+
const hasRequire = pluginFile.includes(requireString);
|
|
15
|
+
const resolution = {
|
|
16
|
+
description: `Restore ${filename} from scaffold defaults (this will revert any local changes)`,
|
|
17
|
+
command: `npx restore-scaffold-file ${filename}`,
|
|
18
|
+
};
|
|
19
|
+
report(`${filename} does not extend ${requireString}`, hasRequire, resolution);
|
|
20
|
+
report(
|
|
21
|
+
`${filename} extends ${requireString} but has been customized`,
|
|
22
|
+
hasRequire && pristineFile.trim() !== pluginFile.trim() ? null : true,
|
|
23
|
+
resolution,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { assertJavascriptFile };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { get } = require('lodash');
|
|
2
|
+
|
|
3
|
+
const assertJsonFile = (report, filename, json) => {
|
|
4
|
+
return function assertJsonFile(field, expectedValue) {
|
|
5
|
+
const currentValue = get(json, field);
|
|
6
|
+
|
|
7
|
+
const deleteResolution = {
|
|
8
|
+
description: `Delete ${field} in ${filename}`,
|
|
9
|
+
command: `npx read-write-json delete "${filename}" "${field}"`,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const changeResolution = {
|
|
13
|
+
description: `Change ${field} in ${filename} from "${currentValue}" to "${expectedValue}"`,
|
|
14
|
+
command: `npx read-write-json write "${filename}" "${field}" "${expectedValue}"`,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const resolution = expectedValue === undefined ? deleteResolution : changeResolution;
|
|
18
|
+
const ok = currentValue === expectedValue;
|
|
19
|
+
report(`Unexpected value in ${filename}: ${field} should be "${expectedValue}"`, ok, resolution);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = { assertJsonFile };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const { checkEslintRc } = require('./lint.eslintrc');
|
|
2
|
+
const { checkLintStagedRc } = require('./lint.lintstagedrc.json');
|
|
3
|
+
const { checkPackageJson } = require('./lint.package.json');
|
|
4
|
+
const { checkPrettierRc } = require('./lint.prettierrc');
|
|
5
|
+
const { checkRollupConfig } = require('./lint.rollup.config');
|
|
6
|
+
const { checkTsconfig } = require('./lint.tsconfig.json');
|
|
7
|
+
|
|
8
|
+
const linters = [checkEslintRc, checkLintStagedRc, checkPackageJson, checkPrettierRc, checkRollupConfig, checkTsconfig];
|
|
9
|
+
module.exports = { linters };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { assertJavascriptFile } = require('../asserters/assertJavascriptFile');
|
|
2
|
+
|
|
3
|
+
function checkEslintRc(report) {
|
|
4
|
+
assertJavascriptFile(
|
|
5
|
+
report,
|
|
6
|
+
'.eslintrc.js',
|
|
7
|
+
'.eslintrc.js',
|
|
8
|
+
'Eslint config',
|
|
9
|
+
'@spinnaker/pluginsdk/pluginconfig/eslintrc',
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { checkEslintRc };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const { assertJsonFile } = require('../asserters/assertJsonFile');
|
|
5
|
+
const { readJson } = require('@spinnaker/scripts/read-write-json');
|
|
6
|
+
|
|
7
|
+
const PLUGIN_SDK = '@spinnaker/pluginsdk';
|
|
8
|
+
const PEER_DEPS = '@spinnaker/pluginsdk-peerdeps';
|
|
9
|
+
|
|
10
|
+
function getLatestPackageVersion(pkg) {
|
|
11
|
+
const versionsString = execSync(`npm info ${pkg} versions`).toString();
|
|
12
|
+
return JSON.parse(versionsString.replace(/'/g, '"')).pop();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getInstalledPackageVersion(pkgJson, pkg) {
|
|
16
|
+
return (
|
|
17
|
+
(pkgJson.dependencies && pkgJson.dependencies[pkg]) || (pkgJson.devDependencies && pkgJson.devDependencies[pkg])
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function checkPackageJson(report) {
|
|
22
|
+
const pkgJson = readJson('package.json');
|
|
23
|
+
|
|
24
|
+
const latestSdkVersion = getLatestPackageVersion(PLUGIN_SDK);
|
|
25
|
+
const installedSdkVersion = getInstalledPackageVersion(pkgJson, PLUGIN_SDK);
|
|
26
|
+
|
|
27
|
+
report(
|
|
28
|
+
installedSdkVersion
|
|
29
|
+
? `This plugin uses an out of date ${PLUGIN_SDK}@${installedSdkVersion}`
|
|
30
|
+
: `This plugin does not have ${PLUGIN_SDK} installed`,
|
|
31
|
+
installedSdkVersion === latestSdkVersion,
|
|
32
|
+
{
|
|
33
|
+
description: `Install ${PLUGIN_SDK}@${latestSdkVersion}`,
|
|
34
|
+
command: `yarn add ${PLUGIN_SDK}@${latestSdkVersion}`,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const latestPeerDepsVersion = getLatestPackageVersion(PEER_DEPS);
|
|
39
|
+
const installedPeerDepsVersion = getInstalledPackageVersion(pkgJson, PEER_DEPS);
|
|
40
|
+
|
|
41
|
+
report(
|
|
42
|
+
installedPeerDepsVersion
|
|
43
|
+
? `This plugin uses an out of date ${PEER_DEPS}@${installedPeerDepsVersion}`
|
|
44
|
+
: `This plugin does not have ${PEER_DEPS} installed`,
|
|
45
|
+
installedPeerDepsVersion === latestPeerDepsVersion,
|
|
46
|
+
{
|
|
47
|
+
description: `Install ${PEER_DEPS}@${latestPeerDepsVersion}`,
|
|
48
|
+
command: `yarn add ${PEER_DEPS}@${latestPeerDepsVersion}`,
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const checkPackageJsonField = assertJsonFile(report, 'package.json', pkgJson);
|
|
53
|
+
|
|
54
|
+
checkPackageJsonField('devDependencies.husky', undefined);
|
|
55
|
+
checkPackageJsonField('dependencies.husky', undefined);
|
|
56
|
+
checkPackageJsonField('scripts.build', 'npm run clean && NODE_ENV=production rollup -c');
|
|
57
|
+
checkPackageJsonField('scripts.clean', 'npx shx rm -rf build');
|
|
58
|
+
checkPackageJsonField('scripts.lint', 'eslint --ext js,jsx,ts,tsx src');
|
|
59
|
+
checkPackageJsonField('scripts.develop', 'npm run clean && run-p watch proxy');
|
|
60
|
+
checkPackageJsonField('scripts.postinstall', 'check-plugin && check-peer-dependencies || true');
|
|
61
|
+
checkPackageJsonField('scripts.prepare', 'husky-install');
|
|
62
|
+
checkPackageJsonField('scripts.prettier', "prettier --write 'src/**/*.{js,jsx,ts,tsx,html,css,less,json}'");
|
|
63
|
+
checkPackageJsonField('scripts.proxy', 'dev-proxy');
|
|
64
|
+
checkPackageJsonField('scripts.watch', 'rollup -c -w --no-watch.clearScreen');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = { checkPackageJson };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { assertJavascriptFile } = require('../asserters/assertJavascriptFile');
|
|
2
|
+
|
|
3
|
+
function checkPrettierRc(report) {
|
|
4
|
+
assertJavascriptFile(
|
|
5
|
+
report,
|
|
6
|
+
'.prettierrc.js',
|
|
7
|
+
'scaffold.prettierrc.js',
|
|
8
|
+
'Prettier config',
|
|
9
|
+
'@spinnaker/pluginsdk/pluginconfig/prettierrc.js',
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { checkPrettierRc };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { assertJavascriptFile } = require('../asserters/assertJavascriptFile');
|
|
2
|
+
|
|
3
|
+
function checkRollupConfig(report) {
|
|
4
|
+
assertJavascriptFile(
|
|
5
|
+
report,
|
|
6
|
+
'rollup.config.js',
|
|
7
|
+
'rollup.config.js',
|
|
8
|
+
'Rollup config',
|
|
9
|
+
'@spinnaker/pluginsdk/pluginconfig/rollup.config',
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { checkRollupConfig };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { assertJsonFile } = require('../asserters/assertJsonFile');
|
|
2
|
+
const { assertFileExists } = require('../asserters/assertFileExists');
|
|
3
|
+
const { readJson } = require('@spinnaker/scripts/read-write-json');
|
|
4
|
+
|
|
5
|
+
function checkTsconfig(report) {
|
|
6
|
+
const exists = assertFileExists(report, 'tsconfig.json');
|
|
7
|
+
|
|
8
|
+
if (exists) {
|
|
9
|
+
const tsConfigJson = readJson('tsconfig.json');
|
|
10
|
+
|
|
11
|
+
const checkTsconfigField = assertJsonFile(report, 'tsconfig.json', tsConfigJson);
|
|
12
|
+
|
|
13
|
+
checkTsconfigField('extends', '@spinnaker/pluginsdk/pluginconfig/tsconfig.json');
|
|
14
|
+
checkTsconfigField('compilerOptions.outDir', 'build/dist');
|
|
15
|
+
checkTsconfigField('compilerOptions.rootDir', 'src');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { checkTsconfig };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
const yargs = require('yargs');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
const { linters } = require('./check-plugin/linters');
|
|
7
|
+
|
|
8
|
+
yargs
|
|
9
|
+
.scriptName('check-plugin')
|
|
10
|
+
.option('verbose', {
|
|
11
|
+
alias: 'v',
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
default: false,
|
|
14
|
+
})
|
|
15
|
+
.option('fix', {
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
alias: 'f',
|
|
18
|
+
describe: 'When enabled, fixes are automatically applied',
|
|
19
|
+
default: false,
|
|
20
|
+
})
|
|
21
|
+
.option('fix-warnings', {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
alias: 'w',
|
|
24
|
+
describe: 'When enabled, fixes are automatically applied even for warnings',
|
|
25
|
+
default: false,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { verbose, fix, fixWarnings } = yargs.argv;
|
|
29
|
+
checkPlugin({ verbose, fixWarnings, fix: fix || fixWarnings });
|
|
30
|
+
|
|
31
|
+
function checkPlugin(options) {
|
|
32
|
+
const { verbose, fix, fixWarnings } = options;
|
|
33
|
+
|
|
34
|
+
const errorFixers = [];
|
|
35
|
+
const warningFixers = [];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param message { string }
|
|
39
|
+
* @param ok { boolean }
|
|
40
|
+
* @param resolution {{
|
|
41
|
+
* description: string
|
|
42
|
+
* command?: string
|
|
43
|
+
* fixer?: Function
|
|
44
|
+
* }}
|
|
45
|
+
*/
|
|
46
|
+
function reporter(message, ok, resolution = {}) {
|
|
47
|
+
const fixer = resolution.fixer || (resolution.command && (() => execSync(resolution.command)));
|
|
48
|
+
|
|
49
|
+
if (ok === true) {
|
|
50
|
+
if (verbose) {
|
|
51
|
+
console.log(` ✅ ${message}`);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
if (ok === false) {
|
|
55
|
+
console.log(` ❌ Error: ${message}`);
|
|
56
|
+
} else {
|
|
57
|
+
console.log(` ☑️ Warning: ${message}`);
|
|
58
|
+
}
|
|
59
|
+
if (fixer) {
|
|
60
|
+
errorFixers.push(fixer);
|
|
61
|
+
if (resolution.description) {
|
|
62
|
+
console.log(` Fix: ${resolution.description}`);
|
|
63
|
+
}
|
|
64
|
+
if (resolution.command) {
|
|
65
|
+
console.log(' Command:');
|
|
66
|
+
console.log();
|
|
67
|
+
console.log(` ${resolution.command}`);
|
|
68
|
+
console.log();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
linters.forEach((linter) => linter(reporter));
|
|
75
|
+
|
|
76
|
+
const fixingErrors = fix && errorFixers.length;
|
|
77
|
+
const fixingWarnings = fixWarnings && warningFixers.length;
|
|
78
|
+
|
|
79
|
+
console.log();
|
|
80
|
+
console.log();
|
|
81
|
+
if (fixingErrors || fixingWarnings) {
|
|
82
|
+
if (fixingWarnings) {
|
|
83
|
+
console.log('Fixing errors and warnings...');
|
|
84
|
+
} else {
|
|
85
|
+
console.log('Fixing errors...');
|
|
86
|
+
}
|
|
87
|
+
} else if (warningFixers.length) {
|
|
88
|
+
console.log(`Run this command to auto-fix all errors and warnings:`);
|
|
89
|
+
console.log();
|
|
90
|
+
console.log(`npx check-plugin --fix-warnings`);
|
|
91
|
+
} else if (errorFixers.length) {
|
|
92
|
+
console.log(`Run this command to auto-fix all errors:`);
|
|
93
|
+
console.log();
|
|
94
|
+
console.log(`npx check-plugin --fix`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log();
|
|
98
|
+
console.log();
|
|
99
|
+
|
|
100
|
+
if (fix) {
|
|
101
|
+
errorFixers.forEach((fix) => fix());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (fixWarnings) {
|
|
105
|
+
warningFixers.forEach((fix) => fix());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const selfsigned = require('selfsigned');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate certificates using selfsigned module.
|
|
5
|
+
*
|
|
6
|
+
* Borrowed from Webpack:
|
|
7
|
+
* https://github.com/webpack/webpack-dev-server/blob/ca36239cd845115084ca1ec8c8ff3ae10d414e86/lib/utils/createCertificate.js
|
|
8
|
+
*/
|
|
9
|
+
function createCertificate(attributes) {
|
|
10
|
+
return selfsigned.generate(attributes, {
|
|
11
|
+
algorithm: 'sha256',
|
|
12
|
+
days: 30,
|
|
13
|
+
keySize: 2048,
|
|
14
|
+
extensions: [
|
|
15
|
+
{
|
|
16
|
+
name: 'keyUsage',
|
|
17
|
+
keyCertSign: true,
|
|
18
|
+
digitalSignature: true,
|
|
19
|
+
nonRepudiation: true,
|
|
20
|
+
keyEncipherment: true,
|
|
21
|
+
dataEncipherment: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'extKeyUsage',
|
|
25
|
+
serverAuth: true,
|
|
26
|
+
clientAuth: true,
|
|
27
|
+
codeSigning: true,
|
|
28
|
+
timeStamping: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'subjectAltName',
|
|
32
|
+
altNames: [
|
|
33
|
+
{
|
|
34
|
+
// type 2 is DNS
|
|
35
|
+
type: 2,
|
|
36
|
+
value: 'localhost',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: 2,
|
|
40
|
+
value: 'localhost.localdomain',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 2,
|
|
44
|
+
value: 'lvh.me',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 2,
|
|
48
|
+
value: '*.lvh.me',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 2,
|
|
52
|
+
value: '[::1]',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
// type 7 is IP
|
|
56
|
+
type: 7,
|
|
57
|
+
ip: '127.0.0.1',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 7,
|
|
61
|
+
ip: 'fe80::1',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const certs = createCertificate([{ name: 'commonName', value: 'localhost' }]);
|
|
70
|
+
const combined = certs.private + certs.cert;
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
key: combined,
|
|
74
|
+
cert: combined,
|
|
75
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chokidar = require('chokidar');
|
|
4
|
+
const WebSocket = require('ws');
|
|
5
|
+
|
|
6
|
+
// Create a websocket server on port 8999 to live reload the client
|
|
7
|
+
const clients = [];
|
|
8
|
+
const wss = new WebSocket.Server({ port: 8999 });
|
|
9
|
+
wss.on('listening', () => {
|
|
10
|
+
console.log('Websocket (livereload) listening on localhost:8999');
|
|
11
|
+
});
|
|
12
|
+
wss.on('connection', (ws) => {
|
|
13
|
+
clients.push(ws);
|
|
14
|
+
ws.on('close', () => {
|
|
15
|
+
const index = clients.indexOf(ws);
|
|
16
|
+
if (index !== -1) {
|
|
17
|
+
clients.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const watchPath = path.resolve('build', 'dist', 'index.js');
|
|
23
|
+
const watcher = chokidar.watch(watchPath);
|
|
24
|
+
console.log(`Watching ${watchPath} for changes`);
|
|
25
|
+
watcher.on('change', (path) => {
|
|
26
|
+
console.log(`${path} changed, reloading ${clients.length} connected browsers`);
|
|
27
|
+
clients.forEach((ws) => {
|
|
28
|
+
try {
|
|
29
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
30
|
+
ws.send('livereload');
|
|
31
|
+
}
|
|
32
|
+
ws.close();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function liveReloadJs(req, res, next) {
|
|
40
|
+
res.set('Content-Type', 'application/javascript');
|
|
41
|
+
res.send(`
|
|
42
|
+
export const plugin = {
|
|
43
|
+
initialize() {
|
|
44
|
+
const socket = new WebSocket('ws://localhost:8999/');
|
|
45
|
+
socket.addEventListener('message', function (event) {
|
|
46
|
+
console.log('Message from server ', event.data);
|
|
47
|
+
location.reload();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = liveReloadJs;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
/*********************************
|
|
5
|
+
* dev-proxy: a development proxy for doing local development on a Deck Plugin
|
|
6
|
+
* This proxy allows a Deck Plugin Developer to load their Deck plugin into an existing Spinnaker installation.
|
|
7
|
+
*
|
|
8
|
+
* Point the proxy to the URL of a live spinnaker installation.
|
|
9
|
+
* It will serve the deck assets over http://localhost:9000.
|
|
10
|
+
* It serves a custom copy of `/plugin-manifest.json` which instructs spinnaker to load the plugin assets locally.
|
|
11
|
+
* It also enables live reloading (whenever the plugin assets change) via a websocket connection between the browser and proxy.
|
|
12
|
+
*********************************/
|
|
13
|
+
const express = require('express');
|
|
14
|
+
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const http = require('http');
|
|
18
|
+
const https = require('https');
|
|
19
|
+
const certs = require('./certs');
|
|
20
|
+
|
|
21
|
+
console.log('dev-proxy: a development proxy for doing local development on a Deck Plugin');
|
|
22
|
+
console.log('This service proxies deck assets from an live deck installation and loads your Deck plugin');
|
|
23
|
+
console.log();
|
|
24
|
+
|
|
25
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'UTF-8'));
|
|
26
|
+
|
|
27
|
+
const DEV_PROXY_HOST = process.env.DEV_PROXY_HOST || (packageJson.devProxy && packageJson.devProxy.host);
|
|
28
|
+
|
|
29
|
+
if (!DEV_PROXY_HOST) {
|
|
30
|
+
console.error();
|
|
31
|
+
console.error();
|
|
32
|
+
console.error('Error: No Deck URL specified. Add a field to package.json:');
|
|
33
|
+
console.error();
|
|
34
|
+
console.error('"devProxy": {');
|
|
35
|
+
console.error(' "host": "https://existing.spinnaker.deck.url/"');
|
|
36
|
+
console.error('}');
|
|
37
|
+
console.error();
|
|
38
|
+
console.error('Or, to specify the proxy host on the command line:');
|
|
39
|
+
console.error();
|
|
40
|
+
console.error('DEV_PROXY_HOST=https://existing.spinnaker.deck.url/ yarn proxy');
|
|
41
|
+
console.error();
|
|
42
|
+
console.error();
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const PLUGIN_ID = process.env.PLUGIN_ID || getPluginId();
|
|
46
|
+
console.log(`pluginId: ${PLUGIN_ID}`);
|
|
47
|
+
const PLUGIN_DIST_DIR = path.resolve('build', 'dist');
|
|
48
|
+
|
|
49
|
+
function getPluginId() {
|
|
50
|
+
try {
|
|
51
|
+
const line = fs
|
|
52
|
+
.readFileSync(path.resolve('..', 'build.gradle'))
|
|
53
|
+
.toString()
|
|
54
|
+
.split(/\n/)
|
|
55
|
+
.find((line) => line.includes('pluginId'));
|
|
56
|
+
|
|
57
|
+
const [_, pluginId] = /pluginId\s*=\s*"([^"]+)"/.exec(line);
|
|
58
|
+
return pluginId;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error();
|
|
61
|
+
console.error();
|
|
62
|
+
console.error(`Error: Unable to determine pluginId from ${path.resolve('..', 'build.gradle')}`);
|
|
63
|
+
console.error(`Expected to find a line matching 'pluginId = "your.pluginid"`);
|
|
64
|
+
console.error();
|
|
65
|
+
process.exit(2);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const app = express();
|
|
70
|
+
|
|
71
|
+
// Serve a plugin manifest with the plugin details filled in
|
|
72
|
+
app.get('/plugin-manifest.json', (req, resp, next) => {
|
|
73
|
+
resp.send([
|
|
74
|
+
{
|
|
75
|
+
id: PLUGIN_ID,
|
|
76
|
+
version: '0.0.0',
|
|
77
|
+
url: `/plugindev/${PLUGIN_ID}/index.js`,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'plugindev.livereload',
|
|
81
|
+
version: '0.0.0',
|
|
82
|
+
url: `/livereload.js`,
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Serve the plugin build via /plugindev/*
|
|
88
|
+
app.use(`/plugindev/${PLUGIN_ID}/`, express.static(PLUGIN_DIST_DIR));
|
|
89
|
+
|
|
90
|
+
// Send this livereload code to the client which will load it as a plugin
|
|
91
|
+
app.use('/livereload.js', require('./livereload'));
|
|
92
|
+
|
|
93
|
+
// Serve all other requests to deck code from an existing spinnaker environment
|
|
94
|
+
app.use('/', createProxyMiddleware({ target: DEV_PROXY_HOST, changeOrigin: true }));
|
|
95
|
+
|
|
96
|
+
// http
|
|
97
|
+
http.createServer(app).listen(9000);
|
|
98
|
+
|
|
99
|
+
// https
|
|
100
|
+
https
|
|
101
|
+
.createServer(
|
|
102
|
+
{
|
|
103
|
+
key: certs.key,
|
|
104
|
+
cert: certs.cert,
|
|
105
|
+
},
|
|
106
|
+
app,
|
|
107
|
+
)
|
|
108
|
+
.listen(9443);
|
|
109
|
+
|
|
110
|
+
console.log(`Server started on http://localhost:9000/`);
|
|
111
|
+
console.log(`Server started on https://localhost:9443/`);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
PACKAGEDIR=$(cd $(dirname $0)/../../; pwd -P);
|
|
4
|
+
cd $PACKAGEDIR;
|
|
5
|
+
|
|
6
|
+
[[ ! -e package.json ]] && {
|
|
7
|
+
echo "Unable to install husky commit hooks..."
|
|
8
|
+
echo "package.json not found at $PACKAGEDIR"
|
|
9
|
+
exit
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[[ ! -e .git ]] && [[ ! -e ../.git ]] && {
|
|
13
|
+
echo "Unable to install husky commit hooks..."
|
|
14
|
+
echo ".git not found at $PACKAGEDIR nor at $PACKAGEDIR/.."
|
|
15
|
+
exit
|
|
16
|
+
}
|
|
17
|
+
HUSKYBIN=$PACKAGEDIR/node_modules/.bin/husky
|
|
18
|
+
|
|
19
|
+
[[ ! -e $HUSKYBIN ]] && {
|
|
20
|
+
echo "Unable to install husky commit hooks..."
|
|
21
|
+
echo "husky binary not found at $HUSKYBIN"
|
|
22
|
+
exit
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
DIRNAME=$(basename $PACKAGEDIR);
|
|
26
|
+
[[ -e ../.git ]] && INSTALLDIR=".."
|
|
27
|
+
[[ -e .git ]] && INSTALLDIR="."
|
|
28
|
+
|
|
29
|
+
cd $INSTALLDIR
|
|
30
|
+
$HUSKYBIN install
|
|
31
|
+
|
|
32
|
+
cat > .husky/pre-commit <<'EOF'
|
|
33
|
+
#!/usr/bin/env bash
|
|
34
|
+
# CHECK THIS FILE INTO SOURCE CONTROL!
|
|
35
|
+
|
|
36
|
+
. "$(dirname "$0")/_/husky.sh"
|
|
37
|
+
|
|
38
|
+
EOF
|
|
39
|
+
|
|
40
|
+
echo "[[ -e $DIRNAME/node_modules/.bin/lint-staged ]] && cd $DIRNAME; ./node_modules/.bin/lint-staged -p false" >> .husky/pre-commit
|
|
41
|
+
chmod +x .husky/pre-commit
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
// Rename these files
|
|
8
|
+
const fileMapping = {
|
|
9
|
+
'tsconfig.json': 'scaffold.tsconfig.json',
|
|
10
|
+
'.prettierrc.js': 'scaffold.prettierrc.js',
|
|
11
|
+
// 'scaffold-deck.gradle': `${scaffoldTargetDir}.gradle`,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const file = require('yargs').argv._[0];
|
|
15
|
+
const sourceFile = path.resolve('node_modules', '@spinnaker', 'pluginsdk', 'scaffold', fileMapping[file] || file);
|
|
16
|
+
const destFile = path.resolve('.', file);
|
|
17
|
+
|
|
18
|
+
const bytes = fs.readFileSync(sourceFile);
|
|
19
|
+
fs.writeFileSync(destFile, bytes);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @ts-check */
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const { execSync } = require('child_process');
|
|
8
|
+
const readlineSync = require('readline-sync');
|
|
9
|
+
|
|
10
|
+
const yargs = require('yargs')
|
|
11
|
+
.option('directory', {
|
|
12
|
+
type: 'string',
|
|
13
|
+
})
|
|
14
|
+
.option('name', {
|
|
15
|
+
type: 'string',
|
|
16
|
+
}).argv;
|
|
17
|
+
|
|
18
|
+
const pluginNameQuestion = 'Enter the short name for your plugin (default: myplugin): ';
|
|
19
|
+
const pluginName = yargs.name || readlineSync.question(pluginNameQuestion, { defaultInput: 'myplugin' });
|
|
20
|
+
|
|
21
|
+
const dirQuestion = `Directory to scaffold into (default: ${pluginName}-deck): `;
|
|
22
|
+
const scaffoldTargetDir = yargs.directory || readlineSync.question(dirQuestion, { defaultInput: `${pluginName}-deck` });
|
|
23
|
+
const basename = path.basename(path.resolve(scaffoldTargetDir));
|
|
24
|
+
|
|
25
|
+
// Rename these files
|
|
26
|
+
const fileMapping = {
|
|
27
|
+
'scaffold.tsconfig.json': 'tsconfig.json',
|
|
28
|
+
'scaffold.prettierrc.js': '.prettierrc.js',
|
|
29
|
+
'scaffold-deck.gradle': `${basename}.gradle`,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const renamedFile = (file) => fileMapping[file] || file;
|
|
33
|
+
|
|
34
|
+
function mkdirIfNotExists(dirPath) {
|
|
35
|
+
if (!fs.existsSync(dirPath)) {
|
|
36
|
+
fs.mkdirSync(dirPath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function recursiveCopy(srcDir, targetDir) {
|
|
41
|
+
const contents = fs.readdirSync(srcDir);
|
|
42
|
+
contents
|
|
43
|
+
.filter((x) => x !== '.' && x !== '..')
|
|
44
|
+
.forEach((file) => {
|
|
45
|
+
const srcPath = path.resolve(srcDir, file);
|
|
46
|
+
const targetPath = path.resolve(targetDir, renamedFile(file));
|
|
47
|
+
const stat = fs.statSync(srcPath);
|
|
48
|
+
if (stat.isDirectory()) {
|
|
49
|
+
mkdirIfNotExists(targetPath);
|
|
50
|
+
recursiveCopy(srcPath, targetPath);
|
|
51
|
+
} else if (stat.isFile()) {
|
|
52
|
+
fs.writeFileSync(targetPath, fs.readFileSync(srcPath));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function updatePackageJson(pkgJsonPath, basename) {
|
|
58
|
+
const pluginSdkPackageContents = fs.readFileSync(path.resolve(__dirname, '..', 'package.json')).toString();
|
|
59
|
+
const pluginSdkVersion = JSON.parse(pluginSdkPackageContents).version;
|
|
60
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath).toString());
|
|
61
|
+
pkgJson.name = basename;
|
|
62
|
+
pkgJson.dependencies['@spinnaker/pluginsdk'] = pluginSdkVersion;
|
|
63
|
+
pkgJson.files = ['build/dist'];
|
|
64
|
+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
mkdirIfNotExists(scaffoldTargetDir);
|
|
68
|
+
recursiveCopy(path.resolve(__dirname, '..', 'scaffold'), scaffoldTargetDir);
|
|
69
|
+
updatePackageJson(path.resolve(scaffoldTargetDir, 'package.json'), basename);
|
|
70
|
+
|
|
71
|
+
console.log(`Deck plugin scaffolded into ${scaffoldTargetDir}`);
|
|
72
|
+
console.log(`Installing dependencies using 'yarn' and 'npx check-peer-dependencies --install' ...`);
|
|
73
|
+
|
|
74
|
+
process.chdir(scaffoldTargetDir);
|
|
75
|
+
console.log(`yarn`);
|
|
76
|
+
execSync(`yarn`, { stdio: 'inherit' });
|
|
77
|
+
|
|
78
|
+
console.log(`npx check-peer-dependencies --install`);
|
|
79
|
+
execSync(`npx check-peer-dependencies --install`, { stdio: 'inherit' });
|