File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6262 "topics" : {
6363 "hello" : {
6464 "description" : " Say hello to the world and others"
65+ },
66+ "apply" : {
67+ "description" : " apply"
6568 }
6669 },
6770 "macos" : {
Original file line number Diff line number Diff line change 11import { Args , Command , Flags } from '@oclif/core'
2+ import path from 'node:path' ;
3+
4+ import { ApplyOrchestrator } from './orchestrator.js' ;
25
36export default class Apply extends Command {
47 static args = {
@@ -16,6 +19,8 @@ export default class Apply extends Command {
1619 force : Flags . boolean ( { char : 'f' } ) ,
1720 // flag with a value (-n, --name=VALUE)
1821 name : Flags . string ( { char : 'n' , description : 'name to print' } ) ,
22+ // flag with a value (-p, --path=VALUE)
23+ path : Flags . string ( { char : 'p' , description : 'path to project' } ) ,
1924 }
2025
2126 public async run ( ) : Promise < void > {
@@ -26,5 +31,12 @@ export default class Apply extends Command {
2631 if ( args . file && flags . force ) {
2732 this . log ( `you input --force and --file: ${ args . file } ` )
2833 }
34+
35+ if ( flags . path ) {
36+ this . log ( `Applying Codify from: ${ flags . path } ` ) ;
37+ }
38+
39+ const resolvedPath = path . resolve ( flags . path ?? '.' ) ;
40+ await ApplyOrchestrator . run ( resolvedPath ) ;
2941 }
3042}
Original file line number Diff line number Diff line change 1+ import readline from 'node:readline'
2+
3+ import { ConfigReader } from '../../config-compiler/index.js' ;
4+ import { PluginCollection } from '../../plugins/plugin-collection.js' ;
5+
6+ const rl = readline . createInterface ( {
7+ input : process . stdin ,
8+ output : process . stdout
9+ } ) ;
10+
11+
12+ export const ApplyOrchestrator = {
13+
14+ async run ( rootDirectory : string ) : Promise < string > {
15+ const project = await ConfigReader . parseProject ( rootDirectory ) ;
16+ if ( project . isEmpty ( ) ) {
17+ console . log ( 'Empty project. Taking no action' ) ;
18+ return '' ;
19+ }
20+
21+ const pluginCollection = new PluginCollection ( ) ;
22+ const dependencyMap = await pluginCollection . initialize ( project ) ;
23+ project . validateWithResourceMap ( dependencyMap ) ;
24+ project . resolveResourceDependencies ( dependencyMap ) ;
25+
26+ const validationResults = await pluginCollection . validate ( project ) ;
27+ project . handlePluginResourceValidationResults ( validationResults ) ;
28+ project . calculateEvaluationOrder ( ) ;
29+
30+ const plan = await pluginCollection . getPlan ( project ) ;
31+ console . log ( JSON . stringify ( plan , null , 2 ) ) ;
32+
33+ console . log ( 'Is this okay?' ) ;
34+
35+ for await ( const line of rl ) {
36+ if ( line === 'yes' ) {
37+ break ;
38+ } else {
39+ return '' ;
40+ }
41+ }
42+
43+ await pluginCollection . apply ( plan ) ;
44+ await pluginCollection . destroy ( ) ;
45+
46+ return '' ;
47+ } ,
48+ } ;
Original file line number Diff line number Diff line change 1- import { ConfigCompiler } from '../../config-compiler/index.js' ;
1+ import { ConfigReader } from '../../config-compiler/index.js' ;
22import { PluginCollection } from '../../plugins/plugin-collection.js' ;
33
44export const PlanOrchestrator = {
55 async run ( rootDirectory : string ) : Promise < string > {
6- const project = await ConfigCompiler . parseProject ( rootDirectory ) ;
6+ const project = await ConfigReader . parseProject ( rootDirectory ) ;
77 if ( project . isEmpty ( ) ) {
88 console . log ( 'Empty project. Taking no action' ) ;
99 return '' ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { ConfigLoader } from './loader/index.js';
77import { FileParser } from './parser/index.js' ;
88import { JsonFileParser } from './parser/json/file-parser.js' ;
99
10- export class ConfigCompiler {
10+ export class ConfigReader {
1111
1212 static readonly supportedParsers : Record < string , FileParser > = {
1313 'json' : new JsonFileParser ( ) ,
@@ -17,7 +17,7 @@ export class ConfigCompiler {
1717 const loadedProject = await ( new ConfigLoader ( ) . loadProject ( directory ) ) ;
1818
1919 const configBlocksResult = await Promise . all ( loadedProject . coreModule . files . map ( ( file ) => {
20- const parser = ConfigCompiler . supportedParsers [ file . fileType ] ;
20+ const parser = ConfigReader . supportedParsers [ file . fileType ] ;
2121 if ( ! parser ) {
2222 throw new InternalError ( `Unsupported file format loaded into parser: ${ file . fileName } ` ) ;
2323 }
Original file line number Diff line number Diff line change 11import * as fs from 'node:fs/promises' ;
22import * as path from 'node:path' ;
33
4- import { ConfigCompiler } from '../index.js' ;
4+ import { ConfigReader } from '../index.js' ;
55import { LoadedFile } from './entities/file.js' ;
66import { LoadedModule } from './entities/module.js' ;
77import { LoadedProject } from './entities/project.js' ;
@@ -37,7 +37,7 @@ export class ConfigLoader {
3737
3838 await Promise . all ( dir
3939 . map ( async ( fileName ) => {
40- const matchedParser = Object . entries ( ConfigCompiler . supportedParsers ) . find ( ( [ k ] ) => fileName . endsWith ( k ) )
40+ const matchedParser = Object . entries ( ConfigReader . supportedParsers ) . find ( ( [ k ] ) => fileName . endsWith ( k ) )
4141 if ( ! matchedParser ) {
4242 return ;
4343 }
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import { ResourceConfig } from './resource-config.js';
88export class Project {
99 projectConfig : ProjectConfig | null ;
1010 resourceConfigs : ResourceConfig [ ] ;
11-
1211 evaluationOrder : ResourceConfig [ ] = [ ] ;
1312
1413 constructor ( projectConfig : ProjectConfig | null , resourceConfigs : ResourceConfig [ ] ) {
Original file line number Diff line number Diff line change @@ -65,6 +65,10 @@ export class Plugin {
6565 return response ;
6666 }
6767
68+ async apply ( planId : string ) : Promise < void > {
69+ await this . ipcBridge ! . sendMessageForResult ( { cmd : 'apply' , data : { planId } } ) ;
70+ }
71+
6872 destroy ( ) {
6973 this . ipcBridge ! . killPlugin ( ) ;
7074 }
Original file line number Diff line number Diff line change @@ -61,6 +61,17 @@ export class PluginCollection {
6161 return result ;
6262 }
6363
64+ async apply ( planResponseData : PlanResponseData [ ] ) : Promise < void > {
65+ for ( const { planId, resourceType } of planResponseData ) {
66+ const pluginName = this . resourceToPluginMapping . get ( resourceType ) ;
67+ if ( ! pluginName ) {
68+ throw new Error ( `Internal error: unable to determine plugin for apply: ${ resourceType } ` ) ;
69+ }
70+
71+ await this . plugins . get ( pluginName ) ! . apply ( planId ) ;
72+ }
73+ }
74+
6475 async destroy ( ) : Promise < void > {
6576 for ( const plugin of this . plugins . values ( ) ) {
6677 plugin . destroy ( ) ;
You can’t perform that action at this time.
0 commit comments