Skip to content

Commit

Permalink
Merge pull request crc-org#6 from evidolob/update-dev-flow
Browse files Browse the repository at this point in the history
feat: update development flow
  • Loading branch information
gbraad authored Mar 9, 2023
2 parents 3d82c40 + 394d89f commit 35288a7
Show file tree
Hide file tree
Showing 10 changed files with 527 additions and 50 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ This repo copied from [podman-desktop crc extension](https://github.com/containe

# Run and build

To build this extension use:

```shell
yarn desk:build
```

>Note: all command will check that parent directory contains [podman-desktop](https://github.com/containers/podman-desktop) repo, and if its doesn't, it will clone it.
If you want to prepare dev environment, use:
To prepare dev environment, use:

```shell
yarn desk:prepare
```
This command check/clone podman-desktop and replace existing crc extension with this one.
This command check/clone podman-desktop, delete existing crc extension, make links, build podman-desktop without builtin crc extension.

To launch podman-desktop with this crc extension use:

```shell
yarn desk:run
```

>Note: If you do any modification of code inside this repo, you need to rerun any command described above to copy your changes in to podman-desktop repo. Automatic update not implemented yet.
To rebuild podman-desktop and crc extension run:

```shell
yarn desk:build
```
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@
"desk:build": "node ./scripts/run.mjs build",
"desk:prepare": "node ./scripts/run.mjs prepare",
"desk:run": "node ./scripts/run.mjs run",
"desk:watch": "node ./scripts/run.mjs watch"
"desk:clean": "node ./scripts/run.mjs clean"
},
"dependencies": {
"@tmpwip/extension-api": "^0.0.1",
"got": "^12.5.3"
},
"devDependencies": {
"7zip-min": "^1.4.4",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^11.0.0",
"@types/node": "^18.14.6",
"mkdirp": "^2.1.3",
"rollup": "^3.18.0",
"tslib": "^2.5.0",
"typescript": "^4.9.5",
"zip-local": "^0.3.5"
}
}
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
sourcemap: true,
},
external: [
'@tmpwip/extension-api',
'@podman-desktop/api',
'node:stream',
'node:http',
'node:url',
Expand Down
6 changes: 5 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ if (fs.existsSync(builtinDirectory)) {
fs.rmSync(builtinDirectory, { recursive: true, force: true });
}

zipper.sync.zip(path.resolve(__dirname, '../')).compress().save(destFile);
const zip = zipper.sync.zip(path.resolve(__dirname, '../'));
zip.lowLevel().remove('assets');
zip.lowLevel().remove('.git');
zip.lowLevel().remove('node_modules');
zip.compress().save(destFile);

// create unzipped built-in
mkdirp(unzippedDirectory).then(() => {
Expand Down
95 changes: 64 additions & 31 deletions scripts/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'node:child_process';
import * as util from 'node:util';

// const exec = util.promisify(cp.exec);
import * as os from 'node:os';

import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const desktopPath = path.join(__dirname, '..', '..', 'podman-desktop');
let isNeedToInstallDependencies = false;

async function exec(command, args, options) {
return new Promise((resolve, reject) => {
if(os.platform() === 'win32'){
if(!options) {
options = {};
}

options.shell = true;
}
const proc = cp.spawn(command, args, options);
proc.stderr.pipe(process.stderr);
proc.stdout.pipe(process.stdout);
Expand All @@ -51,65 +55,94 @@ async function checkAndCloneDesktopRepo() {
if(!fs.existsSync(desktopPath)) {
console.log('Cloning podman-desktop repository...');
await exec('git', ['clone', 'https://github.com/containers/podman-desktop.git'], {cwd: path.join(__dirname, '..', '..')})
isNeedToInstallDependencies = true;
} else {
console.log('desktop repo already exist...');
}
}

function copyExt() {
function removeCrcExt() {
const crcExtPath = path.join(desktopPath, 'extensions', 'crc');
if(fs.existsSync(crcExtPath)){
console.log('Deleting old crc extensions');
console.log('Deleting old crc extension');
fs.rmSync(crcExtPath, {recursive: true});
}
fs.mkdirSync(crcExtPath);
const ourExtensionPath = path.join(__dirname, '..', '..', 'crc-extension');
console.log('Copying own crc extension...');
fs.cpSync(ourExtensionPath + path.sep, crcExtPath, {recursive: true});

console.log('All done, go ' + desktopPath + ' and run "yarn watch" to start podman-desktop with this extension.');
}

async function linkApi() {
console.log('Linking @podman-desktop/api...');
await exec('yarn',['link'], {cwd: path.join(desktopPath, 'packages', 'extension-api')});
await exec('yarn',['link', '@podman-desktop/api'], {cwd: path.join(__dirname, '..')});
}

async function unlinkApi() {
console.log('Unlinking @podman-desktop/api...');
await exec('yarn',['unlink'], {cwd: path.join(desktopPath, 'packages', 'extension-api')});
await exec('yarn',['unlink', '@podman-desktop/api'], {cwd: path.join(__dirname, '..')});
}

async function patchPDBuild() {
console.log('Removing crc build script from package.json...');
const filePath = path.resolve(desktopPath, 'package.json');
const content = fs.readFileSync(filePath);
const packageObj = JSON.parse(content.toString('utf8'));
packageObj.scripts['build:extensions:crc'] = '';
fs.writeFileSync(filePath, JSON.stringify(packageObj, undefined, ' '));
}

async function prepareDev() {
await checkAndCloneDesktopRepo();
copyExt();
if(isNeedToInstallDependencies){
console.warn('But first you need to call "yarn" to install dependencies');
}
removeCrcExt();
await patchPDBuild();
linkApi();
await exec('yarn',undefined, {cwd: desktopPath });
await buildPD();
await exec('yarn',[], {cwd: path.join(__dirname, '..')});
}

async function build() {
await checkAndCloneDesktopRepo();
copyExt();
async function buildPD() {
await exec('yarn',['compile:current'], {cwd: desktopPath});
}

await exec('yarn',undefined, {cwd: path.join(__dirname, '..', '..', 'podman-desktop'), });
await exec('yarn',['build'], {cwd: path.join(__dirname, '..', '..', 'podman-desktop')});
async function buildCrc() {
await exec('yarn',['build'], {cwd: path.join(__dirname, '..')});

const pluginsPath = path.resolve(os.homedir(), '.local/share/containers/podman-desktop/plugins/crc.cdix/');
fs.rmSync(pluginsPath, { recursive: true, force: true });

fs.mkdirSync(pluginsPath, {recursive: true});
fs.cpSync(path.resolve(__dirname,'..', 'builtin' ,'crc.cdix'), pluginsPath, {recursive: true});
}

async function run() {
copyExt();
await exec('yarn',['watch'], {cwd: path.join(__dirname, '..', '..', 'podman-desktop')});
async function build() {
await buildPD();
await buildCrc();
}

async function watch() {
throw new Error('Implement watch');
async function run() {
await buildCrc();

if(os.platform() === 'darwin') {
await exec('open', ['-W', '-a', path.resolve(desktopPath, 'dist', 'mac', 'Podman Desktop.app')]);
} else if(os.platform() === 'win32') {
await exec(path.resolve(desktopPath, 'dist', 'win-unpacked', '"Podman Desktop.exe"'));
} else {
throw new Error('Cannot launch Podman Desktop on ' + os.platform());
}
}

const firstArg = process.argv[2];

switch(firstArg) {
case 'watch':
await watch();
break;
case 'build':
await build();
break;

case 'run':
await run();
break;

case 'clean':
await unlinkApi();
break;
case 'prepare' :
default:
await prepareDev();
Expand Down
2 changes: 1 addition & 1 deletion src/crc-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ChildProcess } from 'node:child_process';
import { spawn } from 'node:child_process';
import { isMac, isWindows } from './util';

import type { Logger } from '@tmpwip/extension-api';
import type { Logger } from '@podman-desktop/api';

const macosExtraPath = '/usr/local/bin:/opt/local/bin';
const crcWindowsInstallPath = 'c:\\Program Files\\Red Hat OpenShift Local';
Expand Down
2 changes: 1 addition & 1 deletion src/detection-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { ProviderDetectionCheck } from '@tmpwip/extension-api';
import type { ProviderDetectionCheck } from '@podman-desktop/api';
import type { CrcVersion } from './crc-cli';
import { getInstallationPath } from './crc-cli';

Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import * as extensionApi from '@tmpwip/extension-api';
import * as extensionApi from '@podman-desktop/api';
import * as path from 'node:path';
import * as os from 'node:os';
import * as fs from 'node:fs';
Expand Down
2 changes: 1 addition & 1 deletion src/log-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { Logger } from '@tmpwip/extension-api';
import type { Logger } from '@podman-desktop/api';
import type { DaemonCommander } from './daemon-commander';

export class LogProvider {
Expand Down
Loading

0 comments on commit 35288a7

Please sign in to comment.