11import { CreatePlan , Resource , ResourceSettings , SpawnStatus , getPty } from 'codify-plugin-lib' ;
2- import { ResourceConfig } from 'codify-schemas' ;
3- import * as fsSync from 'node:fs' ;
2+ import { OS , ResourceConfig } from 'codify-schemas' ;
43import * as fs from 'node:fs/promises' ;
54import os from 'node:os' ;
65import path from 'node:path' ;
76
8- import { codifySpawn } from '../../utils/codify-spawn.js' ;
97import { FileUtils } from '../../utils/file-utils.js' ;
108import { Utils } from '../../utils/index.js' ;
119import { MacportsInstallParameter , PortPackage } from './install-parameter.js' ;
@@ -33,6 +31,7 @@ export class MacportsResource extends Resource<MacportsConfig> {
3331 override getSettings ( ) : ResourceSettings < MacportsConfig > {
3432 return {
3533 id : 'macports' ,
34+ operatingSystems : [ OS . Darwin ] ,
3635 schema,
3736 parameterSettings : {
3837 install : { type : 'stateful' , definition : new MacportsInstallParameter ( ) }
@@ -52,7 +51,8 @@ export class MacportsResource extends Resource<MacportsConfig> {
5251 }
5352
5453 override async create ( plan : CreatePlan < MacportsConfig > ) : Promise < void > {
55- const macOSVersion = ( await codifySpawn ( 'sw_vers --productVersion' ) ) ?. data ?. split ( '.' ) ?. at ( 0 ) ;
54+ const $ = getPty ( ) ;
55+ const macOSVersion = ( await $ . spawn ( 'sw_vers --productVersion' ) ) ?. data ?. split ( '.' ) ?. at ( 0 ) ;
5656 if ( ! macOSVersion ) {
5757 throw new Error ( 'Unable to determine macOS version' ) ;
5858 }
@@ -68,17 +68,18 @@ export class MacportsResource extends Resource<MacportsConfig> {
6868 console . log ( `Downloading macports installer ${ installerUrl } ` )
6969 await Utils . downloadUrlIntoFile ( installerPath , installerUrl ) ;
7070
71- await codifySpawn ( `installer -pkg "${ installerPath } " -target /;` , { requiresRoot : true } )
71+ await $ . spawn ( `installer -pkg "${ installerPath } " -target /;` , { requiresRoot : true } )
7272
7373 await FileUtils . addToStartupFile ( '' )
7474 await FileUtils . addToStartupFile ( 'export PATH=/opt/local/bin:/opt/local/sbin:$PATH' )
7575 }
7676
7777 override async destroy ( ) : Promise < void > {
78- await codifySpawn ( 'port -fp uninstall installed' , { requiresRoot : true , throws : false } ) ;
79- await codifySpawn ( 'dscl . -delete /Users/macports' , { requiresRoot : true , throws : false } ) ;
80- await codifySpawn ( 'dscl . -delete /Groups/macports' , { requiresRoot : true , throws : false } ) ;
81- await codifySpawn ( 'rm -rf \\\n' +
78+ const $ = getPty ( ) ;
79+ await $ . spawnSafe ( 'port -fp uninstall installed' , { requiresRoot : true , interactive : true } ) ;
80+ await $ . spawnSafe ( 'dscl . -delete /Users/macports' , { requiresRoot : true } ) ;
81+ await $ . spawnSafe ( 'dscl . -delete /Groups/macports' , { requiresRoot : true } ) ;
82+ await $ . spawnSafe ( 'rm -rf \\\n' +
8283 ' /opt/local \\\n' +
8384 ' /Applications/DarwinPorts \\\n' +
8485 ' /Applications/MacPorts \\\n' +
@@ -88,7 +89,7 @@ export class MacportsResource extends Resource<MacportsConfig> {
8889 ' /Library/StartupItems/DarwinPortsStartup \\\n' +
8990 ' /Library/Tcl/darwinports1.0 \\\n' +
9091 ' /Library/Tcl/macports1.0 \\\n' +
91- ' ~/.macports' , { requiresRoot : true , throws : false } )
92+ ' ~/.macports' , { requiresRoot : true } )
9293
9394 await FileUtils . removeLineFromZshrc ( 'export PATH=/opt/local/bin:/opt/local/sbin:$PATH' ) ;
9495
0 commit comments