Skip to content

Commit

Permalink
Align pkg and app creators with master (#12756)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordojordo authored Dec 3, 2024
1 parent 267e9c2 commit 43b0a7a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 83 deletions.
23 changes: 3 additions & 20 deletions creators/extension/app/app.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@
"engines": {
"node": ">=16"
},
"dependencies": {
"cache-loader": "^4.1.0",
"color": "4.2.3",
"ip": "2.0.1",
"node-polyfill-webpack-plugin": "^3.0.0"
},
"dependencies": {},
"resolutions": {
"d3-color": "3.1.0",
"ejs": "3.1.9",
"follow-redirects": "1.15.2",
"glob": "7.2.3",
"glob-parent": "6.0.2",
"json5": "2.2.3",
"@types/lodash": "4.17.5",
"merge": "2.1.1",
"node-forge": "1.3.1",
"nth-check": "2.1.1",
"qs": "6.11.1",
"roarr": "7.0.4",
"semver": "7.5.4",
"@vue/cli-service/html-webpack-plugin": "^5.0.0"
"@types/node": "18.11.9",
"@types/lodash": "4.17.5"
}
}
34 changes: 32 additions & 2 deletions creators/extension/app/init
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const path = require('path');
const fs = require('fs-extra');
Expand Down Expand Up @@ -65,6 +66,7 @@ if ( addGitlabWorkflow ) {

let setName = false;

// Check that there is a package file
if (!fs.existsSync(path.join(appFolder, './package.json'))) {
console.log(' Adding package.json');
fs.copySync(path.join(__dirname, 'app.package.json'), path.join(appFolder, 'package.json'));
Expand Down Expand Up @@ -109,6 +111,32 @@ if (creatorPkg._pkgs) {

fs.writeFileSync(path.join(appFolder, 'package.json'), JSON.stringify(pkg, null, 2));

// Add workflow folder if needed
if ( addWorkflowFolder ) {
// Point to the workflow directory inside the skeleton application
const workflowDir = path.join(appFolder, '.github/workflows');

if ( !fs.existsSync(workflowDir) ) {
console.log(' Creating folder: .github/workflows');
fs.mkdirSync(workflowDir, { recursive: true });
}

const workflowFiles = [
'build-extension-catalog.yml',
'build-extension-charts.yml'
];

workflowFiles.forEach((fileName) => {
const dest = path.join(workflowDir, fileName); // Destination in the skeleton application
const src = path.join(__dirname, 'files/.github/workflows', fileName); // Source in the package

if ( !fs.existsSync(dest) ) {
console.log(` Adding file ${ fileName } to root workflows`);
fs.copySync(src, dest);
}
});
}

// Copy base files
files.forEach((file) => {
const destinationFile = file === 'gitignore' ? '.gitignore' : file;
Expand All @@ -118,7 +146,7 @@ files.forEach((file) => {
if (!fs.existsSync(dest)) {
console.log(` Adding file: ${ file }`);

const folder = path.dirname(file);
const folder = path.dirname(dest);

fs.ensureDirSync(folder);

Expand All @@ -127,4 +155,6 @@ files.forEach((file) => {
}
});

console.log('');
console.log('Skeleton Application creation complete.\n');

/* eslint-enable no-console */
4 changes: 2 additions & 2 deletions creators/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@rancher/create-extension",
"description": "Rancher UI Extension generator",
"version": "1.0.3",
"version": "1.0.4",
"license": "Apache-2.0",
"author": "SUSE",
"packageManager": "yarn@4.4.1",
"packageManager": "yarn@4.5.0",
"bin": {
"create-extension": "init"
},
Expand Down
64 changes: 6 additions & 58 deletions creators/extension/pkg/init
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const fs = require('fs-extra');
const path = require('path');

const targets = {
dev: './node_modules/.bin/nuxt dev',
nuxt: './node_modules/.bin/nuxt',
};

const files = [
'tsconfig.json',
'vue.config.js',
Expand Down Expand Up @@ -35,25 +31,18 @@ console.log('Creating Skeleton UI Package');

const args = process.argv;

if (args.length !== 3) {
console.log('Expected single argument of package name');
}

const name = args[2];
const folder = path.resolve('.');
const pkgFolder = path.join(folder, 'pkg', name);

let addTypeFolders = false;
let addWorkflowFolder = false;
let addTypeFolders = true;

if ( args.length >= 3 ) {
for ( let i = 3; i < args.length; i++ ) {
switch (args[i]) {
case '--skip-templates':
case '-t':
addTypeFolders = true;
break;
case '-w':
addWorkflowFolder = true;
addTypeFolders = false;
break;
default:
break;
Expand Down Expand Up @@ -82,19 +71,8 @@ const pkg = JSON.parse(rawdata);
pkg.name = name;
pkg.description = `${ name } plugin`;

Object.keys(targets).forEach((target) => {
if (!pkg.scripts[target]) {
pkg.scripts[target] = targets[target];
console.log(` Adding script '${ target }' to package.json`);
}
});

writePackageJson();

// Add dependencies
// pkg.dependencies['@rancher/shell'] = '^0.6.2';
// pkg.dependencies['core-js'] = '3.18.3';

function writePackageJson() {
fs.writeFileSync(path.join(pkgFolder, 'package.json'), JSON.stringify(pkg, null, 2));
}
Expand All @@ -111,31 +89,6 @@ if (addTypeFolders) {
});
}

// Add workflow folder if needed
if (addWorkflowFolder) {
const workflowDir = path.join(folder, '.github/workflows');

if (!fs.existsSync(workflowDir)) {
fs.mkdirSync(workflowDir, { recursive: true });
}

const files = [
'build-extension-catalog.yml',
'build-extension-charts.yml'
];

files.forEach((fileName) => {
const file = path.join(workflowDir, fileName);

if (!fs.existsSync(file)) {
const src = path.join(__dirname, 'files/.github/workflows', fileName);

console.log(` Adding file ${ fileName } to root workflows`);
fs.copySync(src, file);
}
});
}

// Copy base files
files.forEach((file) => {
const src = path.join(__dirname, 'files', file);
Expand All @@ -147,13 +100,6 @@ files.forEach((file) => {
}
});

// require("child_process").spawn('yarn', ['install'], {
// cwd: process.cwd(),
// stdio: "inherit"
// });

// Update tsconfig

const topLevelRawdata = fs.readFileSync(path.join(folder, 'package.json'));
const topLevelPkg = JSON.parse(topLevelRawdata);
let updated = false;
Expand Down Expand Up @@ -198,3 +144,5 @@ function updateArray(data) {

return updated;
}

/* eslint-enable no-console */
2 changes: 1 addition & 1 deletion creators/extension/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"init"
],
"engines": {
"node": ">=20.0.0"
"node": ">=16.0.0"
},
"dependencies": {
"fs-extra": "^10.0.0"
Expand Down

0 comments on commit 43b0a7a

Please sign in to comment.