Skip to content

Commit

Permalink
feat: apt command
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Mar 26, 2024
1 parent 21a57b8 commit 0194ae2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
48 changes: 35 additions & 13 deletions lib/commands/apt/build.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
import Command from "#lib/command";
import Command from "./command.js";
import glob from "#core/glob";
import fs from "node:fs";

export default class extends Command {
#packageSpec;
#codenames;

constructor ( { packageSpec, codenames } ) {
super();

this.#packageSpec = packageSpec;
this.#codenames = codenames;
// static
static cli () {
return {
"options": {
"codename": {
"description": "ubuntu codename",
"schema": {
"type": "array",
"items": {
"type": "string",
},
"uniqueItems": true,
},
},
},
"arguments": {
"package": {
"description": `Pacjage to build. Use "all" to build all packages.`,
"required": true,
"schema": {
"type": "string",
},
},
},
};
}

// public
async run () {
if ( !this.root ) return result( [ 5 - 0, `Unable to find root package` ] );

var packages;

if ( this.#packageSpec === "all" ) {
if ( process.cli.args.package === "all" ) {
packages = glob( "*", {
"cwd": this.resources + "/packages",
"cwd": this.root + "/packages",
} ).filter( name => !name.endsWith( ".disabled" ) );
}
else {
packages = [ this.#packageSpec ];
packages = [ process.cli.args.package ];
}

const res = this.getCodenames( this.#codenames );
const res = this.getCodenames( process.cli.options.codenames );
if ( !res.ok ) return res;

const codenames = res.data;

for ( const pkg of packages ) {
if ( fs.readFileSync( this.resources + "/packages/" + pkg, "utf8" ).includes( "ARCHITECTURE=all" ) ) {
if ( fs.readFileSync( this.root + "/packages/" + pkg, "utf8" ).includes( "ARCHITECTURE=all" ) ) {
const res = this.spawnSync( this.resources + "/build.sh", [ pkg ], {
"stdio": "inherit",
} );
if ( !res.ok ) return res;
}
else {

// XXX
for ( const codename of codenames ) {
const res = this.spawnSync(
"docker",
Expand Down
12 changes: 5 additions & 7 deletions lib/commands/apt/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import Command from "#lib/command";
import "#core/result";
import { readConfig } from "#core/config";
import childProcess from "node:child_process";
import { fileURLToPath } from "node:url";

export default class extends Command {
#rootPackage;
#config;
#codenames;
#resources;

constructor () {
super();
Expand All @@ -19,14 +21,10 @@ export default class extends Command {
return this.#rootPackage?.root;
}

// XXX
get dists () {
return this.root + "/dists";
}

// XXX
get resources () {
return this.root + "/resources";
this.#resources ??= fileURLToPath( import.meta.resolve( "#resources/apt" ) );

return this.#resources;
}

get config () {
Expand Down
5 changes: 5 additions & 0 deletions lib/commands/apt/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import ejs from "#core/ejs";

export default class extends Command {

// static
static cli () {
return;
}

// public
async run () {
var res;
Expand Down
4 changes: 2 additions & 2 deletions resources/apt/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

SCRIPT_DIR="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
ROOT=pwd

_DISTS=$SCRIPT_DIR/../dists
_DISTS=$ROOT/dists
_COMPONENT=main

# init
Expand Down

0 comments on commit 0194ae2

Please sign in to comment.