@rancher/create-extension 2.0.1 → 2.0.3

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.
@@ -5,26 +5,9 @@
5
5
  "engines": {
6
6
  "node": ">=16"
7
7
  },
8
- "dependencies": {
9
- "cache-loader": "^4.1.0",
10
- "color": "4.2.3",
11
- "ip": "2.0.1",
12
- "node-polyfill-webpack-plugin": "^3.0.0"
13
- },
8
+ "dependencies": {},
14
9
  "resolutions": {
15
- "d3-color": "3.1.0",
16
- "ejs": "3.1.9",
17
- "follow-redirects": "1.15.2",
18
- "glob": "7.2.3",
19
- "glob-parent": "6.0.2",
20
- "json5": "2.2.3",
21
- "@types/lodash": "4.17.5",
22
- "merge": "2.1.1",
23
- "node-forge": "1.3.1",
24
- "nth-check": "2.1.1",
25
- "qs": "6.11.1",
26
- "roarr": "7.0.4",
27
- "semver": "7.5.4",
28
- "@vue/cli-service/html-webpack-plugin": "^5.0.0"
10
+ "@types/node": "18.11.9",
11
+ "@types/lodash": "4.17.5"
29
12
  }
30
13
  }
@@ -0,0 +1 @@
1
+ 16
package/app/init CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console */
2
3
 
3
4
  const path = require('path');
4
5
  const fs = require('fs-extra');
@@ -15,6 +16,7 @@ const files = [
15
16
  'gitignore',
16
17
  '.eslintignore',
17
18
  '.eslintrc.js',
19
+ '.nvmrc',
18
20
  '.yarnrc.yml',
19
21
  'babel.config.js',
20
22
  '.vscode/settings.json'
@@ -27,7 +29,7 @@ const args = process.argv;
27
29
  let appFolder = path.resolve('.');
28
30
  let shellVersion = '';
29
31
 
30
- if (args.length === 3) {
32
+ if (args.length >= 3 && !args[2].includes('@rancher/create-extension/app/init')) {
31
33
  const name = args[2];
32
34
  const folder = path.resolve('.');
33
35
 
@@ -37,6 +39,7 @@ if (args.length === 3) {
37
39
  }
38
40
 
39
41
  let addGitlabWorkflow = false;
42
+ let addWorkflowFolder = true;
40
43
 
41
44
  // Check for Gitlab integration option
42
45
  if ( args.length >= 3 ) {
@@ -47,6 +50,10 @@ if ( args.length >= 3 ) {
47
50
  case '-l':
48
51
  addGitlabWorkflow = true;
49
52
  break;
53
+ case '--skip-workflow':
54
+ case '-w':
55
+ addWorkflowFolder = false;
56
+ break;
50
57
  default:
51
58
  break;
52
59
  }
@@ -57,10 +64,9 @@ if ( addGitlabWorkflow ) {
57
64
  files.push('.gitlab-ci.yml');
58
65
  }
59
66
 
60
- // Check that there is a package file
61
-
62
67
  let setName = false;
63
68
 
69
+ // Check that there is a package file
64
70
  if (!fs.existsSync(path.join(appFolder, './package.json'))) {
65
71
  console.log(' Adding package.json');
66
72
  fs.copySync(path.join(__dirname, 'app.package.json'), path.join(appFolder, 'package.json'));
@@ -105,6 +111,32 @@ if (creatorPkg._pkgs) {
105
111
 
106
112
  fs.writeFileSync(path.join(appFolder, 'package.json'), JSON.stringify(pkg, null, 2));
107
113
 
114
+ // Add workflow folder if needed
115
+ if ( addWorkflowFolder ) {
116
+ // Point to the workflow directory inside the skeleton application
117
+ const workflowDir = path.join(appFolder, '.github/workflows');
118
+
119
+ if ( !fs.existsSync(workflowDir) ) {
120
+ console.log(' Creating folder: .github/workflows');
121
+ fs.mkdirSync(workflowDir, { recursive: true });
122
+ }
123
+
124
+ const workflowFiles = [
125
+ 'build-extension-catalog.yml',
126
+ 'build-extension-charts.yml'
127
+ ];
128
+
129
+ workflowFiles.forEach((fileName) => {
130
+ const dest = path.join(workflowDir, fileName); // Destination in the skeleton application
131
+ const src = path.join(__dirname, 'files/.github/workflows', fileName); // Source in the package
132
+
133
+ if ( !fs.existsSync(dest) ) {
134
+ console.log(` Adding file ${ fileName } to root workflows`);
135
+ fs.copySync(src, dest);
136
+ }
137
+ });
138
+ }
139
+
108
140
  // Copy base files
109
141
  files.forEach((file) => {
110
142
  const destinationFile = file === 'gitignore' ? '.gitignore' : file;
@@ -114,7 +146,7 @@ files.forEach((file) => {
114
146
  if (!fs.existsSync(dest)) {
115
147
  console.log(` Adding file: ${ file }`);
116
148
 
117
- const folder = path.dirname(file);
149
+ const folder = path.dirname(dest);
118
150
 
119
151
  fs.ensureDirSync(folder);
120
152
 
@@ -123,4 +155,6 @@ files.forEach((file) => {
123
155
  }
124
156
  });
125
157
 
126
- console.log('');
158
+ console.log('Skeleton Application creation complete.\n');
159
+
160
+ /* eslint-enable no-console */
package/init CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable no-console */
3
3
 
4
- const { execSync } = require('child_process');
4
+ const { execSync, spawnSync } = require('child_process');
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
7
  const creatorPkg = require('./package.json');
@@ -124,7 +124,14 @@ try {
124
124
  if ( updateOnly ) {
125
125
  // Run the update script directly
126
126
  console.log('Updating applications...');
127
- execSync(`node ${ path.join(updatePath, 'init') }`, { stdio: 'inherit' });
127
+ const updateInitPath = path.join(updatePath, 'init');
128
+ const updateArgs = [updateInitPath, shellVersion, tagUsed, ...args];
129
+
130
+ const result = spawnSync('node', updateArgs, { stdio: 'inherit' });
131
+
132
+ if (result.status !== 0) {
133
+ throw new Error('Failed to create skeleton application.');
134
+ }
128
135
 
129
136
  console.log('Update completed successfully.');
130
137
  process.exit(0);
@@ -139,7 +146,14 @@ try {
139
146
  if ( !isInsideSkeleton && !skeletonExists ) {
140
147
  console.log(`Creating skeleton application: ${ appName }...`);
141
148
  // Pass all arguments to the app/init script
142
- execSync(`node ${ path.join(__dirname, 'app', 'init') } ${ appName } ${ shellVersion } ${ args.join(' ') }`, { stdio: 'inherit' });
149
+ const appInitPath = path.join(__dirname, 'app', 'init');
150
+ const appArgs = [appInitPath, appName, shellVersion, ...args];
151
+
152
+ const result = spawnSync('node', appArgs, { stdio: 'inherit' });
153
+
154
+ if (result.status !== 0) {
155
+ throw new Error('Failed to create skeleton application.');
156
+ }
143
157
 
144
158
  // Ensure the skeleton path directory is created before attempting to change directory
145
159
  if ( !fs.existsSync(skeletonPath) ) {
@@ -165,16 +179,30 @@ try {
165
179
  // Check for package existence and create it if necessary
166
180
  if ( !pkgExists ) {
167
181
  console.log(`Creating package: ${ extensionName }...`);
168
- execSync(`node ${ path.join(__dirname, 'pkg', 'init') } ${ extensionName } ${ shellVersion } ${ args.join(' ') }`, { stdio: 'inherit' });
182
+ const pkgInitPath = path.join(__dirname, 'pkg', 'init');
183
+ const pkgArgs = [pkgInitPath, extensionName, shellVersion, ...args];
184
+
185
+ const result = spawnSync('node', pkgArgs, { stdio: 'inherit' });
186
+
187
+ if (result.status !== 0) {
188
+ throw new Error('Failed to create package.');
189
+ }
169
190
  }
170
191
 
171
192
  if ( args.includes('--update') || args.includes('-u') ) {
172
193
  // Run the update script
173
194
  console.log('Updating applications...');
174
- execSync(`node ${ path.join(updatePath, 'init') } ${ extensionName }`, { stdio: 'inherit' });
195
+ const updatePath = path.join(__dirname, 'update');
196
+ const updateArgs = [updatePath, ...args];
197
+
198
+ const result = spawnSync('node', updateArgs, { stdio: 'inherit' });
199
+
200
+ if (result.status !== 0) {
201
+ throw new Error('Failed to update applications.');
202
+ }
175
203
  }
176
204
 
177
- console.log('Extension created successfully.');
205
+ // console.log('Extension created successfully.');
178
206
 
179
207
  if ( skeletonOnly || !isInsideSkeleton ) {
180
208
  console.log(`To begin, run: \n\n\tcd ${ appName } && yarn install\n`);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@rancher/create-extension",
3
3
  "description": "Rancher UI Extension generator",
4
- "version": "2.0.1",
4
+ "version": "2.0.3",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SUSE",
7
- "packageManager": "yarn@4.4.1",
7
+ "packageManager": "yarn@4.5.0",
8
8
  "bin": {
9
- "create-extension": "./init"
9
+ "create-extension": "init"
10
10
  },
11
11
  "files": [
12
12
  "**/*",
package/pkg/init CHANGED
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console */
2
3
 
3
4
  const fs = require('fs-extra');
4
5
  const path = require('path');
5
- const https = require('https');
6
-
7
- const targets = {
8
- dev: './node_modules/.bin/nuxt dev',
9
- nuxt: './node_modules/.bin/nuxt',
10
- };
11
6
 
12
7
  const files = [
13
8
  'tsconfig.json',
@@ -31,39 +26,23 @@ const typeFolders = [
31
26
  'detail'
32
27
  ];
33
28
 
34
- const shellPkgPath = 'node_modules/@rancher/shell';
35
-
36
29
  console.log('');
37
30
  console.log('Creating Skeleton UI Package');
38
31
 
39
32
  const args = process.argv;
40
33
 
41
- if (args.length !== 3) {
42
- console.log('Expected single argument of package name');
43
- }
44
-
45
34
  const name = args[2];
46
35
  const folder = path.resolve('.');
47
36
  const pkgFolder = path.join(folder, 'pkg', name);
48
- let shellVersion = '';
49
37
 
50
- let addTypeFolders = false;
51
- let addWorkflowFolder = false;
52
- let ignoreShellPkgPathCheck = false;
38
+ let addTypeFolders = true;
53
39
 
54
40
  if ( args.length >= 3 ) {
55
- shellVersion = args[3];
56
-
57
41
  for ( let i = 3; i < args.length; i++ ) {
58
42
  switch (args[i]) {
43
+ case '--skip-templates':
59
44
  case '-t':
60
- addTypeFolders = true;
61
- break;
62
- case '-w':
63
- addWorkflowFolder = true;
64
- break;
65
- case '-i':
66
- ignoreShellPkgPathCheck = true;
45
+ addTypeFolders = false;
67
46
  break;
68
47
  default:
69
48
  break;
@@ -71,12 +50,6 @@ if ( args.length >= 3 ) {
71
50
  }
72
51
  }
73
52
 
74
- if (!ignoreShellPkgPathCheck && !fs.existsSync(path.join(pkgFolder, `../../${ shellPkgPath }/package.json`))) {
75
- console.log('');
76
- console.log('@rancher/shell not found in node_modules! Please do "yarn install" and make sure you run this command from the base folder of your app');
77
- process.exit(1);
78
- }
79
-
80
53
  const isNodeModulesShell = !fs.existsSync(path.join(folder, 'shell'));
81
54
 
82
55
  if (!isNodeModulesShell) {
@@ -98,19 +71,8 @@ const pkg = JSON.parse(rawdata);
98
71
  pkg.name = name;
99
72
  pkg.description = `${ name } plugin`;
100
73
 
101
- Object.keys(targets).forEach((target) => {
102
- if (!pkg.scripts[target]) {
103
- pkg.scripts[target] = targets[target];
104
- console.log(` Adding script '${ target }' to package.json`);
105
- }
106
- });
107
-
108
74
  writePackageJson();
109
75
 
110
- // Add dependencies
111
- // pkg.dependencies['@rancher/shell'] = '^0.6.2';
112
- // pkg.dependencies['core-js'] = '3.18.3';
113
-
114
76
  function writePackageJson() {
115
77
  fs.writeFileSync(path.join(pkgFolder, 'package.json'), JSON.stringify(pkg, null, 2));
116
78
  }
@@ -127,31 +89,6 @@ if (addTypeFolders) {
127
89
  });
128
90
  }
129
91
 
130
- // Add workflow folder if needed
131
- if (addWorkflowFolder) {
132
- const workflowDir = path.join(folder, '.github/workflows');
133
-
134
- if (!fs.existsSync(workflowDir)) {
135
- fs.mkdirSync(workflowDir, { recursive: true });
136
- }
137
-
138
- const files = [
139
- 'build-extension-catalog.yml',
140
- 'build-extension-charts.yml'
141
- ];
142
-
143
- files.forEach((fileName) => {
144
- const file = path.join(workflowDir, fileName);
145
-
146
- if (!fs.existsSync(file)) {
147
- const src = path.join(__dirname, 'files/.github/workflows', fileName);
148
-
149
- console.log(` Adding file ${ fileName } to root workflows`);
150
- fs.copySync(src, file);
151
- }
152
- });
153
- }
154
-
155
92
  // Copy base files
156
93
  files.forEach((file) => {
157
94
  const src = path.join(__dirname, 'files', file);
@@ -163,13 +100,6 @@ files.forEach((file) => {
163
100
  }
164
101
  });
165
102
 
166
- // require("child_process").spawn('yarn', ['install'], {
167
- // cwd: process.cwd(),
168
- // stdio: "inherit"
169
- // });
170
-
171
- // Update tsconfig
172
-
173
103
  const topLevelRawdata = fs.readFileSync(path.join(folder, 'package.json'));
174
104
  const topLevelPkg = JSON.parse(topLevelRawdata);
175
105
  let updated = false;
@@ -214,3 +144,5 @@ function updateArray(data) {
214
144
 
215
145
  return updated;
216
146
  }
147
+
148
+ /* eslint-enable no-console */
package/pkg/package.json CHANGED
@@ -10,31 +10,9 @@
10
10
  "**/*.*",
11
11
  "init"
12
12
  ],
13
- "rancher": {
14
- "annotations": {
15
- "catalog.cattle.io/rancher-version": ">= 2.9.0 < 2.10.0",
16
- "catalog.cattle.io/ui-extensions-version": "< 3.0.0"
17
- }
18
- },
19
13
  "engines": {
20
14
  "node": ">=16.0.0"
21
15
  },
22
- "resolutions": {
23
- "d3-color": "3.1.0",
24
- "ejs": "3.1.9",
25
- "follow-redirects": "1.15.2",
26
- "glob": "7.2.3",
27
- "glob-parent": "6.0.2",
28
- "json5": "2.2.3",
29
- "@types/lodash": "4.17.5",
30
- "merge": "2.1.1",
31
- "node-forge": "1.3.1",
32
- "nth-check": "2.1.1",
33
- "qs": "6.11.1",
34
- "roarr": "7.0.4",
35
- "semver": "7.5.4",
36
- "@vue/cli-service/html-webpack-plugin": "^5.0.0"
37
- },
38
16
  "dependencies": {
39
17
  "fs-extra": "^10.0.0"
40
18
  }
@@ -3,7 +3,12 @@
3
3
  "description": "NAME plugin",
4
4
  "version": "0.1.0",
5
5
  "private": false,
6
- "rancher": true,
6
+ "rancher": {
7
+ "annotations": {
8
+ "catalog.cattle.io/rancher-version": ">= 2.9.0 < 2.10.0",
9
+ "catalog.cattle.io/ui-extensions-version": "< 3.0.0"
10
+ }
11
+ },
7
12
  "scripts": {},
8
13
  "engines": {
9
14
  "node": ">=16"
@@ -11,26 +16,7 @@
11
16
  "devDependencies": {
12
17
  "@vue/cli-plugin-babel": "~5.0.0",
13
18
  "@vue/cli-service": "~5.0.0",
14
- "@vue/cli-plugin-typescript": "~5.0.0",
15
- "cache-loader": "^4.1.0",
16
- "color": "4.2.3",
17
- "ip": "2.0.1",
18
- "node-polyfill-webpack-plugin": "^3.0.0"
19
- },
20
- "resolutions": {
21
- "d3-color": "3.1.0",
22
- "ejs": "3.1.9",
23
- "follow-redirects": "1.15.2",
24
- "glob": "7.2.3",
25
- "glob-parent": "6.0.2",
26
- "json5": "2.2.3",
27
- "merge": "2.1.1",
28
- "node-forge": "1.3.1",
29
- "nth-check": "2.1.1",
30
- "qs": "6.11.1",
31
- "roarr": "7.0.4",
32
- "semver": "7.5.4",
33
- "@vue/cli-service/html-webpack-plugin": "^5.0.0"
19
+ "@vue/cli-plugin-typescript": "~5.0.0"
34
20
  },
35
21
  "browserslist": [
36
22
  "> 1%",
package/update/init CHANGED
@@ -4,17 +4,18 @@ const path = require('path');
4
4
  const fs = require('fs-extra');
5
5
  const { spawnSync } = require('child_process');
6
6
 
7
- const scriptFolder = __dirname;
7
+ const baseFolder = path.resolve(path.join(__dirname, '..'));
8
8
  const dest = path.resolve('.');
9
9
 
10
10
  // Remove first two args
11
- let args = process.argv;
11
+ const args = process.argv;
12
+
12
13
  args.splice(0, 2);
13
14
 
14
- const res = spawnSync(`${__dirname}/upgrade`, args, {
15
- cwd: dest,
15
+ const res = spawnSync(`${ __dirname }/upgrade`, args, {
16
+ cwd: dest,
16
17
  shell: false,
17
- stdio: [ 'ignore', process.stdout, process.stderr ],
18
+ stdio: ['ignore', process.stdout, process.stderr],
18
19
  });
19
20
 
20
21
  if (res.status !== 0) {
@@ -26,13 +27,9 @@ let rawdata = fs.readFileSync(path.join(dest, 'package.json'));
26
27
  const appPackage = JSON.parse(rawdata);
27
28
 
28
29
  // Read the package.json from the app creator
29
- rawdata = fs.readFileSync(path.join(scriptFolder, 'app', 'package.json'));
30
+ rawdata = fs.readFileSync(path.join(baseFolder, 'app', 'package.json'));
30
31
  const latestPackage = JSON.parse(rawdata);
31
32
 
32
- // Read the package.json from the upgrade creator
33
- rawdata = fs.readFileSync(path.join(scriptFolder, 'package.json'));
34
- const upgradePackage = JSON.parse(rawdata);
35
-
36
33
  // Update dependency versions to match the latest from the creator
37
34
  Object.keys(latestPackage._pkgs).forEach((key) => {
38
35
  appPackage.dependencies[key] = latestPackage._pkgs[key];
@@ -43,14 +40,14 @@ appPackage.resolutions = appPackage.resolutions || {};
43
40
  appPackage.resolutions['**/webpack'] = '4';
44
41
 
45
42
  // Update the version of @rancher/shell
46
- const shellVersion = upgradePackage.version;
43
+ const shellVersion = args[0];
47
44
 
48
45
  appPackage.dependencies['@rancher/shell'] = shellVersion;
49
46
 
50
- fs.writeFileSync(path.join(dest, 'package.json'), JSON.stringify(appPackage, null, 2) + '\n');
47
+ fs.writeFileSync(path.join(dest, 'package.json'), `${ JSON.stringify(appPackage, null, 2) }\n`);
51
48
 
52
49
  spawnSync(`yarn`, ['install'], {
53
- cwd: dest,
50
+ cwd: dest,
54
51
  shell: false,
55
- stdio: [ 'ignore', process.stdout, process.stderr ],
52
+ stdio: ['ignore', process.stdout, process.stderr],
56
53
  });
package/update/upgrade CHANGED
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
3
  SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
4
+ BASE_DIR="$(cd $SCRIPT_DIR && cd .. && pwd)"
4
5
 
5
6
  echo "Upgrading Rancher Shell"
6
7
 
7
8
  # Get the version number from the package.json file
8
- VERSION=$(node -p -e "require('${SCRIPT_DIR}/package.json').version")
9
-
9
+ VERSION=$1
10
10
  echo "Updating to version: ${VERSION}"
11
- echo ""
12
11
 
13
12
  FORCE="false"
14
13
 
15
- if [ "$1" == "-f" ]; then
16
- FORCE="true"
17
- fi
14
+ for i in "$@"; do
15
+ if [ "$i" == "-f" ]; then
16
+ FORCE="true"
17
+ fi
18
+ done
18
19
 
19
20
  # Check for a clean git repository
20
21
  if [ ! -d ".git" ] && [ "${FORCE}" == "false" ]; then
@@ -42,7 +43,7 @@ if [ "${HAS_SHELL}" != "1" ]; then
42
43
  fi
43
44
 
44
45
  # Copy files for the top-level folder (from the app creator)
45
- rsync --exclude nuxt.config.js ${SCRIPT_DIR}/app/files/* .
46
+ rsync --exclude nuxt.config.js --exclude .gitlab-ci.yml ${BASE_DIR}/app/files/* .
46
47
 
47
48
  # Go through each folder in the pkg folder and update their files
48
49
  for pkg in ./pkg/*
@@ -51,6 +52,6 @@ do
51
52
  pkgName=$(basename $pkg)
52
53
  echo "Updating package ${pkgName}"
53
54
 
54
- cp ${SCRIPT_DIR}/pkg/files/* ${pkg}
55
+ cp ${BASE_DIR}/pkg/files/* ${pkg}
55
56
  fi
56
57
  done