@aventusjs/cli 0.0.42 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Aventus@Main.package.avt +3084 -3077
- package/lib/Aventus@Sharp.package.avt +1099 -1099
- package/out/RealServer.js +1 -1
- package/out/cli.js +1 -1
- package/package.json +1 -1
package/out/RealServer.js
CHANGED
|
@@ -1093,5 +1093,5 @@ var n;return t=[Nl((n=t)[0]),Nl(n[1]),Nl(n[2])],t=Uc(Pl,t),t=qc(t),t}function nu
|
|
|
1093
1093
|
`),i+=t.join(`
|
|
1094
1094
|
|
|
1095
1095
|
`),{range:ds(e.documentInternal,n.textSpan),contents:{kind:`markdown`,value:i}}}}catch(e){this.printCatchError(e)}return null}async findDefinition(e,t){try{let n=this.languageService.getDefinitionAtPosition(e.uri,e.documentInternal.offsetAt(t));if(n&&n.length>0){let e=n[0],t=this.templateFiles[e.fileName];if(t)return[{uri:t.uri,range:ds(t.documentInternal,e.textSpan)}];let r=Pt(e.fileName);if(r){let t=d.TextDocument.create(e.fileName,`typescript`,1,r);return[{uri:e.fileName,range:ds(t,e.textSpan)}]}}}catch(e){this.printCatchError(e)}return null}async format(e,t,n,r=!0){try{let i=e.documentInternal,a=i.offsetAt(t.start),o=i.offsetAt(t.end),s=null;t.end.line>t.start.line&&(t.end.character===0||Pn(i.getText().substr(o-t.end.character,t.end.character)))&&(o-=t.end.character,s=m.Range.create(m.Position.create(t.end.line,0),t.end));let c={...Bp};r?c.semicolons=p.SemicolonPreference.Insert:c.semicolons=p.SemicolonPreference.Remove;let l=this.languageService.getFormattingEditsForRange(i.uri,a,o,c);if(l){let e=[];for(let t of l)t.span.start>=a&&t.span.start+t.span.length<=o&&e.push({range:ds(i,t.span),newText:t.newText});return s&&e.push({range:s,newText:Fn(0,n)}),e}}catch(e){this.printCatchError(e)}return[]}async doCodeAction(e,t){let n=[];try{let r=e.documentInternal,i=this.languageService.getSyntacticDiagnostics(r.uri),a=this.languageService.getSemanticDiagnostics(r.uri),o=[];for(let e of i)o.push(e.code);for(let e of a)e.code!=6133&&o.push(e.code);let s=[];try{s=this.languageService.getCodeFixesAtPosition(r.uri,r.offsetAt(t.start),r.offsetAt(t.end),o,Bp,zp)}catch{}for(let e of s){let t=[],i={changes:{[r.uri]:t}};for(let n of e.changes)for(let e of n.textChanges)t.push({newText:e.newText,range:ds(r,e.span)});n.push({title:e.description,edit:i})}}catch(e){this.printCatchError(e)}return n}async onReferences(e,t){let n=[];try{let r=e.documentInternal.offsetAt(t),i=this.languageService.findReferences(e.uri,r);for(let e of i??[])for(let t of e.references){let e=this.templateFiles[t.fileName];e&&n.push(m.Location.create(t.fileName,ds(e.documentInternal,t.textSpan)))}}catch(e){this.printCatchError(e)}return n}async onCodeLens(e){return[]}async onRename(e,t,n){try{let r=e.documentInternal.offsetAt(t);if(!this.languageService.getRenameInfo(e.uri,r,{}).canRename)return null;let i=this.languageService.findRenameLocations(e.uri,r,!1,!1,{});if(!i)return null;let a={};for(let e of i){let t=this.templateFiles[e.fileName];t&&(a[e.fileName]??=[]).push(m.TextEdit.replace(ds(t.documentInternal,e.textSpan),n))}return Object.keys(a).length?{changes:a}:null}catch(e){return this.printCatchError(e),null}}printCatchError(t){e.printCatchError(t)}static printCatchError(e){/^Debug Failure\. Expected \d+ <= \d+$/g.test(e.message)||console.error(e)}};const Rp={types:[`node`],module:p.ModuleKind.ES2022,allowNonTsExtensions:!0,jsx:p.JsxEmit.None,importHelpers:!1,allowJs:!0,checkJs:!1,lib:[`lib.es2025.full.d.ts`],target:p.ScriptTarget.ES2025,moduleDetection:p.ModuleDetectionKind.Force,moduleResolution:p.ModuleResolutionKind.NodeNext,experimentalDecorators:!0,noImplicitOverride:!0,strictPropertyInitialization:!0,noImplicitReturns:!0,noUnusedLocals:!0,strictNullChecks:!0,verbatimModuleSyntax:!1},zp={includeExternalModuleExports:!0,includeInsertTextCompletions:!0,includeCompletionsWithClassMemberSnippets:!0,includeAutomaticOptionalChainCompletions:!0,includeCompletionsForImportStatements:!0,includeCompletionsForModuleExports:!0,includeCompletionsWithInsertText:!0,includeInlayEnumMemberValueHints:!0,includeInlayFunctionLikeReturnTypeHints:!0,includeInlayFunctionParameterTypeHints:!0,includeInlayParameterNameHints:`all`,includeInlayParameterNameHintsWhenArgumentMatchesName:!0,includeInlayPropertyDeclarationTypeHints:!0,useLabelDetailsInCompletionEntries:!0,importModuleSpecifierEnding:`index`,importModuleSpecifierPreference:`relative`},Bp={convertTabsToSpaces:!0,tabSize:4,indentSize:4,indentStyle:p.IndentStyle.Smart,newLineCharacter:`
|
|
1096
|
-
`,baseIndentSize:0,insertSpaceAfterCommaDelimiter:!0,insertSpaceAfterConstructor:!1,insertSpaceAfterSemicolonInForStatements:!0,insertSpaceBeforeAndAfterBinaryOperators:!0,insertSpaceAfterKeywordsInControlFlowStatements:!1,insertSpaceAfterFunctionKeywordForAnonymousFunctions:!0,insertSpaceBeforeFunctionParenthesis:!1,insertSpaceAfterTypeAssertion:!0,placeOpenBraceOnNewLineForControlBlocks:!1,placeOpenBraceOnNewLineForFunctions:!1,semicolons:p.SemicolonPreference.Insert,insertSpaceBeforeTypeAnnotation:!1};var Vp=class extends it{languageService;constructor(e){super(e),this.languageService=new Lp,this.languageService.addFile(e)}async onValidate(){return this.languageService.doValidation(this.file)}async onContentChange(){}async onSave(){}onCompletion(e,t){return this.languageService.doComplete(e,t)}onCompletionResolve(e,t){return this.languageService.doResolve(t)}onHover(e,t){return this.languageService.doHover(e,t)}onDefinition(e,t){return this.languageService.findDefinition(e,t)}onFormatting(e,t,n){return this.languageService.format(e,t,n)}onCodeAction(e,t){return this.languageService.doCodeAction(e,t)}onReferences(e,t){return this.languageService.onReferences(e,t)}onCodeLens(e){return this.languageService.onCodeLens(e)}async onRename(e,t,n){return this.languageService.onRename(e,t,n)}async onDelete(){}onGetBuild(){return null}},Hp=class e{static instance;static getInstance(){return this.instance||=new e,this.instance}constructor(){z.getInstance().onNewFile(this.onNewFile.bind(this))}async onNewFile(e){e.documentUser.uri.endsWith(E.Template)&&(new Vp(e),e instanceof O&&await e.validate())}},Up=class{};const Wp={allCommunications:{},list:[class extends Up{channel(){return`aventus.i18n.getKeyFromPosition`}async run(e){if(e.uri){let t=P.getInstance().getMatchingBuildsByUri(e.uri);for(let n of t){let t=n.i18nComponentsFiles[e.uri]?.getKeyFromLocation(e.range);if(t||(t=n.tsLanguageService.i18nFiles[e.uri]?.getKeyFromLocation(e.range),t))return t}}return null}},class extends Up{channel(){return`aventus.i18n.getLocales`}async run(e){if(e.uri){let t=P.getInstance().getMatchingBuildsByUri(e.uri);for(let e of t){let t=e.buildConfig.i18n?.locales,n=e.buildConfig.i18n?.fallback;if(t&&n)return{fallback:n,locales:t}}}return null}}],isInit:!1,init:function(){if(!this.isInit){for(let e of this.list){let t=new e;this.allCommunications[t.channel()]=t}this.isInit=!0}},execute:function(e,t){this.init();let n=this.allCommunications[e];if(n)return t?Array.isArray(t)?n.run.call(n,...t):n.run.call(n,t):n.run.call(n)}};var Gp=class{templateManager;constructor(e){this.templateManager=e}async createGlobal(e){try{let t=await this.templateManager.readGlobal(),n=await this.templateManager.query(e,t.templates,[{label:`Init`,detail:`Create a project`}]);n instanceof to?await n.init(e,this.templateManager.findWorkspace(e)):n&&await this.createProject(e)}catch(e){if(!(e instanceof no))throw e;$.showWarningMessage(`No templates available for this location. Browse templates: https://store.aventusjs.com/templates`)}}async createProject(e){let t=await this.readProjects(),n=await this.templateManager.query(e,t.templates);n&&await n.init(e,this.templateManager.findWorkspace(e))}readProjects(){let e=this.templateManager.getGeneralProjects(),t=this.templateManager.getGeneralProjectsLength(),n=$.getWorkspaceUri();if(n){let r=L(n)+`/.aventus/projects`;return this.templateManager.readTemplates([r],e,t)}return{templates:e,nb:t}}};function Kp(){let e=$.savePath,t=(0,u.readdirSync)(e);for(let n of t)try{(0,u.statSync)((0,f.join)(e,n)).isDirectory()&&(0,u.rmSync)((0,f.join)(e,n),{recursive:!0,force:!0})}catch{}}function qp(){let e=(0,f.join)($.savePath,`packages`);(0,u.existsSync)(e)&&Jp(e)}function Jp(e){let t=(0,u.readdirSync)(e);for(let n of t)try{let t=(0,f.join)(e,n);if((0,u.lstatSync)(t).isDirectory())Jp(t);else if(n.endsWith(`.avt`)){let e=(0,u.readFileSync)(t,`utf8`);e=e.replace(/dependances/g,`dependencies`),(0,u.writeFileSync)(t,e)}}catch(e){console.error(e)}}const Yp={"1.4.0":Kp,"1.4.1":qp};var $=class e{static instance;static delayBetweenBuild(){return this.instance.connection.delayBetweenBuild()}static logLevel(){return this.instance.logLevel}static get isIDE(){return this.instance.isIDE}static sendNotification(t,...n){e.debug(`sendNotification `+t),this.instance.connection.sendNotification(t,n)}static showErrorMessage(t){e.debug(`showErrorMessage `+t),this.instance.connection.showErrorMessage(t)}static showWarningMessage(t){e.debug(`showWarningMessage `+t),this.instance.connection.showWarningMessage(t)}static showInformationMessage(t){e.debug(`showInformationMessage `+t),this.instance.connection.showInformationMessage(t)}static async showLoadingMessage(t,n){e.debug(`showLoadingMessage `+t),await this.instance.connection.showLoadingMessage(t,n)}static async ask(t){return e.debug(`ask `+t),await this.instance.connection.ask(t)}static sendDiagnostics(t,n){e.debug(`sendDiagnostics`),e.debug(t.uri);for(let n of t.diagnostics)e.debug(` `+n.message);this.instance.connection.sendDiagnostics(t,n?.buildConfig.fullname)}static Input(e){return this.instance.connection.Input(e)}static Select(e,t){return this.instance.connection.Select(e,t)}static SelectMultiple(e,t){return this.instance.connection.SelectMultiple(e,t)}static SelectFolder(e,t){return this.instance.connection.SelectFolder(e,t)}static Popup(e,...t){return this.instance.connection.Popup(e,...t)}static setSettings(e,t){return this.instance.connection.setSettings(e,t)}static get noBuild(){return this.instance._noBuild}static get savePath(){return this.instance._savePath}static get extensionPath(){return this.instance._extensionPath}static getWorkspaceUri(){return this.instance.workspaces[0]??``}static get templateManager(){return this.instance._template}static get localTemplateManager(){return this.instance._localTemplate}static get localProjectManager(){return this.instance._localProject}static refreshSettings(){return this.instance.loadSettings()}static debug(e){this.log(e,0)}static information(e){this.log(e,1)}static warning(e){this.log(e,2)}static error(e){this.writeLog(e)}static log(t,n){n>=e.logLevel()&&this.writeLog(t)}static writeLog(e){console.log(e),this.instance._logFile&&((typeof e==`object`||Array.isArray(e))&&(e=JSON.stringify(e,null,4)),(0,u.appendFileSync)((0,f.join)(this.instance._logFile),`[${new Date().toISOString()}] ${e}\n`))}connection;isLoading=!0;isDown=!1;workspaces=[];get logLevel(){return F.getInstance().settings.logLevel}isIDE=!1;_noBuild=!1;_savePath=``;_extensionPath=``;_logFile;_template;_localTemplate;_localProject;settingsLoadGeneration=0;constructor(t){e.instance=this,this.connection=t,this.bindEvent()}start(){this.connection.open()}bindEvent(){this.connection.onInitialize(t=>{this.onInitialize(t),e.debug(`onInitialize`)}),this.connection.onInitialized(async()=>{e.debug(`onInitialized`),await this.onInitialized()}),this.connection.onShutdown(async()=>{e.debug(`onShutdown`),await this.onShutdown()}),this.connection.onCompletion(async(t,n)=>(e.debug(`onCompletion`),await this.onCompletion(t,n))),this.connection.onCompletionResolve(async(t,n)=>(e.debug(`onCompletionResolve`),await this.onCompletionResolve(t,n))),this.connection.onHover(async(t,n)=>(e.debug(`onHover`),await this.onHover(t,n))),this.connection.onDefinition(async(t,n)=>(e.debug(`onDefinition`),await this.onDefinition(t,n))),this.connection.onDocumentFormatting(async(t,n)=>(e.debug(`onDocumentFormatting`),await this.onDocumentFormatting(t,n))),this.connection.onCodeAction(async(t,n)=>(e.debug(`onCodeAction`),await this.onCodeAction(t,n))),this.connection.onCodeLens(async t=>(e.debug(`onCodeLens`),await this.onCodeLens(t))),this.connection.onReferences(async(t,n)=>(e.debug(`onReferences`),await this.onReferences(t,n))),this.connection.onRenameRequest(async(t,n,r)=>(e.debug(`onRenameRequest`),await this.onRenameRequest(t,n,r))),this.connection.onDocumentColor(async t=>(e.debug(`onDocumentColor`),await this.onDocumentColor(t))),this.connection.onColorPresentation(async(t,n,r)=>(e.debug(`onColorPresentation`),await this.onColorPresentation(t,n,r))),this.connection.onExecuteCommand(async t=>(e.debug(`onExecuteCommand`),await this.onExecuteCommand(t))),this.connection.onDidChangeConfiguration(async()=>(e.debug(`onDidChangeConfiguration`),await this.onDidChangeConfiguration())),this.connection.onRequest(async(t,n)=>(e.debug(`onRequest`),await Wp.execute(t,n)))}onInitialize(t){if(t.workspaceFolders)for(let e of t.workspaceFolders)this.workspaces.push(e.uri);if(!t.savePath){let e=process.env.APPDATA||(process.platform==`darwin`?process.env.HOME+`/Library/Preferences`:process.env.HOME+`/.local/share`),n=(0,f.join)(e,`Code`,`User`,`globalStorage`,`cobwebsite.aventus`);(0,u.existsSync)(n)?t.savePath=n:t.savePath=(0,f.join)(e,`aventus`)}t.extensionPath||=(0,f.dirname)(__dirname),this._noBuild=t.noBuild??!1,this.isIDE=t.isIDE,this._savePath=t.savePath,this._extensionPath=t.extensionPath,this._logFile=t.logFile,this._logFile&&(0,u.writeFileSync)(this._logFile,``),this.isIDE&&this.runUpdate(),e.debug(t)}async onInitialized(){await this.checkNodeJs()&&(await this.loadSettings(),await this.startServer())}async onShutdown(){this.isDown=!0;let e=F.getInstance().settings,t=[],n=async(e,n)=>{try{await n()}catch(n){t.push(Error(`${e}: ${n}`))}};return e.watchFiles&&await n(`FilesWatcher`,()=>As.getInstance().destroy()),e.useCompilators&&(await n(`CSharpManager`,()=>xa.getInstance().destroy()),await n(`PhpManager`,()=>Na.getInstance().destroy())),await n(`ProjectManager`,()=>P.getInstance().destroyAll()),await n(`FilesManager`,()=>z.getInstance().onShutdown()),t}async onCompletion(e,t){return this.isAllowed(e)?await z.getInstance().onCompletion(e,t):null}async onCompletionResolve(e,t){return this.isAllowed(e)?await z.getInstance().onCompletionResolve(e,t):t}async onHover(e,t){return this.isAllowed(e)?await z.getInstance().onHover(e,t):null}async onDefinition(e,t){return this.isAllowed(e)?await z.getInstance().onDefinition(e,t):null}async onDocumentFormatting(e,t){return this.isAllowed(e)?await z.getInstance().onFormatting(e,t):null}async onCodeAction(e,t){return this.isAllowed(e)?await z.getInstance().onCodeAction(e,t):null}async onCodeLens(e){return this.isAllowed(e)?await z.getInstance().onCodeLens(e):null}async onReferences(e,t){return this.isAllowed(e)?await z.getInstance().onReferences(e,t):null}async onRenameRequest(e,t,n){return this.isAllowed(e)?await z.getInstance().onRename(e,t,n):null}async onDocumentColor(e){return e&&this.isStyleDocument(e)?Fp.onDocumentColor(e):null}async onColorPresentation(e,t,n){return e&&this.isStyleDocument(e)?Fp.onColorPresentations(e,t,n):null}async onExecuteCommand(e){await eo.execute(e)}async onDidChangeConfiguration(){await this.loadSettings()}isAllowed(t){return t?e.isAllowed(t):!1}static isAllowed(e){return this.instance.isDown||this.instance.isLoading?!1:!!(e.uri.endsWith(E.Base)||e.uri.endsWith(E.Config)||e.uri.endsWith(E.Template))}isStyleDocument(e){return!!(e.uri.endsWith(E.ComponentStyle)||e.uri.endsWith(E.Component)||e.uri.endsWith(E.GlobalStyle))}async loadSettings(){this.settingsLoadGeneration++;let e=this.settingsLoadGeneration,t=await this.connection.getSettings();t||={};let n=await this.connection.getSettingsHtml();n||={},e===this.settingsLoadGeneration&&(F.getInstance().initSettings(t),F.getInstance().setSettingsHtml(n))}async startServer(){let t=F.getInstance().settings;t.useTemplates&&(this._template=new io(this.workspaces),await this._template.init(),this._localTemplate=new Ip(this._template),this._localProject=new Gp(this._template)),t.useCompilators&&(xa.getInstance(),Na.getInstance()),P.getInstance(),Hp.getInstance(),t.loadFiles?t.buildOnly?t.configPath?await z.getInstance().loadConfigFile(t.configPath,t.builds,t.statics):await z.getInstance().loadConfigFileNotSet(this.workspaces,t.builds,t.statics):(await z.getInstance().loadAllAventusFiles(this.workspaces),await qa.write()):ks.sendDone(),this.isLoading=!1,e.debug(`start server done`)}runUpdate(){setTimeout(()=>{let t=`1.5.2`,n=F.getInstance().hiddenSettings.version;if(t==n||!/([0-9]+)\.([0-9]+)\.([0-9]+)/g.test(t)||!/([0-9]+)\.([0-9]+)\.([0-9]+)/g.test(n))return;let r=(e,t)=>{let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number),i=Math.max(n.length,r.length);for(let e=0;e<i;e++){let t=n[e]||0,i=r[e]||0;if(t>i)return 1;if(t<i)return-1}return 0},i=Yp;for(let a in i)if(/([0-9]+)\.([0-9]+)\.([0-9]+)/g.test(a)&&r(a,n)==1&&r(a,t)!=1)try{e.information(`Running update for `+a+` (old version : `+n+`, current version : 1.5.2)`),i[a]()}catch(e){console.error(e)}F.getInstance().setHiddenSettings({version:t})},5e3)}async checkNodeJs(){let t=(e,t)=>{let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if(n[e]>r[e])return!0;if(n[e]<r[e])return!1}return!0},{stdout:n}=await qo(`node -v`),r=n.toString().trim(),i=r.match(/^v?(\d+)\.(\d+)\.(\d+)$/),a=r.startsWith(`v`)?r.slice(1):r;return!i||!t(a,`22.18.0`)?(e.showErrorMessage(`To use Aventus, you need at least the nodejs version : 22.18.0`),!1):!0}},Xp=class{static cmd=`aventus/closefile`;static action(e){}},Zp=class e{static cmd=`aventus/compiled`;static timeByBuild={};static removeBuild(t){delete e.timeByBuild[t]}static action(t){let n=new Date,r=n.getHours();r<10&&(r=`0`+r);let i=n.getMinutes();i<10&&(i=`0`+i);let a=n.getSeconds();a<10&&(a=`0`+a);let o=r+`:`+i+`:`+a,s=t+` compiled at `+o;e.timeByBuild[t]=s}},Qp=class{static cmd=`aventus/editFile`;static async action(e){}},$p=class{static cmd=`aventus/server/start`;static callbacks=[];static action(e){let t=[...this.callbacks];for(let n of t)n(e)}},em=class{static cmd=`aventus/server/stop`;static action(){}},tm=class{static cmd=`aventus/initStep`;static doneTxt=`Aventus : Done`;static action(e){e=e.replace(`$(loading~spin)`,`◌`),e==this.doneTxt&&_m.started()}},nm=class{static cmd=`aventus/openfile`;static action(e){}},rm=class{static cmd=`aventus/registerBuild`;static action(e){e.pathConfig,e.buildName}},im=class{static cmd=`aventus/registerData`;static action(e){}},am=class{static cmd=`aventus/registerStatic`;static action(e){}},om=class e{static info={loadFileTime:0,builds:{},statics:{},files:{}};static loadFileTime={cmd:`aventus/statistics/loadFileTime`,action:t=>{e.info.loadFileTime=t}};static buildTime={cmd:`aventus/statistics/buildTime`,action:(t,n)=>{let r=e.info.builds;r[t]||(r[t]={buildTime:0}),r[t].buildTime=n}};static staticTime={cmd:`aventus/statistics/staticTime`,action:(t,n)=>{let r=e.info.statics;r[t]||(r[t]={buildTime:0}),r[t].buildTime=n}};static sizeFile={cmd:`aventus/statistics/fileSize`,action:(e,t,n,r)=>{this.info.files[e]={path:e,size:t,type:n,typeName:r}}}},sm=class{static cmd=`aventus/unregisterBuild`;static action(e){e.pathConfig,e.buildName}},cm=class{static cmd=`aventus/unregisterData`;static action(e){}},lm=class{static cmd=`aventus/unregisterStatic`;static action(e){}};const um={allNotifications:{[Xp.cmd]:Xp,[Zp.cmd]:Zp,[$p.cmd]:$p,[em.cmd]:em,[nm.cmd]:nm,[rm.cmd]:rm,[im.cmd]:im,[am.cmd]:am,[sm.cmd]:sm,[cm.cmd]:cm,[lm.cmd]:lm,[Qp.cmd]:Qp,[tm.cmd]:tm,[om.loadFileTime.cmd]:om.loadFileTime,[om.buildTime.cmd]:om.buildTime,[om.sizeFile.cmd]:om.sizeFile,[om.staticTime.cmd]:om.staticTime}};function dm(e){if(e.startsWith(`file://`))return e;let t=e[0].toLowerCase()+e.substring(1);return t=fm(encodeURI(t.replace(/\\/g,`/`))),f.sep===`/`?`file://`+t:`file:///`+t}function fm(e){return e.replace(/:/g,`%3A`).replace(/@/g,`%40`)}m.DiagnosticSeverity.Error,m.DiagnosticSeverity.Warning,m.DiagnosticSeverity.Information,m.DiagnosticSeverity.Hint;var pm=class{notifications=um;errorsByBuildByFile={};cbErrors=[];_connection;config;executeCommand;constructor(e){this._connection=new mm,this.config=e}async open(){this._connection.open()}delayBetweenBuild(){return 0}sendNotification(e,t){this.notifications.allNotifications[e]&&this.notifications.allNotifications[e].action.call(this.notifications.allNotifications[e],...t)}showErrorMessage(e){console.log(`[error] : `+e)}showWarningMessage(e){console.log(`[warning] : `+e)}showInformationMessage(e){console.log(`[info] : `+e)}async showLoadingMessage(e,t){process.stdout.write(e);let n=process.stdout.columns||80,r=e.split(`
|
|
1096
|
+
`,baseIndentSize:0,insertSpaceAfterCommaDelimiter:!0,insertSpaceAfterConstructor:!1,insertSpaceAfterSemicolonInForStatements:!0,insertSpaceBeforeAndAfterBinaryOperators:!0,insertSpaceAfterKeywordsInControlFlowStatements:!1,insertSpaceAfterFunctionKeywordForAnonymousFunctions:!0,insertSpaceBeforeFunctionParenthesis:!1,insertSpaceAfterTypeAssertion:!0,placeOpenBraceOnNewLineForControlBlocks:!1,placeOpenBraceOnNewLineForFunctions:!1,semicolons:p.SemicolonPreference.Insert,insertSpaceBeforeTypeAnnotation:!1};var Vp=class extends it{languageService;constructor(e){super(e),this.languageService=new Lp,this.languageService.addFile(e)}async onValidate(){return this.languageService.doValidation(this.file)}async onContentChange(){}async onSave(){}onCompletion(e,t){return this.languageService.doComplete(e,t)}onCompletionResolve(e,t){return this.languageService.doResolve(t)}onHover(e,t){return this.languageService.doHover(e,t)}onDefinition(e,t){return this.languageService.findDefinition(e,t)}onFormatting(e,t,n){return this.languageService.format(e,t,n)}onCodeAction(e,t){return this.languageService.doCodeAction(e,t)}onReferences(e,t){return this.languageService.onReferences(e,t)}onCodeLens(e){return this.languageService.onCodeLens(e)}async onRename(e,t,n){return this.languageService.onRename(e,t,n)}async onDelete(){}onGetBuild(){return null}},Hp=class e{static instance;static getInstance(){return this.instance||=new e,this.instance}constructor(){z.getInstance().onNewFile(this.onNewFile.bind(this))}async onNewFile(e){e.documentUser.uri.endsWith(E.Template)&&(new Vp(e),e instanceof O&&await e.validate())}},Up=class{};const Wp={allCommunications:{},list:[class extends Up{channel(){return`aventus.i18n.getKeyFromPosition`}async run(e){if(e.uri){let t=P.getInstance().getMatchingBuildsByUri(e.uri);for(let n of t){let t=n.i18nComponentsFiles[e.uri]?.getKeyFromLocation(e.range);if(t||(t=n.tsLanguageService.i18nFiles[e.uri]?.getKeyFromLocation(e.range),t))return t}}return null}},class extends Up{channel(){return`aventus.i18n.getLocales`}async run(e){if(e.uri){let t=P.getInstance().getMatchingBuildsByUri(e.uri);for(let e of t){let t=e.buildConfig.i18n?.locales,n=e.buildConfig.i18n?.fallback;if(t&&n)return{fallback:n,locales:t}}}return null}}],isInit:!1,init:function(){if(!this.isInit){for(let e of this.list){let t=new e;this.allCommunications[t.channel()]=t}this.isInit=!0}},execute:function(e,t){this.init();let n=this.allCommunications[e];if(n)return t?Array.isArray(t)?n.run.call(n,...t):n.run.call(n,t):n.run.call(n)}};var Gp=class{templateManager;constructor(e){this.templateManager=e}async createGlobal(e){try{let t=await this.templateManager.readGlobal(),n=await this.templateManager.query(e,t.templates,[{label:`Init`,detail:`Create a project`}]);n instanceof to?await n.init(e,this.templateManager.findWorkspace(e)):n&&await this.createProject(e)}catch(e){if(!(e instanceof no))throw e;$.showWarningMessage(`No templates available for this location. Browse templates: https://store.aventusjs.com/templates`)}}async createProject(e){let t=await this.readProjects(),n=await this.templateManager.query(e,t.templates);n&&await n.init(e,this.templateManager.findWorkspace(e))}readProjects(){let e=this.templateManager.getGeneralProjects(),t=this.templateManager.getGeneralProjectsLength(),n=$.getWorkspaceUri();if(n){let r=L(n)+`/.aventus/projects`;return this.templateManager.readTemplates([r],e,t)}return{templates:e,nb:t}}};function Kp(){let e=$.savePath,t=(0,u.readdirSync)(e);for(let n of t)try{(0,u.statSync)((0,f.join)(e,n)).isDirectory()&&(0,u.rmSync)((0,f.join)(e,n),{recursive:!0,force:!0})}catch{}}function qp(){let e=(0,f.join)($.savePath,`packages`);(0,u.existsSync)(e)&&Jp(e)}function Jp(e){let t=(0,u.readdirSync)(e);for(let n of t)try{let t=(0,f.join)(e,n);if((0,u.lstatSync)(t).isDirectory())Jp(t);else if(n.endsWith(`.avt`)){let e=(0,u.readFileSync)(t,`utf8`);e=e.replace(/dependances/g,`dependencies`),(0,u.writeFileSync)(t,e)}}catch(e){console.error(e)}}const Yp={"1.4.0":Kp,"1.4.1":qp};var $=class e{static instance;static delayBetweenBuild(){return this.instance.connection.delayBetweenBuild()}static logLevel(){return this.instance.logLevel}static get isIDE(){return this.instance.isIDE}static sendNotification(t,...n){e.debug(`sendNotification `+t),this.instance.connection.sendNotification(t,n)}static showErrorMessage(t){e.debug(`showErrorMessage `+t),this.instance.connection.showErrorMessage(t)}static showWarningMessage(t){e.debug(`showWarningMessage `+t),this.instance.connection.showWarningMessage(t)}static showInformationMessage(t){e.debug(`showInformationMessage `+t),this.instance.connection.showInformationMessage(t)}static async showLoadingMessage(t,n){e.debug(`showLoadingMessage `+t),await this.instance.connection.showLoadingMessage(t,n)}static async ask(t){return e.debug(`ask `+t),await this.instance.connection.ask(t)}static sendDiagnostics(t,n){e.debug(`sendDiagnostics`),e.debug(t.uri);for(let n of t.diagnostics)e.debug(` `+n.message);this.instance.connection.sendDiagnostics(t,n?.buildConfig.fullname)}static Input(e){return this.instance.connection.Input(e)}static Select(e,t){return this.instance.connection.Select(e,t)}static SelectMultiple(e,t){return this.instance.connection.SelectMultiple(e,t)}static SelectFolder(e,t){return this.instance.connection.SelectFolder(e,t)}static Popup(e,...t){return this.instance.connection.Popup(e,...t)}static setSettings(e,t){return this.instance.connection.setSettings(e,t)}static get noBuild(){return this.instance._noBuild}static get savePath(){return this.instance._savePath}static get extensionPath(){return this.instance._extensionPath}static getWorkspaceUri(){return this.instance.workspaces[0]??``}static get templateManager(){return this.instance._template}static get localTemplateManager(){return this.instance._localTemplate}static get localProjectManager(){return this.instance._localProject}static refreshSettings(){return this.instance.loadSettings()}static debug(e){this.log(e,0)}static information(e){this.log(e,1)}static warning(e){this.log(e,2)}static error(e){this.writeLog(e)}static log(t,n){n>=e.logLevel()&&this.writeLog(t)}static writeLog(e){console.log(e),this.instance._logFile&&((typeof e==`object`||Array.isArray(e))&&(e=JSON.stringify(e,null,4)),(0,u.appendFileSync)((0,f.join)(this.instance._logFile),`[${new Date().toISOString()}] ${e}\n`))}connection;isLoading=!0;isDown=!1;workspaces=[];get logLevel(){return F.getInstance().settings.logLevel}isIDE=!1;_noBuild=!1;_savePath=``;_extensionPath=``;_logFile;_template;_localTemplate;_localProject;settingsLoadGeneration=0;constructor(t){e.instance=this,this.connection=t,this.bindEvent()}start(){this.connection.open()}bindEvent(){this.connection.onInitialize(t=>{this.onInitialize(t),e.debug(`onInitialize`)}),this.connection.onInitialized(async()=>{e.debug(`onInitialized`),await this.onInitialized()}),this.connection.onShutdown(async()=>{e.debug(`onShutdown`),await this.onShutdown()}),this.connection.onCompletion(async(t,n)=>(e.debug(`onCompletion`),await this.onCompletion(t,n))),this.connection.onCompletionResolve(async(t,n)=>(e.debug(`onCompletionResolve`),await this.onCompletionResolve(t,n))),this.connection.onHover(async(t,n)=>(e.debug(`onHover`),await this.onHover(t,n))),this.connection.onDefinition(async(t,n)=>(e.debug(`onDefinition`),await this.onDefinition(t,n))),this.connection.onDocumentFormatting(async(t,n)=>(e.debug(`onDocumentFormatting`),await this.onDocumentFormatting(t,n))),this.connection.onCodeAction(async(t,n)=>(e.debug(`onCodeAction`),await this.onCodeAction(t,n))),this.connection.onCodeLens(async t=>(e.debug(`onCodeLens`),await this.onCodeLens(t))),this.connection.onReferences(async(t,n)=>(e.debug(`onReferences`),await this.onReferences(t,n))),this.connection.onRenameRequest(async(t,n,r)=>(e.debug(`onRenameRequest`),await this.onRenameRequest(t,n,r))),this.connection.onDocumentColor(async t=>(e.debug(`onDocumentColor`),await this.onDocumentColor(t))),this.connection.onColorPresentation(async(t,n,r)=>(e.debug(`onColorPresentation`),await this.onColorPresentation(t,n,r))),this.connection.onExecuteCommand(async t=>(e.debug(`onExecuteCommand`),await this.onExecuteCommand(t))),this.connection.onDidChangeConfiguration(async()=>(e.debug(`onDidChangeConfiguration`),await this.onDidChangeConfiguration())),this.connection.onRequest(async(t,n)=>(e.debug(`onRequest`),await Wp.execute(t,n)))}onInitialize(t){if(t.workspaceFolders)for(let e of t.workspaceFolders)this.workspaces.push(e.uri);if(!t.savePath){let e=process.env.APPDATA||(process.platform==`darwin`?process.env.HOME+`/Library/Preferences`:process.env.HOME+`/.local/share`),n=(0,f.join)(e,`Code`,`User`,`globalStorage`,`cobwebsite.aventus`);(0,u.existsSync)(n)?t.savePath=n:t.savePath=(0,f.join)(e,`aventus`)}t.extensionPath||=(0,f.dirname)(__dirname),this._noBuild=t.noBuild??!1,this.isIDE=t.isIDE,this._savePath=t.savePath,this._extensionPath=t.extensionPath,this._logFile=t.logFile,this._logFile&&(0,u.writeFileSync)(this._logFile,``),this.isIDE&&this.runUpdate(),e.debug(t)}async onInitialized(){await this.checkNodeJs()&&(await this.loadSettings(),await this.startServer())}async onShutdown(){this.isDown=!0;let e=F.getInstance().settings,t=[],n=async(e,n)=>{try{await n()}catch(n){t.push(Error(`${e}: ${n}`))}};return e.watchFiles&&await n(`FilesWatcher`,()=>As.getInstance().destroy()),e.useCompilators&&(await n(`CSharpManager`,()=>xa.getInstance().destroy()),await n(`PhpManager`,()=>Na.getInstance().destroy())),await n(`ProjectManager`,()=>P.getInstance().destroyAll()),await n(`FilesManager`,()=>z.getInstance().onShutdown()),t}async onCompletion(e,t){return this.isAllowed(e)?await z.getInstance().onCompletion(e,t):null}async onCompletionResolve(e,t){return this.isAllowed(e)?await z.getInstance().onCompletionResolve(e,t):t}async onHover(e,t){return this.isAllowed(e)?await z.getInstance().onHover(e,t):null}async onDefinition(e,t){return this.isAllowed(e)?await z.getInstance().onDefinition(e,t):null}async onDocumentFormatting(e,t){return this.isAllowed(e)?await z.getInstance().onFormatting(e,t):null}async onCodeAction(e,t){return this.isAllowed(e)?await z.getInstance().onCodeAction(e,t):null}async onCodeLens(e){return this.isAllowed(e)?await z.getInstance().onCodeLens(e):null}async onReferences(e,t){return this.isAllowed(e)?await z.getInstance().onReferences(e,t):null}async onRenameRequest(e,t,n){return this.isAllowed(e)?await z.getInstance().onRename(e,t,n):null}async onDocumentColor(e){return e&&this.isStyleDocument(e)?Fp.onDocumentColor(e):null}async onColorPresentation(e,t,n){return e&&this.isStyleDocument(e)?Fp.onColorPresentations(e,t,n):null}async onExecuteCommand(e){await eo.execute(e)}async onDidChangeConfiguration(){await this.loadSettings()}isAllowed(t){return t?e.isAllowed(t):!1}static isAllowed(e){return this.instance.isDown||this.instance.isLoading?!1:!!(e.uri.endsWith(E.Base)||e.uri.endsWith(E.Config)||e.uri.endsWith(E.Template))}isStyleDocument(e){return!!(e.uri.endsWith(E.ComponentStyle)||e.uri.endsWith(E.Component)||e.uri.endsWith(E.GlobalStyle))}async loadSettings(){this.settingsLoadGeneration++;let e=this.settingsLoadGeneration,t=await this.connection.getSettings();t||={};let n=await this.connection.getSettingsHtml();n||={},e===this.settingsLoadGeneration&&(F.getInstance().initSettings(t),F.getInstance().setSettingsHtml(n))}async startServer(){let t=F.getInstance().settings;t.useTemplates&&(this._template=new io(this.workspaces),await this._template.init(),this._localTemplate=new Ip(this._template),this._localProject=new Gp(this._template)),t.useCompilators&&(xa.getInstance(),Na.getInstance()),P.getInstance(),Hp.getInstance(),t.loadFiles?t.buildOnly?t.configPath?await z.getInstance().loadConfigFile(t.configPath,t.builds,t.statics):await z.getInstance().loadConfigFileNotSet(this.workspaces,t.builds,t.statics):(await z.getInstance().loadAllAventusFiles(this.workspaces),await qa.write()):ks.sendDone(),this.isLoading=!1,e.debug(`start server done`)}runUpdate(){setTimeout(()=>{let t=`1.5.3`,n=F.getInstance().hiddenSettings.version;if(t==n||!/([0-9]+)\.([0-9]+)\.([0-9]+)/g.test(t)||!/([0-9]+)\.([0-9]+)\.([0-9]+)/g.test(n))return;let r=(e,t)=>{let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number),i=Math.max(n.length,r.length);for(let e=0;e<i;e++){let t=n[e]||0,i=r[e]||0;if(t>i)return 1;if(t<i)return-1}return 0},i=Yp;for(let a in i)if(/([0-9]+)\.([0-9]+)\.([0-9]+)/g.test(a)&&r(a,n)==1&&r(a,t)!=1)try{e.information(`Running update for `+a+` (old version : `+n+`, current version : 1.5.3)`),i[a]()}catch(e){console.error(e)}F.getInstance().setHiddenSettings({version:t})},5e3)}async checkNodeJs(){let t=(e,t)=>{let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){if(n[e]>r[e])return!0;if(n[e]<r[e])return!1}return!0},{stdout:n}=await qo(`node -v`),r=n.toString().trim(),i=r.match(/^v?(\d+)\.(\d+)\.(\d+)$/),a=r.startsWith(`v`)?r.slice(1):r;return!i||!t(a,`22.18.0`)?(e.showErrorMessage(`To use Aventus, you need at least the nodejs version : 22.18.0`),!1):!0}},Xp=class{static cmd=`aventus/closefile`;static action(e){}},Zp=class e{static cmd=`aventus/compiled`;static timeByBuild={};static removeBuild(t){delete e.timeByBuild[t]}static action(t){let n=new Date,r=n.getHours();r<10&&(r=`0`+r);let i=n.getMinutes();i<10&&(i=`0`+i);let a=n.getSeconds();a<10&&(a=`0`+a);let o=r+`:`+i+`:`+a,s=t+` compiled at `+o;e.timeByBuild[t]=s}},Qp=class{static cmd=`aventus/editFile`;static async action(e){}},$p=class{static cmd=`aventus/server/start`;static callbacks=[];static action(e){let t=[...this.callbacks];for(let n of t)n(e)}},em=class{static cmd=`aventus/server/stop`;static action(){}},tm=class{static cmd=`aventus/initStep`;static doneTxt=`Aventus : Done`;static action(e){e=e.replace(`$(loading~spin)`,`◌`),e==this.doneTxt&&_m.started()}},nm=class{static cmd=`aventus/openfile`;static action(e){}},rm=class{static cmd=`aventus/registerBuild`;static action(e){e.pathConfig,e.buildName}},im=class{static cmd=`aventus/registerData`;static action(e){}},am=class{static cmd=`aventus/registerStatic`;static action(e){}},om=class e{static info={loadFileTime:0,builds:{},statics:{},files:{}};static loadFileTime={cmd:`aventus/statistics/loadFileTime`,action:t=>{e.info.loadFileTime=t}};static buildTime={cmd:`aventus/statistics/buildTime`,action:(t,n)=>{let r=e.info.builds;r[t]||(r[t]={buildTime:0}),r[t].buildTime=n}};static staticTime={cmd:`aventus/statistics/staticTime`,action:(t,n)=>{let r=e.info.statics;r[t]||(r[t]={buildTime:0}),r[t].buildTime=n}};static sizeFile={cmd:`aventus/statistics/fileSize`,action:(e,t,n,r)=>{this.info.files[e]={path:e,size:t,type:n,typeName:r}}}},sm=class{static cmd=`aventus/unregisterBuild`;static action(e){e.pathConfig,e.buildName}},cm=class{static cmd=`aventus/unregisterData`;static action(e){}},lm=class{static cmd=`aventus/unregisterStatic`;static action(e){}};const um={allNotifications:{[Xp.cmd]:Xp,[Zp.cmd]:Zp,[$p.cmd]:$p,[em.cmd]:em,[nm.cmd]:nm,[rm.cmd]:rm,[im.cmd]:im,[am.cmd]:am,[sm.cmd]:sm,[cm.cmd]:cm,[lm.cmd]:lm,[Qp.cmd]:Qp,[tm.cmd]:tm,[om.loadFileTime.cmd]:om.loadFileTime,[om.buildTime.cmd]:om.buildTime,[om.sizeFile.cmd]:om.sizeFile,[om.staticTime.cmd]:om.staticTime}};function dm(e){if(e.startsWith(`file://`))return e;let t=e[0].toLowerCase()+e.substring(1);return t=fm(encodeURI(t.replace(/\\/g,`/`))),f.sep===`/`?`file://`+t:`file:///`+t}function fm(e){return e.replace(/:/g,`%3A`).replace(/@/g,`%40`)}m.DiagnosticSeverity.Error,m.DiagnosticSeverity.Warning,m.DiagnosticSeverity.Information,m.DiagnosticSeverity.Hint;var pm=class{notifications=um;errorsByBuildByFile={};cbErrors=[];_connection;config;executeCommand;constructor(e){this._connection=new mm,this.config=e}async open(){this._connection.open()}delayBetweenBuild(){return 0}sendNotification(e,t){this.notifications.allNotifications[e]&&this.notifications.allNotifications[e].action.call(this.notifications.allNotifications[e],...t)}showErrorMessage(e){console.log(`[error] : `+e)}showWarningMessage(e){console.log(`[warning] : `+e)}showInformationMessage(e){console.log(`[info] : `+e)}async showLoadingMessage(e,t){process.stdout.write(e);let n=process.stdout.columns||80,r=e.split(`
|
|
1097
1097
|
`),i=0;for(let e of r)i+=Math.max(1,Math.ceil(e.length/n));try{await t();for(let e=0;e<i;e++)ge.default.clearLine(process.stdout,0),ge.default.cursorTo(process.stdout,0),e<i-1&&ge.default.moveCursor(process.stdout,0,-1)}catch(e){console.error(e)}}async ask(e){return(await this.Select([{label:`Yes`},{label:`No`}],{title:e}))?.label==`Yes`}subscribeErrors(e){this.cbErrors.push(e)}unsubscribeErrors(e){let t=this.cbErrors.indexOf(e);t>-1&&this.cbErrors.splice(t,1)}emitErrors(){for(let e in this.errorsByBuildByFile)for(let t of this.cbErrors)t(this.errorsByBuildByFile[e],e)}sendDiagnostics(e,t){let n=t=>{e.diagnostics&&e.diagnostics.length>0?t[e.uri]=e.diagnostics:t[e.uri]&&delete t[e.uri]};if(t&&this.config.errorByBuild){this.errorsByBuildByFile[t]||(this.errorsByBuildByFile[t]={});let e=this.errorsByBuildByFile[t];n(e)}else this.errorsByBuildByFile[``]||(this.errorsByBuildByFile[``]={}),n(this.errorsByBuildByFile[``]);this.emitErrors()}onInitialize(e){let t={extensionPath:(0,f.dirname)(__dirname),isIDE:!1,noBuild:this.config.noBuild,workspaceFolders:[{name:``,uri:dm(process.cwd())}]};this._connection.onInitialize(()=>{e(t)})}onInitialized(e){this._connection.onInitialized(()=>{e()})}onShutdown(e){this._connection.onShutdown(()=>{e()})}async getSettings(){return{watchFiles:this.config.watchFiles??!1,useCompilators:this.config.useCompilators??!1,useTemplates:this.config.useTemplates??!1,buildOnly:this.config.buildOnly??!0,loadFiles:this.config.loadFiles??!1,builds:this.config.builds,statics:this.config.statics,configPath:this.config.configPath,logLevel:this.config.logLevel,errorByBuild:this.config.errorByBuild,useStats:this.config.useStats}}async getSettingsHtml(){return{}}async setSettings(e,t){}onRequest(e){}async onCompletion(e){}async onCompletionResolve(e){}async onHover(e){}async onDefinition(e){}async onDocumentFormatting(e){}async onCodeAction(e){}async onCodeLens(e){}async onReferences(e){}async onRenameRequest(e){}async onDocumentColor(e){}async onColorPresentation(e){}onExecuteCommand(e){this.executeCommand=e}onDidChangeConfiguration(e){}async Input(e){let t;if(e.validations){let n=[];if(e.validations){let t=e=>{n.push(t=>t.match(new RegExp(e.regex))?null:e.message)};for(let n of e.validations)t(n)}t=async e=>{for(let t of n){let n=t(e);if(n!==null)return n}return!0}}if(e.password)return await _m.interaction.password(e.title,t);let n=``;return e.title&&(n+=e.title),e.placeHolder&&(n!=``&&(n+=` - `),n+=e.placeHolder),await _m.interaction.input(n,e.value,t)}async Select(e,t){let n=``;t.title&&(n+=t.title),t.placeHolder&&(n!=``&&(n+=` - `),n+=t.placeHolder);let r=[];for(let t=0;t<e.length;t++){let n=e[t],i=n.detail?n.label+` - `+n.detail:n.label;r.push({value:String(t),name:i,checked:n.picked??!1})}let i=await _m.interaction.select(n,r);return i===null?null:e[Number(i)]??null}async SelectMultiple(e,t){let n=``;t.title&&(n+=t.title),t.placeHolder&&(n!=``&&(n+=` - `),n+=t.placeHolder);let r=[];for(let t=0;t<e.length;t++){let n=e[t],i=n.detail?n.label+` - `+n.detail:n.label;r.push({value:String(t),name:i,checked:n.picked??!1})}let i=await _m.interaction.selectMultiple(n,r);if(!i)return null;let a=[];for(let t of i){let n=e[Number(t)];n!==void 0&&a.push(n)}return a.length>0?a:null}async Popup(e,...t){if(t.length>0){let n=[];for(let e of t)n.push({value:e,name:e,checked:!1});return await _m.interaction.select(e,n)}else return console.log(e),null}async SelectFolder(e,t){return await _m.interaction.tree(e,`directory`,t)}},mm=class{open(){this.run(this.onInitializeCb),this.run(this.onInitializedCb)}onInitializeCb=[];onInitialize(e){this.onInitializeCb.push(e)}onInitializedCb=[];onInitialized(e){this.onInitializedCb.push(e)}stop(){this.run(this.onShutdownCb)}onShutdownCb=[];onShutdown(e){this.onShutdownCb.push(e)}run(e){for(let t of e)t()}},hm=class{watcher;stack={created:[],deleted:[],updated:[]};mutex=new gm;timeout;stopped=!1;closing;stop(){return this.closing?this.closing:(this.stopped=!0,clearTimeout(this.timeout),this.timeout=void 0,this.stack={created:[],deleted:[],updated:[]},this.closing=this.watcher.close(),this.closing)}constructor(e){this.watcher=(0,me.watch)(e,{ignored:/(^|[\/\\])\../,persistent:!0}),this.watcher.on(`add`,this.onCreate.bind(this)).on(`change`,this.onChange.bind(this)).on(`unlink`,this.onDelete.bind(this))}async onCreate(e){if(this.stopped||!e.endsWith(`.avt`))return;if(await this.mutex.waitOne(),this.stopped){this.mutex.release();return}let t=e.toString();this.stack.created.includes(t)||this.stack.created.push(t);let n=this.stack.updated.indexOf(t);n!=-1&&this.stack.updated.splice(n,1);let r=this.stack.deleted.indexOf(t);r!=-1&&this.stack.deleted.splice(r,1),this.mutex.release(),this.triggerTimer()}async onChange(e){if(this.stopped||!e.endsWith(`.avt`))return;if(await this.mutex.waitOne(),this.stopped){this.mutex.release();return}let t=e.toString();!this.stack.created.includes(t)&&!this.stack.updated.includes(t)&&this.stack.updated.push(t);let n=this.stack.deleted.indexOf(t);n!=-1&&this.stack.deleted.splice(n,1),this.mutex.release(),this.triggerTimer()}async onDelete(e){if(this.stopped||!e.endsWith(`.avt`))return;if(await this.mutex.waitOne(),this.stopped){this.mutex.release();return}let t=e.toString();this.stack.deleted.includes(t)||this.stack.deleted.push(t);let n=this.stack.updated.indexOf(t);n!=-1&&this.stack.updated.splice(n,1);let r=this.stack.created.indexOf(t);r!=-1&&this.stack.created.splice(r,1),this.mutex.release(),this.triggerTimer()}triggerTimer(){this.stopped||(clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.timeout=void 0,this.sendStack()},500))}async sendStack(){if(await this.mutex.waitOne(),this.stopped){this.mutex.release();return}try{await Ui.run({deleted:this.stack.deleted.map(I),created:this.stack.created.map(I),updated:this.stack.updated.map(I)}),this.stack={created:[],deleted:[],updated:[]}}finally{this.mutex.release()}}},gm=class{waitingList=[];isLocked=!1;waitOne(){return new Promise(e=>{this.isLocked?this.waitingList.push(()=>{e()}):(this.isLocked=!0,e())})}release(){let e=this.waitingList.shift();e?e():this.isLocked=!1}dispose(){this.waitingList=[],this.isLocked=!1}},_m=class{static _interaction;static get interaction(){return this._interaction}static server=null;static cliConnection=null;static filesWatcher=null;static get connection(){return this.cliConnection?this.cliConnection._connection:null}static get notifications(){return this.cliConnection?.notifications}static waitingStart=null;static start(e){return new Promise((t,n)=>{try{if(!this.server)this.cliConnection=new pm(e),e.watchFiles&&(this.filesWatcher=new hm(process.cwd())),this.server=new $(this.cliConnection),e.noStart?t():(this.waitingStart=()=>{this.waitingStart=null,t()},this.server.start());else if(this.waitingStart){let e=this.waitingStart;this.waitingStart=()=>{e(),t()}}else t()}catch(e){this.waitingStart=null,this.server=null,this.cliConnection=null;let t=this.filesWatcher;this.filesWatcher=null,t?t.stop().then(()=>n(e),()=>n(e)):n(e)}})}static started(){this.waitingStart&&this.waitingStart()}static async create(){await Hi.run(I(process.cwd()))}static stop(){this.connection&&this.connection.stop()}static async log(){await this.interaction.log()}static subscribeErrors(e){this.cliConnection?.subscribeErrors(e)}static unsubscribeErrors(e){this.cliConnection?.unsubscribeErrors(e)}static async executeCommand(e,...t){await this.cliConnection.executeCommand({command:e,arguments:t})}static getErrors(){return this.cliConnection?.errorsByBuildByFile??{}}static getStatistics(){return om.info}static async Input(e){return this.cliConnection.Input(e)}};exports.RealServer=_m;
|
package/out/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
let e=require("commander"),t=require("path"),n=require("vscode-languageserver"),r=require("child_process"),i=require("fs");var a=class{static realInteraction;static async load(e){let t=eval;this.realInteraction=(await t(`import("./RealInteraction.js")`)).default.RealInteraction,this.realInteraction._server=o,e&&(this.realInteraction.config=e)}static async init(){this.clear(),console.log(`Welcome inside Aventus CLI`)}static clear(){this.realInteraction.clear()}static async select(e,t){return this.realInteraction?.select(e,t)||null}static async selectMultiple(e,t){return this.realInteraction?.selectMultiple(e,t)||null}static async input(e,t,n){return this.realInteraction?.input(e,t,n)||null}static async password(e,t){return this.realInteraction?.password(e,t)||null}static async tree(e,t,n){return this.realInteraction?.tree(e,t,n)||null}static async log(){return this.realInteraction?.log()||null}},o=class{static realServer;static get notifications(){return this.realServer?.notifications}static async load(){let e=eval;this.realServer=(await e(`import("./RealServer.js")`)).default.RealServer,this.realServer._interaction=a}static subscribeErrors(e){return this.realServer?.subscribeErrors(e)}static unsubscribeErrors(e){return this.realServer?.unsubscribeErrors(e)}static executeCommand(e,...t){return this.realServer?.executeCommand(e,...t)}static getErrors(){return this.realServer?.getErrors()}static start(e){return this.realServer?.start(e)}static create(){return this.realServer?.create()}static getStatistics(){return this.realServer?.getStatistics()}static async Input(e){return this.realServer?.Input(e)}},s=class e{static actions={};argsNb=0;register(t){let n=this.name.trim().split(` `),r=``,i=t;for(let t of n)r+=t,e.actions[r]||(e.actions[r]=i.command(t)),i=e.actions[r],r+=` `;i=i.description(this.description),i=this._registerArgs(i),i=this._registerOptions(i),i.action(async(...e)=>{let t=[];for(let n=0;n<this.argsNb;n++)t.push(e[n]);let n=e[this.argsNb];await this.run(t,n),process.exit(0)})}_registerArgs(e){return this.registerArgs(t=>{let n=``;if(t.type){let e=`<`,r=`>`;t.typeIsRequired!==void 0&&!t.typeIsRequired&&(e=`[`,r=`]`),t.typeIsArray&&(r=`...`+r),n+=`${e}${t.type}${r}`}this.argsNb++,e=e.argument(n,t.description,t.defaultValue)}),e}_registerOptions(e){let t=new Set,n=[];return this.registerOptions(r=>{let i=r.name;e.on(`option:${i}`,()=>t.add(i));for(let e of r.conflicts?[].concat(r.conflicts):[])n.push([i,e]);let a=[];if(r.shortName){Array.isArray(r.shortName)||(r.shortName=[r.shortName]);for(let e of r.shortName)a.push(`-`+e)}a.push(`--`+r.name);let o=a.join(`, `);if(r.type){let e=`<`,t=`>`;r.typeIsRequired!==void 0&&!r.typeIsRequired&&(e=`[`,t=`]`),r.typeIsArray&&(t=`...`+t),o+=` ${e}${r.type}${t}`}e=r.required?e.requiredOption(o,r.description,r.defaultValue):e.option(o,r.description,r.defaultValue)}),e.hook(`preAction`,()=>{let r=n.find(([e,n])=>t.has(e)&&t.has(n));t.clear(),r&&e.error(`options '--${r[0]}' and '--${r[1]}' cannot be used together`,{code:`commander.conflictingOption`})}),e}},c=class{register(e){let t=this.name.trim().split(` `),n=``,r=e;for(let e of t)n+=e,s.actions[n]||(s.actions[n]=r.command(e)),r=s.actions[n],n+=` `;r=r.description(this.description)}};function l(e){return t.sep===`/`?decodeURIComponent(e.replace(`file://`,``)):decodeURIComponent(e.replace(`file:///`,``))}function u(e){if(e.startsWith(`file://`))return e;let n=e[0].toLowerCase()+e.substring(1);return n=d(encodeURI(n.replace(/\\/g,`/`))),t.sep===`/`?`file://`+n:`file:///`+n}function d(e){return e.replace(/:/g,`%3A`).replace(/@/g,`%40`)}function f(e){let t=1024,n=[`Bytes`,`KiB`,`MiB`,`GiB`,`TiB`,`PiB`,`EiB`,`ZiB`,`YiB`],r=e==0?0:Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`}const p={Error:n.DiagnosticSeverity.Error,Warning:n.DiagnosticSeverity.Warning,Information:n.DiagnosticSeverity.Information,Hint:n.DiagnosticSeverity.Hint};var m=class extends s{get name(){return`build`}get description(){return`Build an aventus project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){e({name:`builds`,conflicts:`no-builds`,description:`Define the build name`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`no-builds`,description:`No builds`,type:`boolean`,typeIsRequired:!1}),e({name:`statics`,conflicts:`no-statics`,description:`Define the static files to export`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`no-statics`,description:`No statics`,type:`boolean`,typeIsRequired:!1}),e({name:`verbose`,conflicts:`silent`,shortName:`v`,description:`Debug your compilation`}),e({name:`silent`,shortName:`s`,description:`No output`}),e({name:`json`,type:`boolean`,typeIsRequired:!1,description:`Result as json`})}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),await o.load(),n.builds===!1&&(n.builds=[]),n.statics===!1&&(n.statics=[]),await o.start({configPath:r,loadFiles:!0,buildOnly:n[`no-statics`],noBuild:n[`no-builds`],builds:n.builds,statics:n.statics,logLevel:n.verbose?0:3,errorByBuild:!0,useStats:!n.silent}),n.json?this.handleResultJson(n):this.handleResult(n)}handleResult(e){let t=o.getStatistics(),n=e.silent?e=>{}:console.log;n(),n(`Loading all files : Done in `+t.loadFileTime+`ms`),n(),n(`----`),n();let r=o.getErrors(),i=!1;if(r[``])for(let t in r[``])for(let n of r[``][t])n.severity===p.Error&&(i=!0),e.silent||console.error(`${l(t)}:${n.range.start.line+1} : ${n.message}`);let a={},s={};for(let e in t.files){let n=t.files[e];if(n.type==`build`&&n.typeName){a[n.typeName]||(a[n.typeName]=[]);let e=` ${n.path} - ${f(n.size)}`;a[n.typeName].push(e)}else if(n.type==`static`&&n.typeName){s[n.typeName]||(s[n.typeName]=[]);let e=` ${n.path} - ${f(n.size)}`;s[n.typeName].push(e)}}let c=Object.keys(t.builds).length,u=Object.keys(t.statics).length,d=0;for(let o in t.builds){n(`Building `+o),n();let s=!1,f=r[o],m=t.builds[o],h=a[o];if(h){for(let e of h)n(e);n()}if(f){let t=!1;for(let n in f)for(let r of f[n]){let i=``,a;if(r.severity==p.Error)i=`\x1B[31m[error]\x1B[0m`,s=!0,a=console.error;else if(r.severity==p.Warning)i=`\x1B[33m[warning]\x1B[0m`,a=console.warn;else if(r.severity==p.Information)i=`\x1B[34m[info]\x1B[0m`,a=console.info;else if(r.severity==p.Hint){i=`\x1B[90m[hint]\x1B[0m`;continue}e.silent||(a(` ${i} ${l(n).replace(/\\/g,`/`)}:${r.range.start.line+1} : ${r.message}`),t=!0)}t&&n()}s?(n(` Build failed in `+m.buildTime+`ms`),i=!0):n(` Build success in `+m.buildTime+`ms`),d++,d==c&&u==0?n():(n(),n(`----`),n())}d=0;for(let e in t.statics){n(`Export static `+e),n();let r=t.statics[e],i=s[e];if(i){for(let e of i)n(e);n()}n(` Exported in `+r.buildTime+`ms`),d++,d==u?n():(n(),n(`----`),n())}i&&process.exit(1)}handleResultJson(e){let t=o.getStatistics(),n={success:!0,builds:{},statics:{}},r=o.getErrors(),i=!1;if(r[``])for(let e in r[``]){let t=l(e).replace(/\\/g,`/`);n.diagnostics||={},n.diagnostics[t]=[];for(let a of r[``][e])a.severity===p.Error&&(n.success=!1,i=!0),n.diagnostics[t].push({content:a.message,type:a.severity===p.Error?`error`:a.severity===p.Warning?`warning`:a.severity===p.Information?`info`:`hint`,start:`${a.range.start.line+1}:${a.range.start.character}`,end:`${a.range.end.line+1}:${a.range.end.character}`})}let a=e=>{n.builds[e]||(n.builds[e]={diagnostics:{},outputSize:{},success:!0})},s=e=>{n.statics[e]||(n.statics[e]={outputSize:{}})},c=e=>{let t=1024,n=[`Bytes`,`KiB`,`MiB`,`GiB`,`TiB`,`PiB`,`EiB`,`ZiB`,`YiB`],r=e==0?0:Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`};for(let e in t.files){let r=t.files[e];if(r.type==`build`&&r.typeName){let e=r.typeName,t=l(r.path).replace(/\\/g,`/`);a(e),n.builds[e].outputSize[t]=c(r.size)}else if(r.type==`static`&&r.typeName){let e=l(r.path).replace(/\\/g,`/`);s(r.typeName),n.statics[r.typeName].outputSize[e]=c(r.size)}}for(let e in t.builds){a(e);let t=r[e];if(t)for(let r in t){let a=l(r).replace(/\\/g,`/`),o=[];n.builds[e].diagnostics[a]=o;for(let a of t[r]){let t;a.severity==p.Error?(n.builds[e].success=!1,n.success=!1,i=!0,t=`error`):a.severity==p.Warning?t=`warning`:a.severity==p.Information?t=`info`:a.severity==p.Hint&&(t=`hint`),o.push({content:a.message,start:a.range.start.line+1+`:`+a.range.start.character,end:a.range.end.line+1+`:`+a.range.end.character,type:t})}}}console.log(JSON.stringify(n,void 0,4)),i&&process.exit(1)}},h=class extends s{get name(){return`dev`}get description(){return`Start an interactive cli to dev with your aventus project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){}async run(e,t){await a.load({clear:!0,printLogo:!0}),await o.load(),console.clear(),await a.init(),await o.start({loadFiles:!0,watchFiles:!0,useCompilators:!0,useTemplates:!0});let n=[{value:`create`,name:`Create...`},{value:`log`,name:`Show logs`},{value:`quit`,name:`Quit`}];for(a.clear();;){let e=await a.select(`Which action shoud I perform?`,n);e==`create`?await o.create():e==`log`?await a.log():e==`quit`?process.exit(0):console.log(`WIP`),a.clear()}}},g=class extends s{get name(){return`check`}get description(){return`Check an aventus project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){e({name:`builds`,description:`Define the build name`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`json`,type:`boolean`,typeIsRequired:!1,description:`Result as json`})}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),n.builds===!1&&(n.builds=[]),await o.load(),await o.start({noBuild:!0,loadFiles:!0,buildOnly:!0,configPath:r,builds:n.builds,statics:void 0,logLevel:3,errorByBuild:!0,useStats:!1}),n.json?this.handleResultJson(n):this.handleResult(n)}handleResult(e){let t=o.getStatistics(),n=console.log;n(),n(`Loading all files : Done in `+t.loadFileTime+`ms`),n(),n(`----`),n();let r=o.getErrors(),i=!1;for(let e in r){let t=!1,a=r[e];if(a){let e=!1;for(let n in a)for(let r of a[n]){let a=``,o;if(r.severity==p.Error)a=`\x1B[31m[error]\x1B[0m`,t=!0,i=!0,o=console.error;else if(r.severity==p.Warning)a=`\x1B[33m[warning]\x1B[0m`,o=console.warn;else if(r.severity==p.Information)a=`\x1B[34m[info]\x1B[0m`,o=console.info;else if(r.severity==p.Hint){a=`\x1B[90m[hint]\x1B[0m`;continue}o(` ${a} ${l(n).replace(/\\/g,`/`)}:${r.range.start.line+1} : ${r.message}`),e=!0}e&&n()}t||n(` Build has no error`)}i&&process.exit(1)}handleResultJson(e){let t={success:!0,builds:{}},n=o.getErrors(),r=!1,i=e=>{t.builds[e]||(t.builds[e]={diagnostics:{},success:!0})};for(let e in n){i(e);let a=n[e];if(a)for(let n in a){let i=l(n).replace(/\\/g,`/`),o=[];t.builds[e].diagnostics[i]=o;for(let i of a[n]){let n;i.severity==p.Error?(t.builds[e].success=!1,t.success=!1,r=!0,n=`error`):i.severity==p.Warning?n=`warning`:i.severity==p.Information?n=`info`:i.severity==p.Hint&&(n=`hint`),o.push({content:i.message,start:i.range.start.line+1+`:`+i.range.start.character,end:i.range.end.line+1+`:`+i.range.end.character,type:n})}}}console.log(JSON.stringify(t,void 0,4)),r&&process.exit(1)}},_=class extends s{get name(){return`format`}get description(){return`Format your project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),await o.load(),await o.start({noBuild:!0,configPath:r}),await o.executeCommand(`aventus.format`)}},v=class extends s{get name(){return`store login`}get description(){return`Login to the store`}registerArgs(e){}registerOptions(e){e({name:`username`,shortName:`u`,description:`Username for connection`,type:`string`,typeIsRequired:!0}),e({name:`password`,shortName:`p`,description:`Password for connection`,type:`string`,typeIsRequired:!0})}async run(e,t){try{await a.load(),await o.load(),await o.start({noStart:!0}),await o.executeCommand(`aventus.store.connect`,t.username,t.password)}catch(e){console.log(e),process.exit(1)}}},y=class extends s{get name(){return`store logout`}get description(){return`Logout from the store`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noStart:!0}),await o.executeCommand(`aventus.store.disconnect`)}catch(e){console.log(e),process.exit(1)}}},b=class extends s{get name(){return`store publish`}get description(){return`Publish to the store`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noStart:!0}),await o.executeCommand(`aventus.store.publish_package`)}catch(e){console.log(e),process.exit(1)}}},x=class extends s{get name(){return`create`}get description(){return`Create new project / files from a template`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0,loadFiles:!0}),await o.executeCommand(`aventus.create`,u(process.cwd()))}catch(e){console.log(e)}}},S=class extends s{get name(){return`template install`}get description(){return`Import template to create aventus element`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.import`)}catch(e){console.log(e),process.exit(1)}}},C=class extends s{get name(){return`project install`}get description(){return`Import project to init aventus`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.import_project`)}catch(e){console.log(e),process.exit(1)}}},w=class{static cmd=`aventus/server/start`;static callbacks=[];static action(e){let t=[...this.callbacks];for(let n of t)n(e)}},T=class extends s{get name(){return`serve`}get description(){return`Start live server`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({loadFiles:!0,watchFiles:!0}),await o.executeCommand(`aventus.liveserver.start`),await this.waitStart(),await o.Input({title:`Press enter to stop server`})}catch(e){console.log(e)}}getAction(){return o.notifications.allNotifications[w.cmd]}waitStart(){return new Promise(e=>{let t=n=>{console.log(`Server started : `+n);let r=this.getAction().callbacks.indexOf(t);r!=-1&&this.getAction().callbacks.splice(r,1),e()};this.getAction().callbacks.push(t)})}},E=class extends s{get name(){return`dependencies help-llm`}get description(){return`Write dependencies to help llm`}registerArgs(e){}registerOptions(e){}async run(e,n){try{let n=e[0];n&&=(0,t.resolve)(n),await o.load(),await o.start({noBuild:!0,loadFiles:!1,configPath:n}),await o.executeCommand(`aventus.ai.dependencies`)}catch(e){console.log(e)}}},D=class extends s{get name(){return`project uninstall`}get description(){return`Uninstall project`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.uninstall_project`)}catch(e){console.log(e),process.exit(1)}}},O=class extends s{get name(){return`template uninstall`}get description(){return`Uninstall project`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.uninstall`)}catch(e){console.log(e),process.exit(1)}}},k=class extends c{get name(){return`project`}get description(){return`Manage project's templates`}},A=class extends c{get name(){return`template`}get description(){return`Manage templates`}},j=class extends c{get name(){return`dependencies`}get description(){return`Manage project's dependencies`}},M=class extends c{get name(){return`store`}get description(){return`Manage store`}},N=class extends s{get name(){return`watch`}get description(){return`Start the compiler in watch mode`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){e({name:`builds`,description:`Define the build name`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`json`,type:`boolean`,typeIsRequired:!1,description:`Result as json`})}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),n.builds===!1&&(n.builds=[]),await o.load(),console.clear(),await o.start({loadFiles:!0,watchFiles:!0,useCompilators:!0,useTemplates:!1,configPath:r,builds:n.builds,useStats:!1}),await this.sleep(2e3);let i=o.getErrors(),a=n.json?this.renderLogJson:this.renderLog;a(i);let s=(e,t)=>{i[t]=e,a(i)};o.subscribeErrors(s),await new Promise(e=>{process.once(`SIGINT`,e)}),o.unsubscribeErrors(s),process.exit(0)}sleep(e){return new Promise(t=>setTimeout(t,e))}renderLog(e){console.clear();let t=console.log;for(let n in e){let r=!1;t(`Build : `+(n??`default`));let i=e[n];if(i){let e=!1;for(let t in i)for(let n of i[t]){let i=``,a;if(n.severity==p.Error)i=`\x1B[31m[error]\x1B[0m`,r=!0,a=console.error;else if(n.severity==p.Warning)i=`\x1B[33m[warning]\x1B[0m`,a=console.warn;else if(n.severity==p.Information)i=`\x1B[34m[info]\x1B[0m`,a=console.info;else if(n.severity==p.Hint){i=`\x1B[90m[hint]\x1B[0m`;continue}a(` ${i} ${l(t).replace(/\\/g,`/`)}:${n.range.start.line+1} : ${n.message}`),e=!0}e&&t()}r||t(` No error detected`)}}renderLogJson(e){console.clear();let t={success:!0,builds:{}},n=e=>{t.builds[e]||(t.builds[e]={diagnostics:{},success:!0})};for(let r in e){let i=e[r];if(r=r==``?`default`:r,n(r),i)for(let e in i){let n=l(e).replace(/\\/g,`/`),a=[];t.builds[r].diagnostics[n]=a;for(let n of i[e]){let e;if(n.severity==p.Error)t.builds[r].success=!1,t.success=!1,e=`error`;else if(n.severity==p.Warning)e=`warning`;else if(n.severity==p.Information)e=`info`;else if(n.severity==p.Hint){e=`hint`;continue}a.push({content:n.message,start:n.range.start.line+1+`:`+n.range.start.character,end:n.range.end.line+1+`:`+n.range.end.character,type:e})}t.builds[r].diagnostics[n].length==0&&delete t.builds[r].diagnostics[n]}}console.log(JSON.stringify(t,void 0,4))}},P=class extends c{get name(){return`ai`}get description(){return`Manage ai helpers`}},F=class extends s{get name(){return`ai prepare`}get description(){return`Prepare file to help AI`}registerArgs(e){}registerOptions(e){}async run(e,n){try{let n=e[0];n&&=(0,t.resolve)(n),await o.load(),await o.start({noBuild:!0,loadFiles:!1,configPath:n}),await o.executeCommand(`aventus.ai.dependencies`),await o.executeCommand(`aventus.ai.rules`)}catch(e){console.log(e)}}},I=`0.0.42`;const L=`@aventusjs/cli`,R=[x,h,N,T,m,g,_,class extends s{get name(){return`update`}get description(){return`Update the cli`}registerArgs(e){}registerOptions(e){}async run(e,n){let r=(await this.runNpm([`view`,L,`version`])).trim();if(!r)throw Error(`npm did not return a version for ${L}.`);if(r===I){console.log(`${L} is already up to date (${I}).`);return}let a=(0,i.realpathSync)((await this.runNpm([`root`,`--global`])).trim()),o=(0,i.realpathSync)((0,t.resolve)(require.resolve(`../../package.json`),`..`)),s;try{s=(0,i.realpathSync)((0,t.resolve)(a,L))}catch{}let c=s===o?[`install`,`--global`,`${L}@${r}`]:[`install`,`--save-dev`,`${L}@${r}`];await this.runNpm(c,!0),console.log(`${L} was updated to ${r}.`)}runNpm(e,t=!1){return new Promise((n,i)=>{let a=process.platform===`win32`?{command:process.env.ComSpec||`cmd.exe`,args:[`/d`,`/s`,`/c`,`npm.cmd`,...e]}:{command:`npm`,args:e},o=(0,r.spawn)(a.command,a.args,{cwd:process.cwd(),stdio:t?`inherit`:[`ignore`,`pipe`,`pipe`]}),s=``,c=``;t||(o.stdout?.on(`data`,e=>s+=e.toString()),o.stderr?.on(`data`,e=>c+=e.toString())),o.on(`error`,i),o.on(`close`,t=>{if(t===0){n(s);return}let r=c.trim();i(Error(`npm ${e.join(` `)} failed with exit code ${t}${r?`: ${r}`:`.`}`))})})}},j,E,P,F,k,C,D,A,S,O,M,v,y,b];function z(e){for(let t of R)new t().register(e)}e.program.version(I).name(`aventus`).description(`Aventus CLI`),z(e.program),e.program.parse(process.argv);
|
|
2
|
+
let e=require("commander"),t=require("path"),n=require("vscode-languageserver"),r=require("child_process"),i=require("fs");var a=class{static realInteraction;static async load(e){let t=eval;this.realInteraction=(await t(`import("./RealInteraction.js")`)).default.RealInteraction,this.realInteraction._server=o,e&&(this.realInteraction.config=e)}static async init(){this.clear(),console.log(`Welcome inside Aventus CLI`)}static clear(){this.realInteraction.clear()}static async select(e,t){return this.realInteraction?.select(e,t)||null}static async selectMultiple(e,t){return this.realInteraction?.selectMultiple(e,t)||null}static async input(e,t,n){return this.realInteraction?.input(e,t,n)||null}static async password(e,t){return this.realInteraction?.password(e,t)||null}static async tree(e,t,n){return this.realInteraction?.tree(e,t,n)||null}static async log(){return this.realInteraction?.log()||null}},o=class{static realServer;static get notifications(){return this.realServer?.notifications}static async load(){let e=eval;this.realServer=(await e(`import("./RealServer.js")`)).default.RealServer,this.realServer._interaction=a}static subscribeErrors(e){return this.realServer?.subscribeErrors(e)}static unsubscribeErrors(e){return this.realServer?.unsubscribeErrors(e)}static executeCommand(e,...t){return this.realServer?.executeCommand(e,...t)}static getErrors(){return this.realServer?.getErrors()}static start(e){return this.realServer?.start(e)}static create(){return this.realServer?.create()}static getStatistics(){return this.realServer?.getStatistics()}static async Input(e){return this.realServer?.Input(e)}},s=class e{static actions={};argsNb=0;register(t){let n=this.name.trim().split(` `),r=``,i=t;for(let t of n)r+=t,e.actions[r]||(e.actions[r]=i.command(t)),i=e.actions[r],r+=` `;i=i.description(this.description),i=this._registerArgs(i),i=this._registerOptions(i),i.action(async(...e)=>{let t=[];for(let n=0;n<this.argsNb;n++)t.push(e[n]);let n=e[this.argsNb];await this.run(t,n),process.exit(0)})}_registerArgs(e){return this.registerArgs(t=>{let n=``;if(t.type){let e=`<`,r=`>`;t.typeIsRequired!==void 0&&!t.typeIsRequired&&(e=`[`,r=`]`),t.typeIsArray&&(r=`...`+r),n+=`${e}${t.type}${r}`}this.argsNb++,e=e.argument(n,t.description,t.defaultValue)}),e}_registerOptions(e){let t=new Set,n=[];return this.registerOptions(r=>{let i=r.name;e.on(`option:${i}`,()=>t.add(i));for(let e of r.conflicts?[].concat(r.conflicts):[])n.push([i,e]);let a=[];if(r.shortName){Array.isArray(r.shortName)||(r.shortName=[r.shortName]);for(let e of r.shortName)a.push(`-`+e)}a.push(`--`+r.name);let o=a.join(`, `);if(r.type){let e=`<`,t=`>`;r.typeIsRequired!==void 0&&!r.typeIsRequired&&(e=`[`,t=`]`),r.typeIsArray&&(t=`...`+t),o+=` ${e}${r.type}${t}`}e=r.required?e.requiredOption(o,r.description,r.defaultValue):e.option(o,r.description,r.defaultValue)}),e.hook(`preAction`,()=>{let r=n.find(([e,n])=>t.has(e)&&t.has(n));t.clear(),r&&e.error(`options '--${r[0]}' and '--${r[1]}' cannot be used together`,{code:`commander.conflictingOption`})}),e}},c=class{register(e){let t=this.name.trim().split(` `),n=``,r=e;for(let e of t)n+=e,s.actions[n]||(s.actions[n]=r.command(e)),r=s.actions[n],n+=` `;r=r.description(this.description)}};function l(e){return t.sep===`/`?decodeURIComponent(e.replace(`file://`,``)):decodeURIComponent(e.replace(`file:///`,``))}function u(e){if(e.startsWith(`file://`))return e;let n=e[0].toLowerCase()+e.substring(1);return n=d(encodeURI(n.replace(/\\/g,`/`))),t.sep===`/`?`file://`+n:`file:///`+n}function d(e){return e.replace(/:/g,`%3A`).replace(/@/g,`%40`)}function f(e){let t=1024,n=[`Bytes`,`KiB`,`MiB`,`GiB`,`TiB`,`PiB`,`EiB`,`ZiB`,`YiB`],r=e==0?0:Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`}const p={Error:n.DiagnosticSeverity.Error,Warning:n.DiagnosticSeverity.Warning,Information:n.DiagnosticSeverity.Information,Hint:n.DiagnosticSeverity.Hint};var m=class extends s{get name(){return`build`}get description(){return`Build an aventus project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){e({name:`builds`,conflicts:`no-builds`,description:`Define the build name`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`no-builds`,description:`No builds`,type:`boolean`,typeIsRequired:!1}),e({name:`statics`,conflicts:`no-statics`,description:`Define the static files to export`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`no-statics`,description:`No statics`,type:`boolean`,typeIsRequired:!1}),e({name:`verbose`,conflicts:`silent`,shortName:`v`,description:`Debug your compilation`}),e({name:`silent`,shortName:`s`,description:`No output`}),e({name:`json`,type:`boolean`,typeIsRequired:!1,description:`Result as json`})}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),await o.load(),n.builds===!1&&(n.builds=[]),n.statics===!1&&(n.statics=[]),await o.start({configPath:r,loadFiles:!0,buildOnly:n[`no-statics`],noBuild:n[`no-builds`],builds:n.builds,statics:n.statics,logLevel:n.verbose?0:3,errorByBuild:!0,useStats:!n.silent}),n.json?this.handleResultJson(n):this.handleResult(n)}handleResult(e){let t=o.getStatistics(),n=e.silent?e=>{}:console.log;n(),n(`Loading all files : Done in `+t.loadFileTime+`ms`),n(),n(`----`),n();let r=o.getErrors(),i=!1;if(r[``])for(let t in r[``])for(let n of r[``][t])n.severity===p.Error&&(i=!0),e.silent||console.error(`${l(t)}:${n.range.start.line+1} : ${n.message}`);let a={},s={};for(let e in t.files){let n=t.files[e];if(n.type==`build`&&n.typeName){a[n.typeName]||(a[n.typeName]=[]);let e=` ${n.path} - ${f(n.size)}`;a[n.typeName].push(e)}else if(n.type==`static`&&n.typeName){s[n.typeName]||(s[n.typeName]=[]);let e=` ${n.path} - ${f(n.size)}`;s[n.typeName].push(e)}}let c=Object.keys(t.builds).length,u=Object.keys(t.statics).length,d=0;for(let o in t.builds){n(`Building `+o),n();let s=!1,f=r[o],m=t.builds[o],h=a[o];if(h){for(let e of h)n(e);n()}if(f){let t=!1;for(let n in f)for(let r of f[n]){let i=``,a;if(r.severity==p.Error)i=`\x1B[31m[error]\x1B[0m`,s=!0,a=console.error;else if(r.severity==p.Warning)i=`\x1B[33m[warning]\x1B[0m`,a=console.warn;else if(r.severity==p.Information)i=`\x1B[34m[info]\x1B[0m`,a=console.info;else if(r.severity==p.Hint){i=`\x1B[90m[hint]\x1B[0m`;continue}e.silent||(a(` ${i} ${l(n).replace(/\\/g,`/`)}:${r.range.start.line+1} : ${r.message}`),t=!0)}t&&n()}s?(n(` Build failed in `+m.buildTime+`ms`),i=!0):n(` Build success in `+m.buildTime+`ms`),d++,d==c&&u==0?n():(n(),n(`----`),n())}d=0;for(let e in t.statics){n(`Export static `+e),n();let r=t.statics[e],i=s[e];if(i){for(let e of i)n(e);n()}n(` Exported in `+r.buildTime+`ms`),d++,d==u?n():(n(),n(`----`),n())}i&&process.exit(1)}handleResultJson(e){let t=o.getStatistics(),n={success:!0,builds:{},statics:{}},r=o.getErrors(),i=!1;if(r[``])for(let e in r[``]){let t=l(e).replace(/\\/g,`/`);n.diagnostics||={},n.diagnostics[t]=[];for(let a of r[``][e])a.severity===p.Error&&(n.success=!1,i=!0),n.diagnostics[t].push({content:a.message,type:a.severity===p.Error?`error`:a.severity===p.Warning?`warning`:a.severity===p.Information?`info`:`hint`,start:`${a.range.start.line+1}:${a.range.start.character}`,end:`${a.range.end.line+1}:${a.range.end.character}`})}let a=e=>{n.builds[e]||(n.builds[e]={diagnostics:{},outputSize:{},success:!0})},s=e=>{n.statics[e]||(n.statics[e]={outputSize:{}})},c=e=>{let t=1024,n=[`Bytes`,`KiB`,`MiB`,`GiB`,`TiB`,`PiB`,`EiB`,`ZiB`,`YiB`],r=e==0?0:Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`};for(let e in t.files){let r=t.files[e];if(r.type==`build`&&r.typeName){let e=r.typeName,t=l(r.path).replace(/\\/g,`/`);a(e),n.builds[e].outputSize[t]=c(r.size)}else if(r.type==`static`&&r.typeName){let e=l(r.path).replace(/\\/g,`/`);s(r.typeName),n.statics[r.typeName].outputSize[e]=c(r.size)}}for(let e in t.builds){a(e);let t=r[e];if(t)for(let r in t){let a=l(r).replace(/\\/g,`/`),o=[];n.builds[e].diagnostics[a]=o;for(let a of t[r]){let t;a.severity==p.Error?(n.builds[e].success=!1,n.success=!1,i=!0,t=`error`):a.severity==p.Warning?t=`warning`:a.severity==p.Information?t=`info`:a.severity==p.Hint&&(t=`hint`),o.push({content:a.message,start:a.range.start.line+1+`:`+a.range.start.character,end:a.range.end.line+1+`:`+a.range.end.character,type:t})}}}console.log(JSON.stringify(n,void 0,4)),i&&process.exit(1)}},h=class extends s{get name(){return`dev`}get description(){return`Start an interactive cli to dev with your aventus project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){}async run(e,t){await a.load({clear:!0,printLogo:!0}),await o.load(),console.clear(),await a.init(),await o.start({loadFiles:!0,watchFiles:!0,useCompilators:!0,useTemplates:!0});let n=[{value:`create`,name:`Create...`},{value:`log`,name:`Show logs`},{value:`quit`,name:`Quit`}];for(a.clear();;){let e=await a.select(`Which action shoud I perform?`,n);e==`create`?await o.create():e==`log`?await a.log():e==`quit`?process.exit(0):console.log(`WIP`),a.clear()}}},g=class extends s{get name(){return`check`}get description(){return`Check an aventus project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){e({name:`builds`,description:`Define the build name`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`json`,type:`boolean`,typeIsRequired:!1,description:`Result as json`})}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),n.builds===!1&&(n.builds=[]),await o.load(),await o.start({noBuild:!0,loadFiles:!0,buildOnly:!0,configPath:r,builds:n.builds,statics:void 0,logLevel:3,errorByBuild:!0,useStats:!1}),n.json?this.handleResultJson(n):this.handleResult(n)}handleResult(e){let t=o.getStatistics(),n=console.log;n(),n(`Loading all files : Done in `+t.loadFileTime+`ms`),n(),n(`----`),n();let r=o.getErrors(),i=!1;for(let e in r){let t=!1,a=r[e];if(a){let e=!1;for(let n in a)for(let r of a[n]){let a=``,o;if(r.severity==p.Error)a=`\x1B[31m[error]\x1B[0m`,t=!0,i=!0,o=console.error;else if(r.severity==p.Warning)a=`\x1B[33m[warning]\x1B[0m`,o=console.warn;else if(r.severity==p.Information)a=`\x1B[34m[info]\x1B[0m`,o=console.info;else if(r.severity==p.Hint){a=`\x1B[90m[hint]\x1B[0m`;continue}o(` ${a} ${l(n).replace(/\\/g,`/`)}:${r.range.start.line+1} : ${r.message}`),e=!0}e&&n()}t||n(` Build has no error`)}i&&process.exit(1)}handleResultJson(e){let t={success:!0,builds:{}},n=o.getErrors(),r=!1,i=e=>{t.builds[e]||(t.builds[e]={diagnostics:{},success:!0})};for(let e in n){i(e);let a=n[e];if(a)for(let n in a){let i=l(n).replace(/\\/g,`/`),o=[];t.builds[e].diagnostics[i]=o;for(let i of a[n]){let n;i.severity==p.Error?(t.builds[e].success=!1,t.success=!1,r=!0,n=`error`):i.severity==p.Warning?n=`warning`:i.severity==p.Information?n=`info`:i.severity==p.Hint&&(n=`hint`),o.push({content:i.message,start:i.range.start.line+1+`:`+i.range.start.character,end:i.range.end.line+1+`:`+i.range.end.character,type:n})}}}console.log(JSON.stringify(t,void 0,4)),r&&process.exit(1)}},_=class extends s{get name(){return`format`}get description(){return`Format your project`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),await o.load(),await o.start({noBuild:!0,configPath:r}),await o.executeCommand(`aventus.format`)}},v=class extends s{get name(){return`store login`}get description(){return`Login to the store`}registerArgs(e){}registerOptions(e){e({name:`username`,shortName:`u`,description:`Username for connection`,type:`string`,typeIsRequired:!0}),e({name:`password`,shortName:`p`,description:`Password for connection`,type:`string`,typeIsRequired:!0})}async run(e,t){try{await a.load(),await o.load(),await o.start({noStart:!0}),await o.executeCommand(`aventus.store.connect`,t.username,t.password)}catch(e){console.log(e),process.exit(1)}}},y=class extends s{get name(){return`store logout`}get description(){return`Logout from the store`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noStart:!0}),await o.executeCommand(`aventus.store.disconnect`)}catch(e){console.log(e),process.exit(1)}}},b=class extends s{get name(){return`store publish`}get description(){return`Publish to the store`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noStart:!0}),await o.executeCommand(`aventus.store.publish_package`)}catch(e){console.log(e),process.exit(1)}}},x=class extends s{get name(){return`create`}get description(){return`Create new project / files from a template`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0,loadFiles:!0}),await o.executeCommand(`aventus.create`,u(process.cwd()))}catch(e){console.log(e)}}},S=class extends s{get name(){return`template install`}get description(){return`Import template to create aventus element`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.import`)}catch(e){console.log(e),process.exit(1)}}},C=class extends s{get name(){return`project install`}get description(){return`Import project to init aventus`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.import_project`)}catch(e){console.log(e),process.exit(1)}}},w=class{static cmd=`aventus/server/start`;static callbacks=[];static action(e){let t=[...this.callbacks];for(let n of t)n(e)}},T=class extends s{get name(){return`serve`}get description(){return`Start live server`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({loadFiles:!0,watchFiles:!0}),await o.executeCommand(`aventus.liveserver.start`),await this.waitStart(),await o.Input({title:`Press enter to stop server`})}catch(e){console.log(e)}}getAction(){return o.notifications.allNotifications[w.cmd]}waitStart(){return new Promise(e=>{let t=n=>{console.log(`Server started : `+n);let r=this.getAction().callbacks.indexOf(t);r!=-1&&this.getAction().callbacks.splice(r,1),e()};this.getAction().callbacks.push(t)})}},E=class extends s{get name(){return`dependencies help-llm`}get description(){return`Write dependencies to help llm`}registerArgs(e){}registerOptions(e){}async run(e,n){try{let n=e[0];n&&=(0,t.resolve)(n),await o.load(),await o.start({noBuild:!0,loadFiles:!1,configPath:n}),await o.executeCommand(`aventus.ai.dependencies`)}catch(e){console.log(e)}}},D=class extends s{get name(){return`project uninstall`}get description(){return`Uninstall project`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.uninstall_project`)}catch(e){console.log(e),process.exit(1)}}},O=class extends s{get name(){return`template uninstall`}get description(){return`Uninstall project`}registerArgs(e){}registerOptions(e){}async run(e,t){try{await a.load(),await o.load(),await o.start({noBuild:!0,useTemplates:!0}),await o.executeCommand(`aventus.template.uninstall`)}catch(e){console.log(e),process.exit(1)}}},k=class extends c{get name(){return`project`}get description(){return`Manage project's templates`}},A=class extends c{get name(){return`template`}get description(){return`Manage templates`}},j=class extends c{get name(){return`dependencies`}get description(){return`Manage project's dependencies`}},M=class extends c{get name(){return`store`}get description(){return`Manage store`}},N=class extends s{get name(){return`watch`}get description(){return`Start the compiler in watch mode`}registerArgs(e){e({description:`aventus.conf.avt path`,type:`string`,typeIsRequired:!1})}registerOptions(e){e({name:`builds`,description:`Define the build name`,type:`string`,typeIsRequired:!0,typeIsArray:!0}),e({name:`json`,type:`boolean`,typeIsRequired:!1,description:`Result as json`})}async run(e,n){let r=e[0];r&&=(0,t.resolve)(r),n.builds===!1&&(n.builds=[]),await o.load(),console.clear(),await o.start({loadFiles:!0,watchFiles:!0,useCompilators:!0,useTemplates:!1,configPath:r,builds:n.builds,useStats:!1}),await this.sleep(2e3);let i=o.getErrors(),a=n.json?this.renderLogJson:this.renderLog;a(i);let s=(e,t)=>{i[t]=e,a(i)};o.subscribeErrors(s),await new Promise(e=>{process.once(`SIGINT`,e)}),o.unsubscribeErrors(s),process.exit(0)}sleep(e){return new Promise(t=>setTimeout(t,e))}renderLog(e){console.clear();let t=console.log;for(let n in e){let r=!1;t(`Build : `+(n??`default`));let i=e[n];if(i){let e=!1;for(let t in i)for(let n of i[t]){let i=``,a;if(n.severity==p.Error)i=`\x1B[31m[error]\x1B[0m`,r=!0,a=console.error;else if(n.severity==p.Warning)i=`\x1B[33m[warning]\x1B[0m`,a=console.warn;else if(n.severity==p.Information)i=`\x1B[34m[info]\x1B[0m`,a=console.info;else if(n.severity==p.Hint){i=`\x1B[90m[hint]\x1B[0m`;continue}a(` ${i} ${l(t).replace(/\\/g,`/`)}:${n.range.start.line+1} : ${n.message}`),e=!0}e&&t()}r||t(` No error detected`)}}renderLogJson(e){console.clear();let t={success:!0,builds:{}},n=e=>{t.builds[e]||(t.builds[e]={diagnostics:{},success:!0})};for(let r in e){let i=e[r];if(r=r==``?`default`:r,n(r),i)for(let e in i){let n=l(e).replace(/\\/g,`/`),a=[];t.builds[r].diagnostics[n]=a;for(let n of i[e]){let e;if(n.severity==p.Error)t.builds[r].success=!1,t.success=!1,e=`error`;else if(n.severity==p.Warning)e=`warning`;else if(n.severity==p.Information)e=`info`;else if(n.severity==p.Hint){e=`hint`;continue}a.push({content:n.message,start:n.range.start.line+1+`:`+n.range.start.character,end:n.range.end.line+1+`:`+n.range.end.character,type:e})}t.builds[r].diagnostics[n].length==0&&delete t.builds[r].diagnostics[n]}}console.log(JSON.stringify(t,void 0,4))}},P=class extends c{get name(){return`ai`}get description(){return`Manage ai helpers`}},F=class extends s{get name(){return`ai prepare`}get description(){return`Prepare file to help AI`}registerArgs(e){}registerOptions(e){}async run(e,n){try{let n=e[0];n&&=(0,t.resolve)(n),await o.load(),await o.start({noBuild:!0,loadFiles:!1,configPath:n}),await o.executeCommand(`aventus.ai.dependencies`),await o.executeCommand(`aventus.ai.rules`)}catch(e){console.log(e)}}},I=`0.0.43`;const L=`@aventusjs/cli`,R=[x,h,N,T,m,g,_,class extends s{get name(){return`update`}get description(){return`Update the cli`}registerArgs(e){}registerOptions(e){}async run(e,n){let r=(await this.runNpm([`view`,L,`version`])).trim();if(!r)throw Error(`npm did not return a version for ${L}.`);if(r===I){console.log(`${L} is already up to date (${I}).`);return}let a=(0,i.realpathSync)((await this.runNpm([`root`,`--global`])).trim()),o=(0,i.realpathSync)((0,t.resolve)(require.resolve(`../../package.json`),`..`)),s;try{s=(0,i.realpathSync)((0,t.resolve)(a,L))}catch{}let c=s===o?[`install`,`--global`,`${L}@${r}`]:[`install`,`--save-dev`,`${L}@${r}`];await this.runNpm(c,!0),console.log(`${L} was updated to ${r}.`)}runNpm(e,t=!1){return new Promise((n,i)=>{let a=process.platform===`win32`?{command:process.env.ComSpec||`cmd.exe`,args:[`/d`,`/s`,`/c`,`npm.cmd`,...e]}:{command:`npm`,args:e},o=(0,r.spawn)(a.command,a.args,{cwd:process.cwd(),stdio:t?`inherit`:[`ignore`,`pipe`,`pipe`]}),s=``,c=``;t||(o.stdout?.on(`data`,e=>s+=e.toString()),o.stderr?.on(`data`,e=>c+=e.toString())),o.on(`error`,i),o.on(`close`,t=>{if(t===0){n(s);return}let r=c.trim();i(Error(`npm ${e.join(` `)} failed with exit code ${t}${r?`: ${r}`:`.`}`))})})}},j,E,P,F,k,C,D,A,S,O,M,v,y,b];function z(e){for(let t of R)new t().register(e)}e.program.version(I).name(`aventus`).description(`Aventus CLI`),z(e.program),e.program.parse(process.argv);
|
package/package.json
CHANGED