@spinnaker/pluginsdk 0.0.0-main-2

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.
Files changed (36) hide show
  1. package/LICENSE.txt +203 -0
  2. package/package.json +52 -0
  3. package/pluginconfig/README.md +2 -0
  4. package/pluginconfig/eslintrc.js +4 -0
  5. package/pluginconfig/huskyrc.js +5 -0
  6. package/pluginconfig/prettierrc.js +5 -0
  7. package/pluginconfig/rollup.config.js +1 -0
  8. package/pluginconfig/tsconfig.json +18 -0
  9. package/scaffold/.eslintrc.js +1 -0
  10. package/scaffold/.lintstagedrc.json +4 -0
  11. package/scaffold/package.json +24 -0
  12. package/scaffold/rollup.config.js +6 -0
  13. package/scaffold/scaffold-deck.gradle +1 -0
  14. package/scaffold/scaffold.prettierrc.js +1 -0
  15. package/scaffold/scaffold.tsconfig.json +7 -0
  16. package/scaffold/src/WidgetizeStage.less +2 -0
  17. package/scaffold/src/WidgetizeStage.tsx +72 -0
  18. package/scaffold/src/index.ts +6 -0
  19. package/scripts/check-plugin/asserters/assertFileExists.js +13 -0
  20. package/scripts/check-plugin/asserters/assertJavascriptFile.js +28 -0
  21. package/scripts/check-plugin/asserters/assertJsonFile.js +23 -0
  22. package/scripts/check-plugin/linters/index.js +9 -0
  23. package/scripts/check-plugin/linters/lint.eslintrc.js +13 -0
  24. package/scripts/check-plugin/linters/lint.lintstagedrc.json.js +7 -0
  25. package/scripts/check-plugin/linters/lint.package.json.js +67 -0
  26. package/scripts/check-plugin/linters/lint.prettierrc.js +13 -0
  27. package/scripts/check-plugin/linters/lint.rollup.config.js +13 -0
  28. package/scripts/check-plugin/linters/lint.tsconfig.json.js +19 -0
  29. package/scripts/check-plugin.js +107 -0
  30. package/scripts/dev-proxy/certs.js +75 -0
  31. package/scripts/dev-proxy/livereload.js +54 -0
  32. package/scripts/dev-proxy/server.js +116 -0
  33. package/scripts/husky-install.sh +41 -0
  34. package/scripts/pluginsdkdir.js +3 -0
  35. package/scripts/restore-scaffold-file.js +19 -0
  36. 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/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@spinnaker/pluginsdk",
3
+ "description": "Provides blessed opinions (rollup, code format, lint) and packages (react, etc) to plugin developers",
4
+ "version": "0.0.0-main-2",
5
+ "module": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "license": "Apache-2.0",
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "registry": "https://registry.npmjs.org"
11
+ },
12
+ "scripts": {
13
+ "clean": "shx rm -rf dist",
14
+ "build": "spinnaker-scripts build",
15
+ "watch": "spinnaker-scripts start",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "bin": {
19
+ "check-plugin": "scripts/check-plugin.js",
20
+ "dev-proxy": "scripts/dev-proxy/server.js",
21
+ "husky-install": "scripts/husky-install.sh",
22
+ "restore-scaffold-file": "scripts/restore-scaffold-file.js",
23
+ "scaffold": "scripts/scaffold.js"
24
+ },
25
+ "dependencies": {
26
+ "@spinnaker/scripts": "^0.4.0",
27
+ "check-peer-dependencies": "^4.0.0",
28
+ "chokidar": "^3.5.1",
29
+ "express": "^4.17.1",
30
+ "http-proxy-middleware": "^1.0.6",
31
+ "husky": "^6.0.0",
32
+ "lint-staged": "^10.5.4",
33
+ "lodash": "^4.17.20",
34
+ "readline-sync": "^1.4.10",
35
+ "selfsigned": "^2.0.1",
36
+ "strip-json-comments": "^3.1.1",
37
+ "ws": "^7.4.3",
38
+ "yargs": "^16.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "@spinnaker/core": "0.0.549",
42
+ "@types/yargs": "^16.0.0",
43
+ "typescript": "4.3.5"
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "scaffold",
48
+ "scripts",
49
+ "pluginconfig"
50
+ ],
51
+ "gitHead": "41637c82dc23fbf1195173a93611a08000fc0e53"
52
+ }
@@ -0,0 +1,2 @@
1
+ These config files are intended to be extended by plugins.
2
+ The plugin should depend on `@spinnaker/pluginsdk` and extend these base configurations.
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ plugins: ['@spinnaker/eslint-plugin'],
3
+ extends: ['plugin:@spinnaker/base'],
4
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ hooks: {
3
+ 'pre-commit': 'pretty-quick --staged',
4
+ },
5
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ singleQuote: true,
3
+ trailingComma: 'all',
4
+ printWidth: 120,
5
+ };
@@ -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,4 @@
1
+ {
2
+ "src/**/*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
3
+ "src/**/*.{css,less,html}": "prettier --write"
4
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "spinnaker-deck-plugin-scaffold",
3
+ "version": "0.0.0-main-2",
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
+ "publishConfig": {
22
+ "registry": "https://registry.npmjs.org"
23
+ }
24
+ }
@@ -0,0 +1,6 @@
1
+ const basePluginConfig = require('@spinnaker/pluginsdk/pluginconfig/rollup.config');
2
+
3
+ export default {
4
+ ...basePluginConfig,
5
+ input: 'src/index.ts',
6
+ };
@@ -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,7 @@
1
+ {
2
+ "extends": "@spinnaker/pluginsdk/pluginconfig/tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/dist",
5
+ "rootDir": "src"
6
+ }
7
+ }
@@ -0,0 +1,2 @@
1
+ .WidgetizeStageConfig {
2
+ }
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+
3
+ import type { IFormikStageConfigInjectedProps, IStage, IStageConfigProps, IStageTypeConfig } from '@spinnaker/core';
4
+ import {
5
+ ExecutionDetailsTasks,
6
+ FormikFormField,
7
+ FormikStageConfig,
8
+ FormValidator,
9
+ HelpField,
10
+ NumberInput,
11
+ TextInput,
12
+ Validators,
13
+ } from '@spinnaker/core';
14
+
15
+ import './WidgetizeStage.less';
16
+
17
+ /** An example stage config using the FormikStageConfig component */
18
+ export function WidgetizeStageConfig(props: IStageConfigProps) {
19
+ return (
20
+ <div className="WidgetizeStageConfig">
21
+ <FormikStageConfig
22
+ {...props}
23
+ validate={validate}
24
+ onChange={props.updateStage}
25
+ render={(props) => <WidgetizeStageForm {...props} />}
26
+ />
27
+ </div>
28
+ );
29
+ }
30
+
31
+ function WidgetizeStageForm(props: IFormikStageConfigInjectedProps) {
32
+ return (
33
+ <>
34
+ <FormikFormField
35
+ name="instanceCount"
36
+ label="Instance Count"
37
+ help={<HelpField content="The number of instances to widgetize" />}
38
+ input={(props) => <NumberInput {...props} />}
39
+ />
40
+
41
+ <FormikFormField
42
+ name="user.email"
43
+ label="User Email"
44
+ help={<HelpField content="The email address of the user performing the widgetize operation" />}
45
+ input={(props) => <TextInput {...props} />}
46
+ />
47
+ </>
48
+ );
49
+ }
50
+
51
+ /** Example validation */
52
+ export function validate(stageConfig: IStage) {
53
+ const validator = new FormValidator(stageConfig);
54
+
55
+ validator
56
+ .field('count')
57
+ .required()
58
+ .withValidators((value, label) => (value < 10 ? `${label} must be > 10` : undefined));
59
+
60
+ validator.field('user.email', 'Email').required().withValidators(Validators.emailValue('Invalid email'));
61
+
62
+ return validator.validateForm();
63
+ }
64
+
65
+ export const widgetizeStage: IStageTypeConfig = {
66
+ key: 'widgetize',
67
+ label: 'Widgetize',
68
+ description: 'Widgetize the froobulator.',
69
+ component: WidgetizeStageConfig,
70
+ executionDetailsSections: [ExecutionDetailsTasks],
71
+ validateFn: validate,
72
+ };
@@ -0,0 +1,6 @@
1
+ import type { IDeckPlugin } from '@spinnaker/core';
2
+ import { widgetizeStage } from './WidgetizeStage';
3
+
4
+ export const plugin: IDeckPlugin = {
5
+ stages: [widgetizeStage],
6
+ };
@@ -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,7 @@
1
+ const { assertFileExists } = require('../asserters/assertFileExists');
2
+
3
+ function checkLintStagedRc(report) {
4
+ assertFileExists(report, '.lintstagedrc.json');
5
+ }
6
+
7
+ module.exports = { checkLintStagedRc };
@@ -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,116 @@
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
+ const DEV_PROXY_HTTP_PORT =
30
+ parseInt(process.env.DEV_PROXY_HTTP_PORT || (packageJson.devProxy && packageJson.devProxy.httpPort)) || 9000;
31
+ const DEV_PROXY_HTTPS_PORT =
32
+ parseInt(process.env.DEV_PROXY_HTTPS_PORT || (packageJson.devProxy && packageJson.devProxy.httpsPort)) || 9443;
33
+
34
+ if (!DEV_PROXY_HOST) {
35
+ console.error();
36
+ console.error();
37
+ console.error('Error: No Deck URL specified. Add a field to package.json:');
38
+ console.error();
39
+ console.error('"devProxy": {');
40
+ console.error(' "host": "https://existing.spinnaker.deck.url/"');
41
+ console.error('}');
42
+ console.error();
43
+ console.error('Or, to specify the proxy host on the command line:');
44
+ console.error();
45
+ console.error('DEV_PROXY_HOST=https://existing.spinnaker.deck.url/ yarn proxy');
46
+ console.error();
47
+ console.error();
48
+ process.exit(1);
49
+ }
50
+ const PLUGIN_ID = process.env.PLUGIN_ID || getPluginId();
51
+ console.log(`pluginId: ${PLUGIN_ID}`);
52
+ const PLUGIN_DIST_DIR = path.resolve('build', 'dist');
53
+
54
+ function getPluginId() {
55
+ try {
56
+ const line = fs
57
+ .readFileSync(path.resolve('..', 'build.gradle'))
58
+ .toString()
59
+ .split(/\n/)
60
+ .find((line) => line.includes('pluginId'));
61
+
62
+ const [_, pluginId] = /pluginId\s*=\s*"([^"]+)"/.exec(line);
63
+ return pluginId;
64
+ } catch (error) {
65
+ console.error();
66
+ console.error();
67
+ console.error(`Error: Unable to determine pluginId from ${path.resolve('..', 'build.gradle')}`);
68
+ console.error(`Expected to find a line matching 'pluginId = "your.pluginid"`);
69
+ console.error();
70
+ process.exit(2);
71
+ }
72
+ }
73
+
74
+ const app = express();
75
+
76
+ // Serve a plugin manifest with the plugin details filled in
77
+ app.get('/plugin-manifest.json', (req, resp, next) => {
78
+ resp.send([
79
+ {
80
+ id: PLUGIN_ID,
81
+ version: '0.0.0',
82
+ url: `/plugindev/${PLUGIN_ID}/index.js`,
83
+ },
84
+ {
85
+ id: 'plugindev.livereload',
86
+ version: '0.0.0',
87
+ url: `/livereload.js`,
88
+ },
89
+ ]);
90
+ });
91
+
92
+ // Serve the plugin build via /plugindev/*
93
+ app.use(`/plugindev/${PLUGIN_ID}/`, express.static(PLUGIN_DIST_DIR));
94
+
95
+ // Send this livereload code to the client which will load it as a plugin
96
+ app.use('/livereload.js', require('./livereload'));
97
+
98
+ // Serve all other requests to deck code from an existing spinnaker environment
99
+ app.use('/', createProxyMiddleware({ target: DEV_PROXY_HOST, changeOrigin: true }));
100
+
101
+ // http
102
+ http.createServer(app).listen(DEV_PROXY_HTTP_PORT);
103
+
104
+ // https
105
+ https
106
+ .createServer(
107
+ {
108
+ key: certs.key,
109
+ cert: certs.cert,
110
+ },
111
+ app,
112
+ )
113
+ .listen(DEV_PROXY_HTTPS_PORT);
114
+
115
+ console.log(`Server started on http://localhost:${DEV_PROXY_HTTP_PORT}/`);
116
+ console.log(`Server started on https://localhost:${DEV_PROXY_HTTPS_PORT}/`);
@@ -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,3 @@
1
+ const path = require('path');
2
+ const pluginSdkDir = path.resolve(__dirname, '..');
3
+ module.exports = pluginSdkDir;
@@ -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' });