@aerogel/cli 0.0.0-next.47ed8ee3c048720794026e45140e9b700cb428b9 → 0.0.0-next.59bf5f7cc06e728d0cf6c00de28f1da48d7d6b8e
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/dist/aerogel-cli.cjs.js +1 -1
- package/dist/aerogel-cli.esm.js +1 -1
- package/package.json +1 -1
- package/src/commands/create.test.ts +10 -1
- package/src/commands/create.ts +17 -10
- package/src/commands/generate-component.test.ts +11 -0
- package/src/commands/generate-component.ts +22 -10
- package/src/commands/generate-model.test.ts +5 -2
- package/src/commands/generate-model.ts +24 -4
- package/src/lib/App.ts +8 -1
- package/src/lib/Log.mock.ts +11 -3
- package/src/lib/Log.test.ts +19 -3
- package/src/lib/Log.ts +31 -17
- package/src/lib/utils.ts +1 -1
- package/src/testing/setup.ts +3 -1
- package/templates/app/package.json +9 -9
- package/templates/app/src/main.ts +5 -1
- package/templates/app/tailwind.config.js +1 -1
- package/templates/app/vite.config.ts +5 -2
package/dist/aerogel-cli.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("commander"),t=require("@babel/runtime/helpers/defineProperty"),s=require("@noeldemartin/utils"),n=require("fs"),i=require("path");require("core-js/modules/esnext.async-iterator.for-each.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js");var r=require("chalk"),a=require("readline");require("core-js/modules/esnext.async-iterator.reduce.js"),require("core-js/modules/esnext.iterator.reduce.js");var o=require("mustache"),c=require("child_process");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("core-js/modules/esnext.async-iterator.map.js"),require("core-js/modules/esnext.iterator.map.js");var d=l(t);var u=s.facade(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return n.existsSync(e)}read(e){return this.isFile(e)?n.readFileSync(e).toString():null}getFiles(e){const t=n.readdirSync(e,{withFileTypes:!0}),s=[];for(const n of t){const t=i.resolve(e,n.name);n.isDirectory()?s.push(...this.getFiles(t)):s.push(t)}return s}isDirectory(e){return this.exists(e)&&n.lstatSync(e).isDirectory()}isFile(e){return this.exists(e)&&n.lstatSync(e).isFile()}isEmptyDirectory(e){return!!this.isDirectory(e)&&0===this.getFiles(e).length}makeDirectory(e){n.mkdirSync(e,{recursive:!0})}write(e,t){n.existsSync(i.dirname(e))||n.mkdirSync(i.dirname(e),{recursive:!0}),n.writeFileSync(e,t)}});var p=s.facade(new class{constructor(){d.default(this,"renderInfo",r.hex("#00ffff")),d.default(this,"renderSuccess",r.hex("#00ff00")),d.default(this,"renderError",r.hex("#ff0000"))}async animate(e,t){var s=this;const n=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";const n=s.renderInfo(s.renderMarkdown(e)+".".repeat(i%4))+t;s.stdout(n)};let i=0;n();const r=setInterval((()=>(i++,n())),1e3),a=await t();return clearInterval(r),n("\n"),a}info(e){s.arrayFrom(e).forEach((e=>{this.log(this.renderInfo(this.renderMarkdown(e)))}))}error(e){s.arrayFrom(e).forEach((e=>{this.log(this.renderError(this.renderMarkdown(e)))}))}fail(e){this.error(e),process.exit(1)}success(e){s.arrayFrom(e).forEach((e=>{this.log(this.renderSuccess(this.renderMarkdown(e)))}))}renderMarkdown(e){const t=s.stringMatchAll(e,/\*\*(.*)\*\*/g);for(const s of t)e=e.replace(s[0],r.bold(s[1]));return e}log(e){s.arrayFrom(e).forEach((e=>console.log(e)))}stdout(e){a.cursorTo(process.stdout,0),a.clearLine(process.stdout,0),process.stdout.write(e)}});class m{static instantiate(e,t,s){return new m(e).instantiate(t,s)}constructor(e){d.default(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=this.getFilenameReplacements(t),i=[];e=`${e}/`.replace(/\/\//,"/");for(const r of u.getFiles(this.path)){const a=Object.entries(s).reduce(((e,t)=>{let[s,n]=t;return e.replaceAll(s,n)}),r.substring(this.path.length+1)),c=n.readFileSync(r).toString(),l=e+(a.endsWith(".template")?a.slice(0,-9):a);u.write(l,o.render(c,t,void 0,["<%","%>"])),i.push(l)}return i}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,n)=>{let[i,r]=n;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${i}.`)):e[`[${t}${i}]`]=s.toString(r),e}),{})}}function h(e){return i.resolve(__dirname,"../",e)}class f{constructor(e){d.default(this,"name",void 0),this.name=e}create(e){!u.exists(e)||u.isDirectory(e)&&u.isEmptyDirectory(e)||p.fail(`Folder at '${e}' already exists!`),m.instantiate(h("templates/app"),e,{app:{name:this.name,slug:s.stringToSlug(this.name)}})}}class g{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,s]of this.parameters)e=e.argument(`<${t}>`,s);for(const[t,s]of Object.entries(this.options)){const n="string"==typeof s?s:s.description,i="string"==typeof s?"string":s.type??"string";e=e.option("boolean"===i?`--${t}`:`--${t} <${i}>`,n)}e=e.action((function(){for(var e=arguments.length,s=new Array(e),n=0;n<e;n++)s[n]=arguments[n];return t.run.call(t,...s)}))}static async run(){for(var e=arguments.length,t=new Array(e),s=0;s<e;s++)t[s]=arguments[s];const n=new this(...t);await n.run()}async run(){}assertAerogelOrDirectory(e){const t=u.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&u.isDirectory(e))return;const s=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";p.fail(`${s} Are you sure this is an Aerogel app?`)}}d.default(g,"command",""),d.default(g,"description",""),d.default(g,"parameters",[]),d.default(g,"options",{});var y=s.facade(new class{constructor(){d.default(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,s)=>{c.exec(e,{cwd:this.cwd??void 0},(e=>{e?s(e):t()}))}))}});class w extends g{constructor(e,t){super(),d.default(this,"path",void 0),d.default(this,"options",void 0),this.path=e,this.options=t}async run(){const e=this.path,t=this.options.name??"Aerogel App";y.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),p.success(["",`That's it! You can start working on **${t}** doing the following:`,` cd ${e}`," npm run dev","","Have fun!"])}async createApp(e,t){p.info(`Creating **${e}**...`),new f(e).create(t)}async installDependencies(){await p.animate("Installing dependencies",(async()=>{await y.run("npm install")}))}async initializeGit(){await p.animate("Initializing git",(async()=>{await y.run("git init"),await y.run("git add ."),await y.run('git commit -m "Start"')}))}}d.default(w,"command","create"),d.default(w,"description","Create AerogelJS app"),d.default(w,"parameters",[["path","Application path"]]),d.default(w,"options",{name:"Application name"});class v extends g{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),d.default(this,"name",void 0),d.default(this,"options",void 0),this.name=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/components"),this.options.story&&this.assertHistoireInstalled(),u.exists(`src/components/${this.name}.vue`)&&p.fail(`${this.name} component already exists!`);const e=m.instantiate(h("templates/component"),"src/components",{component:{name:this.name}});if(this.options.story){const t=m.instantiate(h("templates/component-story"),"src/components",{component:{name:this.name}});e.push(...t)}const t=e.map((e=>`- ${e}`)).join("\n");p.info(`${this.name} component created successfully! The following files were created:\n\n${t}`)}assertHistoireInstalled(){u.exists("src/main.histoire.ts")||p.fail("Histoire is not installed yet!")}}d.default(v,"command","generate:component"),d.default(v,"description","Generate an AerogelJS component"),d.default(v,"parameters",[["name","Component name"]]),d.default(v,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class x extends g{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),d.default(this,"name",void 0),d.default(this,"options",void 0),this.name=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/models"),u.exists(`src/models/${this.name}.ts`)&&p.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=m.instantiate(h("templates/model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n");p.info(`${this.name} model created successfully! The following files were created:\n\n${e}`)}getFieldsDefinition(){if(!this.options.fields)return" //";return function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=e.split("\n"),n=t.indent??0;let i=0,r="";for(const e of s){const t=e.trim(),s=0===t.length;if(0===r.length){if(s)continue;i=e.indexOf(t[0]??""),r+=`${" ".repeat(n)}${t}\n`;continue}if(s){r+="\n";continue}const a=e.indexOf(t[0]??"");r+=`${" ".repeat(n+a-i)}${t}\n`}return r.trimEnd()}(this.options.fields.split(",").map((e=>{const[t,n]=e.split(":");return{name:t,type:s.stringToStudlyCase(n??"string")}})).reduce(((e,t)=>e+`\n${t.name}: FieldType.${t.type},`),""),{indent:8})}assertSoukaiInstalled(){u.contains("package.json",'"soukai"')||p.fail("Soukai is not installed yet!")}}d.default(x,"command","generate:model"),d.default(x,"description","Generate an AerogelJS model"),d.default(x,"parameters",[["name","Model name"]]),d.default(x,"options",{fields:"Create model with the given fields"});var $=s.facade(new class{run(t){const s=new e.Command;s.name("ag").description("AerogelJS CLI").version("0.0.0"),w.define(s),v.define(s),x.define(s),s.parse(t)}});exports.CLI=$;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("commander"),t=require("@babel/runtime/helpers/defineProperty"),n=require("@noeldemartin/utils"),s=require("fs"),i=require("path");require("core-js/modules/esnext.async-iterator.for-each.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.async-iterator.find.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.async-iterator.map.js"),require("core-js/modules/esnext.iterator.map.js");var r=require("chalk"),o=require("readline");require("core-js/modules/esnext.async-iterator.reduce.js"),require("core-js/modules/esnext.iterator.reduce.js");var a=require("mustache"),l=require("child_process");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=c(t);var u=n.facade(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return s.existsSync(e)}read(e){return this.isFile(e)?s.readFileSync(e).toString():null}getFiles(e){const t=s.readdirSync(e,{withFileTypes:!0}),n=[];for(const s of t){const t=i.resolve(e,s.name);s.isDirectory()?n.push(...this.getFiles(t)):n.push(t)}return n}isDirectory(e){return this.exists(e)&&s.lstatSync(e).isDirectory()}isFile(e){return this.exists(e)&&s.lstatSync(e).isFile()}isEmptyDirectory(e){return!!this.isDirectory(e)&&0===this.getFiles(e).length}makeDirectory(e){s.mkdirSync(e,{recursive:!0})}write(e,t){s.existsSync(i.dirname(e))||s.mkdirSync(i.dirname(e),{recursive:!0}),s.writeFileSync(e,t)}});var p=n.facade(new class{constructor(){d.default(this,"renderInfo",r.hex("#00ffff")),d.default(this,"renderSuccess",r.hex("#00ff00")),d.default(this,"renderError",r.hex("#ff0000"))}async animate(e,t){var n=this;const s=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";const s=n.renderInfo(n.renderMarkdown(e)+".".repeat(i%4))+t;n.stdout(s)};let i=0;s();const r=setInterval((()=>(i++,s())),1e3),o=await t();return clearInterval(r),s("\n"),o}info(e){this.log(this.renderMarkdown(e),this.renderInfo)}error(e){this.log(this.renderMarkdown(e),this.renderError)}fail(e){this.error(e),process.exit(1)}success(e){this.log(this.renderMarkdown(e),this.renderSuccess)}renderMarkdown(e){const t=n.stringMatchAll(e,/\*\*(.*)\*\*/g);for(const n of t)e=e.replace(n[0],r.bold(n[1]));return e}log(e,t){this.formatMessage(e).forEach((e=>{this.logLine(t?t(e):e)}))}formatMessage(e){if("\n"===e[0]){const t=(e=e.slice(1).trimEnd()).split("\n"),n=e.trim()[0]??"",s=t.find((e=>e.trim().length>0))?.indexOf(n)??0;return t.map((e=>e.slice(s)))}return[e]}logLine(e){console.log(e)}stdout(e){o.cursorTo(process.stdout,0),o.clearLine(process.stdout,0),process.stdout.write(e)}});class h{static instantiate(e,t,n){return new h(e).instantiate(t,n)}constructor(e){d.default(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=this.getFilenameReplacements(t),i=[];e=`${e}/`.replace(/\/\//,"/");for(const r of u.getFiles(this.path)){const o=Object.entries(n).reduce(((e,t)=>{let[n,s]=t;return e.replaceAll(n,s)}),r.substring(this.path.length+1)),l=s.readFileSync(r).toString(),c=e+(o.endsWith(".template")?o.slice(0,-9):o);u.write(c,a.render(l,t,void 0,["<%","%>"])),i.push(c)}return i}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,s)=>{let[i,r]=s;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${i}.`)):e[`[${t}${i}]`]=n.toString(r),e}),{})}}function m(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return i.resolve(__dirname,"../",e)}function f(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=e.split("\n"),s=t.indent??0;let i=0,r="";for(const e of n){const t=e.trim(),n=0===t.length;if(0===r.length){if(n)continue;i=e.indexOf(t[0]??""),r+=`${" ".repeat(s)}${t}\n`;continue}if(n){r+="\n";continue}const o=e.indexOf(t[0]??"");r+=`${" ".repeat(s+o-i)}${t}\n`}return r.trimEnd()}class g{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};d.default(this,"name",void 0),d.default(this,"options",void 0),this.name=e,this.options=t}create(e){!u.exists(e)||u.isDirectory(e)&&u.isEmptyDirectory(e)||p.fail(`Folder at '${e}' already exists!`),h.instantiate(m("templates/app"),e,{app:{name:this.name,slug:n.stringToSlug(this.name)},local:this.options.local&&{aerogelPath:m("../")}})}}class y{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,n]of this.parameters)e=e.argument(`<${t}>`,n);for(const[t,n]of Object.entries(this.options)){const s="string"==typeof n?n:n.description,i="string"==typeof n?"string":n.type??"string";e=e.option("boolean"===i?`--${t}`:`--${t} <${i}>`,s)}e=e.action((function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];return t.run.call(t,...n)}))}static async run(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];const s=new this(...t);await s.run()}async run(){}assertAerogelOrDirectory(e){const t=u.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&u.isDirectory(e))return;const n=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";p.fail(`${n} Are you sure this is an Aerogel app?`)}}d.default(y,"command",""),d.default(y,"description",""),d.default(y,"parameters",[]),d.default(y,"options",{});var w=n.facade(new class{constructor(){d.default(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,n)=>{l.exec(e,{cwd:this.cwd??void 0},(e=>{e?n(e):t()}))}))}});class v extends y{constructor(e,t){super(),d.default(this,"path",void 0),d.default(this,"options",void 0),this.path=e,this.options=t}async run(){const e=this.path,t=this.options.name??"Aerogel App";w.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),p.success(`\n\n That's it! You can start working on **${t}** doing the following:\n\n cd ${e}\n npm run dev\n\n Have fun!\n `)}async createApp(e,t){p.info(`Creating **${e}**...`),new g(e,{local:this.options.local}).create(t)}async installDependencies(){await p.animate("Installing dependencies",(async()=>{await w.run("npm install")}))}async initializeGit(){await p.animate("Initializing git",(async()=>{await w.run("git init"),await w.run("git add ."),await w.run('git commit -m "Start"')}))}}d.default(v,"command","create"),d.default(v,"description","Create AerogelJS app"),d.default(v,"parameters",[["path","Application path"]]),d.default(v,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used for core development)"}});class x extends y{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),d.default(this,"path",void 0),d.default(this,"options",void 0),this.path=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/components"),this.options.story&&this.assertHistoireInstalled(),u.exists(`src/components/${this.path}.vue`)&&p.fail(`${this.path} component already exists!`);const[e,t]=this.parsePathComponents(),n=h.instantiate(m("templates/component"),`src/components/${e}`,{component:{name:t}});if(this.options.story){const e=h.instantiate(m("templates/component-story"),"src/components",{component:{name:t}});n.push(...e)}const s=n.map((e=>`- ${e}`)).join("\n");p.info(`${t} component created successfully! The following files were created:\n\n${s}`)}assertHistoireInstalled(){u.exists("src/main.histoire.ts")||p.fail("Histoire is not installed yet!")}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}d.default(x,"command","generate:component"),d.default(x,"description","Generate an AerogelJS component"),d.default(x,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),d.default(x,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class $ extends y{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),d.default(this,"name",void 0),d.default(this,"options",void 0),this.name=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/models"),u.exists(`src/models/${this.name}.ts`)&&p.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=h.instantiate(m("templates/model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n");p.info(`${this.name} model created successfully! The following files were created:\n\n${e}`)}getFieldsDefinition(){if(!this.options.fields)return" //";const e=this.options.fields.split(",").map((e=>{const[t,s,i]=e.split(":");return{name:t,type:n.stringToStudlyCase(s??"string"),required:"required"===i}})).reduce(((e,t)=>e+`\n${t.required?f(`\n ${t.name}: {\n type: FieldType.${t.type},\n required: true,\n }\n `):`${t.name}: FieldType.${t.type}`},`),"");return f(e,{indent:8})}assertSoukaiInstalled(){u.contains("package.json",'"soukai"')||u.contains("package.json",'"@aerogel/plugin-soukai"')||p.fail("\n Soukai is not installed yet! You can install it doing the following:\n\n 1. Run the following command:\n npm install soukai @aerogel/plugin-soukai@next\n\n 2. Add this to your plugins array in src/main.ts:\n soukai({ models: import.meta.glob('@/models/*', { eager: true }) })\n ")}}d.default($,"command","generate:model"),d.default($,"description","Generate an AerogelJS model"),d.default($,"parameters",[["name","Model name"]]),d.default($,"options",{fields:"Create model with the given fields"});var j=n.facade(new class{run(t){const n=new e.Command;n.name("ag").description("AerogelJS CLI").version("0.0.0"),v.define(n),x.define(n),$.define(n),n.parse(t)}});exports.CLI=j;
|
|
2
2
|
//# sourceMappingURL=aerogel-cli.cjs.js.map
|
package/dist/aerogel-cli.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Command as e}from"commander";import t from"@babel/runtime/helpers/esm/defineProperty";import{facade as s,
|
|
1
|
+
import{Command as e}from"commander";import t from"@babel/runtime/helpers/esm/defineProperty";import{facade as s,stringMatchAll as n,toString as i,stringToSlug as o,stringToStudlyCase as r}from"@noeldemartin/utils";import{existsSync as a,readFileSync as c,readdirSync as l,lstatSync as p,mkdirSync as d,writeFileSync as m}from"fs";import{resolve as h,dirname as u}from"path";import"core-js/modules/esnext.async-iterator.for-each.js";import"core-js/modules/esnext.iterator.constructor.js";import"core-js/modules/esnext.iterator.for-each.js";import"core-js/modules/esnext.async-iterator.find.js";import"core-js/modules/esnext.iterator.find.js";import"core-js/modules/esnext.async-iterator.map.js";import"core-js/modules/esnext.iterator.map.js";import{hex as f,bold as g}from"chalk";import{cursorTo as y,clearLine as w}from"readline";import"core-js/modules/esnext.async-iterator.reduce.js";import"core-js/modules/esnext.iterator.reduce.js";import{render as v}from"mustache";import{exec as $}from"child_process";var x=s(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return a(e)}read(e){return this.isFile(e)?c(e).toString():null}getFiles(e){const t=l(e,{withFileTypes:!0}),s=[];for(const n of t){const t=h(e,n.name);n.isDirectory()?s.push(...this.getFiles(t)):s.push(t)}return s}isDirectory(e){return this.exists(e)&&p(e).isDirectory()}isFile(e){return this.exists(e)&&p(e).isFile()}isEmptyDirectory(e){return!!this.isDirectory(e)&&0===this.getFiles(e).length}makeDirectory(e){d(e,{recursive:!0})}write(e,t){a(u(e))||d(u(e),{recursive:!0}),m(e,t)}});var j=s(new class{constructor(){t(this,"renderInfo",f("#00ffff")),t(this,"renderSuccess",f("#00ff00")),t(this,"renderError",f("#ff0000"))}async animate(e,t){var s=this;const n=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";const n=s.renderInfo(s.renderMarkdown(e)+".".repeat(i%4))+t;s.stdout(n)};let i=0;n();const o=setInterval((()=>(i++,n())),1e3),r=await t();return clearInterval(o),n("\n"),r}info(e){this.log(this.renderMarkdown(e),this.renderInfo)}error(e){this.log(this.renderMarkdown(e),this.renderError)}fail(e){this.error(e),process.exit(1)}success(e){this.log(this.renderMarkdown(e),this.renderSuccess)}renderMarkdown(e){const t=n(e,/\*\*(.*)\*\*/g);for(const s of t)e=e.replace(s[0],g(s[1]));return e}log(e,t){this.formatMessage(e).forEach((e=>{this.logLine(t?t(e):e)}))}formatMessage(e){if("\n"===e[0]){const t=(e=e.slice(1).trimEnd()).split("\n"),s=e.trim()[0]??"",n=t.find((e=>e.trim().length>0))?.indexOf(s)??0;return t.map((e=>e.slice(n)))}return[e]}logLine(e){console.log(e)}stdout(e){y(process.stdout,0),w(process.stdout,0),process.stdout.write(e)}});class k{static instantiate(e,t,s){return new k(e).instantiate(t,s)}constructor(e){t(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=this.getFilenameReplacements(t),n=[];e=`${e}/`.replace(/\/\//,"/");for(const i of x.getFiles(this.path)){const o=Object.entries(s).reduce(((e,t)=>{let[s,n]=t;return e.replaceAll(s,n)}),i.substring(this.path.length+1)),r=c(i).toString(),a=e+(o.endsWith(".template")?o.slice(0,-9):o);x.write(a,v(r,t,void 0,["<%","%>"])),n.push(a)}return n}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,s)=>{let[n,o]=s;return"object"==typeof o?Object.assign(e,this.getFilenameReplacements(o,`${n}.`)):e[`[${t}${n}]`]=i(o),e}),{})}}function A(){return h(__dirname,"../",arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")}function D(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=e.split("\n"),n=t.indent??0;let i=0,o="";for(const e of s){const t=e.trim(),s=0===t.length;if(0===o.length){if(s)continue;i=e.indexOf(t[0]??""),o+=`${" ".repeat(n)}${t}\n`;continue}if(s){o+="\n";continue}const r=e.indexOf(t[0]??"");o+=`${" ".repeat(n+r-i)}${t}\n`}return o.trimEnd()}class F{constructor(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(this,"name",void 0),t(this,"options",void 0),this.name=e,this.options=s}create(e){!x.exists(e)||x.isDirectory(e)&&x.isEmptyDirectory(e)||j.fail(`Folder at '${e}' already exists!`),k.instantiate(A("templates/app"),e,{app:{name:this.name,slug:o(this.name)},local:this.options.local&&{aerogelPath:A("../")}})}}class I{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,s]of this.parameters)e=e.argument(`<${t}>`,s);for(const[t,s]of Object.entries(this.options)){const n="string"==typeof s?s:s.description,i="string"==typeof s?"string":s.type??"string";e=e.option("boolean"===i?`--${t}`:`--${t} <${i}>`,n)}e=e.action((function(){for(var e=arguments.length,s=new Array(e),n=0;n<e;n++)s[n]=arguments[n];return t.run.call(t,...s)}))}static async run(){for(var e=arguments.length,t=new Array(e),s=0;s<e;s++)t[s]=arguments[s];const n=new this(...t);await n.run()}async run(){}assertAerogelOrDirectory(e){const t=x.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&x.isDirectory(e))return;const s=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";j.fail(`${s} Are you sure this is an Aerogel app?`)}}t(I,"command",""),t(I,"description",""),t(I,"parameters",[]),t(I,"options",{});var b=s(new class{constructor(){t(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,s)=>{$(e,{cwd:this.cwd??void 0},(e=>{e?s(e):t()}))}))}});class S extends I{constructor(e,s){super(),t(this,"path",void 0),t(this,"options",void 0),this.path=e,this.options=s}async run(){const e=this.path,t=this.options.name??"Aerogel App";b.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),j.success(`\n\n That's it! You can start working on **${t}** doing the following:\n\n cd ${e}\n npm run dev\n\n Have fun!\n `)}async createApp(e,t){j.info(`Creating **${e}**...`),new F(e,{local:this.options.local}).create(t)}async installDependencies(){await j.animate("Installing dependencies",(async()=>{await b.run("npm install")}))}async initializeGit(){await j.animate("Initializing git",(async()=>{await b.run("git init"),await b.run("git add ."),await b.run('git commit -m "Start"')}))}}t(S,"command","create"),t(S,"description","Create AerogelJS app"),t(S,"parameters",[["path","Application path"]]),t(S,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used for core development)"}});class O extends I{constructor(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),t(this,"path",void 0),t(this,"options",void 0),this.path=e,this.options=s}async run(){this.assertAerogelOrDirectory("src/components"),this.options.story&&this.assertHistoireInstalled(),x.exists(`src/components/${this.path}.vue`)&&j.fail(`${this.path} component already exists!`);const[e,t]=this.parsePathComponents(),s=k.instantiate(A("templates/component"),`src/components/${e}`,{component:{name:t}});if(this.options.story){const e=k.instantiate(A("templates/component-story"),"src/components",{component:{name:t}});s.push(...e)}const n=s.map((e=>`- ${e}`)).join("\n");j.info(`${t} component created successfully! The following files were created:\n\n${n}`)}assertHistoireInstalled(){x.exists("src/main.histoire.ts")||j.fail("Histoire is not installed yet!")}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}t(O,"command","generate:component"),t(O,"description","Generate an AerogelJS component"),t(O,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),t(O,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class C extends I{constructor(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),t(this,"name",void 0),t(this,"options",void 0),this.name=e,this.options=s}async run(){this.assertAerogelOrDirectory("src/models"),x.exists(`src/models/${this.name}.ts`)&&j.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=k.instantiate(A("templates/model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n");j.info(`${this.name} model created successfully! The following files were created:\n\n${e}`)}getFieldsDefinition(){if(!this.options.fields)return" //";const e=this.options.fields.split(",").map((e=>{const[t,s,n]=e.split(":");return{name:t,type:r(s??"string"),required:"required"===n}})).reduce(((e,t)=>e+`\n${t.required?D(`\n ${t.name}: {\n type: FieldType.${t.type},\n required: true,\n }\n `):`${t.name}: FieldType.${t.type}`},`),"");return D(e,{indent:8})}assertSoukaiInstalled(){x.contains("package.json",'"soukai"')||x.contains("package.json",'"@aerogel/plugin-soukai"')||j.fail("\n Soukai is not installed yet! You can install it doing the following:\n\n 1. Run the following command:\n npm install soukai @aerogel/plugin-soukai@next\n\n 2. Add this to your plugins array in src/main.ts:\n soukai({ models: import.meta.glob('@/models/*', { eager: true }) })\n ")}}t(C,"command","generate:model"),t(C,"description","Generate an AerogelJS model"),t(C,"parameters",[["name","Model name"]]),t(C,"options",{fields:"Create model with the given fields"});var M=s(new class{run(t){const s=new e;s.name("ag").description("AerogelJS CLI").version("0.0.0"),S.define(s),O.define(s),C.define(s),s.parse(t)}});export{M as CLI};
|
|
2
2
|
//# sourceMappingURL=aerogel-cli.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerogel/cli",
|
|
3
3
|
"description": "Aerogel CLI",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.59bf5f7cc06e728d0cf6c00de28f1da48d7d6b8e",
|
|
5
5
|
"main": "dist/aerogel-cli.cjs.js",
|
|
6
6
|
"module": "dist/aerogel-cli.esm.js",
|
|
7
7
|
"types": "dist/aerogel-cli.d.ts",
|
|
@@ -7,13 +7,14 @@ import { CreateCommand } from './create';
|
|
|
7
7
|
|
|
8
8
|
describe('Create command', () => {
|
|
9
9
|
|
|
10
|
-
it('
|
|
10
|
+
it('creates apps', async () => {
|
|
11
11
|
// Act
|
|
12
12
|
await CreateCommand.run('./app', { name: 'My App' });
|
|
13
13
|
|
|
14
14
|
// Assert
|
|
15
15
|
FileMock.expectCreated('./app/.gitignore').toContain('node_modules');
|
|
16
16
|
FileMock.expectCreated('./app/package.json').toContain('"name": "my-app"');
|
|
17
|
+
FileMock.expectCreated('./app/package.json').toContain('"@aerogel/core": "next"');
|
|
17
18
|
FileMock.expectCreated('./app/index.html').toContain('My App');
|
|
18
19
|
FileMock.expectCreated('./app/src/App.vue').toContain(
|
|
19
20
|
'<h1 class="text-4xl font-semibold">{{ $t(\'home.title\') }}</h1>',
|
|
@@ -23,4 +24,12 @@ describe('Create command', () => {
|
|
|
23
24
|
ShellMock.expectRan('git init');
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
it('creates apps for local core development', async () => {
|
|
28
|
+
// Act
|
|
29
|
+
await CreateCommand.run('./app', { name: 'My App', local: true });
|
|
30
|
+
|
|
31
|
+
// Assert
|
|
32
|
+
FileMock.expectCreated('./app/package.json').toMatch(/"@aerogel\/core": "file:[^"]+\/packages\/core"/);
|
|
33
|
+
});
|
|
34
|
+
|
|
26
35
|
});
|
package/src/commands/create.ts
CHANGED
|
@@ -2,9 +2,11 @@ import App from '@/lib/App';
|
|
|
2
2
|
import Command from '@/commands/Command';
|
|
3
3
|
import Log from '@/lib/Log';
|
|
4
4
|
import Shell from '@/lib/Shell';
|
|
5
|
+
import type { CommandOptions } from '@/commands/Command';
|
|
5
6
|
|
|
6
7
|
export interface Options {
|
|
7
8
|
name?: string;
|
|
9
|
+
local?: boolean;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export class CreateCommand extends Command {
|
|
@@ -12,8 +14,12 @@ export class CreateCommand extends Command {
|
|
|
12
14
|
public static command: string = 'create';
|
|
13
15
|
public static description: string = 'Create AerogelJS app';
|
|
14
16
|
public static parameters: [string, string][] = [['path', 'Application path']];
|
|
15
|
-
public static options:
|
|
17
|
+
public static options: CommandOptions = {
|
|
16
18
|
name: 'Application name',
|
|
19
|
+
local: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
description: 'Whether to create an app linked to local Aerogel packages (used for core development)',
|
|
22
|
+
},
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
private path: string;
|
|
@@ -36,20 +42,21 @@ export class CreateCommand extends Command {
|
|
|
36
42
|
await this.installDependencies();
|
|
37
43
|
await this.initializeGit();
|
|
38
44
|
|
|
39
|
-
Log.success(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
Log.success(`
|
|
46
|
+
|
|
47
|
+
That's it! You can start working on **${name}** doing the following:
|
|
48
|
+
|
|
49
|
+
cd ${path}
|
|
50
|
+
npm run dev
|
|
51
|
+
|
|
52
|
+
Have fun!
|
|
53
|
+
`);
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
protected async createApp(name: string, path: string): Promise<void> {
|
|
50
57
|
Log.info(`Creating **${name}**...`);
|
|
51
58
|
|
|
52
|
-
new App(name).create(path);
|
|
59
|
+
new App(name, { local: this.options.local }).create(path);
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
protected async installDependencies(): Promise<void> {
|
|
@@ -17,6 +17,17 @@ describe('Generate component command', () => {
|
|
|
17
17
|
FileMock.expectCreated('src/components/FooBar.vue').toContain('<div>FooBar</div>');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
it('generates components in subfolders', async () => {
|
|
21
|
+
// Arrange
|
|
22
|
+
FileMock.stub('package.json', '@aerogel/core');
|
|
23
|
+
|
|
24
|
+
// Act
|
|
25
|
+
await GenerateComponentCommand.run('module/FooBar');
|
|
26
|
+
|
|
27
|
+
// Assert
|
|
28
|
+
FileMock.expectCreated('src/components/module/FooBar.vue').toContain('<div>FooBar</div>');
|
|
29
|
+
});
|
|
30
|
+
|
|
20
31
|
it('generates components with stories', async () => {
|
|
21
32
|
// Arrange
|
|
22
33
|
FileMock.stub('package.json', '@aerogel/core');
|
|
@@ -13,7 +13,10 @@ export class GenerateComponentCommand extends Command {
|
|
|
13
13
|
|
|
14
14
|
public static command: string = 'generate:component';
|
|
15
15
|
public static description: string = 'Generate an AerogelJS component';
|
|
16
|
-
public static parameters: [string, string][] = [
|
|
16
|
+
public static parameters: [string, string][] = [
|
|
17
|
+
['path', 'Component path (relative to components folder; extension not necessary)'],
|
|
18
|
+
];
|
|
19
|
+
|
|
17
20
|
public static options: CommandOptions = {
|
|
18
21
|
story: {
|
|
19
22
|
description: 'Create component story using Histoire',
|
|
@@ -21,13 +24,13 @@ export class GenerateComponentCommand extends Command {
|
|
|
21
24
|
},
|
|
22
25
|
};
|
|
23
26
|
|
|
24
|
-
private
|
|
27
|
+
private path: string;
|
|
25
28
|
private options: Options;
|
|
26
29
|
|
|
27
|
-
constructor(
|
|
30
|
+
constructor(path: string, options: Options = {}) {
|
|
28
31
|
super();
|
|
29
32
|
|
|
30
|
-
this.
|
|
33
|
+
this.path = path;
|
|
31
34
|
this.options = options;
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -35,17 +38,18 @@ export class GenerateComponentCommand extends Command {
|
|
|
35
38
|
this.assertAerogelOrDirectory('src/components');
|
|
36
39
|
this.options.story && this.assertHistoireInstalled();
|
|
37
40
|
|
|
38
|
-
if (File.exists(`src/components/${this.
|
|
39
|
-
Log.fail(`${this.
|
|
41
|
+
if (File.exists(`src/components/${this.path}.vue`)) {
|
|
42
|
+
Log.fail(`${this.path} component already exists!`);
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
const
|
|
43
|
-
|
|
45
|
+
const [directoryName, componentName] = this.parsePathComponents();
|
|
46
|
+
const files = Template.instantiate(basePath('templates/component'), `src/components/${directoryName}`, {
|
|
47
|
+
component: { name: componentName },
|
|
44
48
|
});
|
|
45
49
|
|
|
46
50
|
if (this.options.story) {
|
|
47
51
|
const storyFiles = Template.instantiate(basePath('templates/component-story'), 'src/components', {
|
|
48
|
-
component: { name:
|
|
52
|
+
component: { name: componentName },
|
|
49
53
|
});
|
|
50
54
|
|
|
51
55
|
files.push(...storyFiles);
|
|
@@ -53,7 +57,7 @@ export class GenerateComponentCommand extends Command {
|
|
|
53
57
|
|
|
54
58
|
const filesList = files.map((file) => `- ${file}`).join('\n');
|
|
55
59
|
|
|
56
|
-
Log.info(`${
|
|
60
|
+
Log.info(`${componentName} component created successfully! The following files were created:\n\n${filesList}`);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
protected assertHistoireInstalled(): void {
|
|
@@ -62,4 +66,12 @@ export class GenerateComponentCommand extends Command {
|
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
protected parsePathComponents(): [string, string] {
|
|
70
|
+
const lastSlashIndex = this.path.lastIndexOf('/');
|
|
71
|
+
|
|
72
|
+
return lastSlashIndex === -1
|
|
73
|
+
? ['', this.path]
|
|
74
|
+
: [this.path.substring(0, lastSlashIndex), this.path.substring(lastSlashIndex + 1)];
|
|
75
|
+
}
|
|
76
|
+
|
|
65
77
|
}
|
|
@@ -21,7 +21,7 @@ describe('Generate model command', () => {
|
|
|
21
21
|
|
|
22
22
|
// Act
|
|
23
23
|
await GenerateModelCommand.run('FooBar', {
|
|
24
|
-
fields: 'name:string,age:number,birth:Date',
|
|
24
|
+
fields: 'name:string:required,age:number,birth:Date',
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
// Assert
|
|
@@ -30,7 +30,10 @@ describe('Generate model command', () => {
|
|
|
30
30
|
formatCodeBlock(`
|
|
31
31
|
defineModelSchema({
|
|
32
32
|
fields: {
|
|
33
|
-
name:
|
|
33
|
+
name: {
|
|
34
|
+
type: FieldType.String,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
34
37
|
age: FieldType.Number,
|
|
35
38
|
birth: FieldType.Date,
|
|
36
39
|
},
|
|
@@ -60,21 +60,41 @@ export class GenerateModelCommand extends Command {
|
|
|
60
60
|
const code = this.options.fields
|
|
61
61
|
.split(',')
|
|
62
62
|
.map((field) => {
|
|
63
|
-
const [name, type] = field.split(':');
|
|
63
|
+
const [name, type, rules] = field.split(':');
|
|
64
64
|
|
|
65
65
|
return {
|
|
66
66
|
name,
|
|
67
67
|
type: stringToStudlyCase(type ?? 'string'),
|
|
68
|
+
required: rules === 'required',
|
|
68
69
|
};
|
|
69
70
|
})
|
|
70
|
-
.reduce((definition, field) =>
|
|
71
|
+
.reduce((definition, field) => {
|
|
72
|
+
const fieldDefinition = field.required
|
|
73
|
+
? formatCodeBlock(`
|
|
74
|
+
${field.name}: {
|
|
75
|
+
type: FieldType.${field.type},
|
|
76
|
+
required: true,
|
|
77
|
+
}
|
|
78
|
+
`)
|
|
79
|
+
: `${field.name}: FieldType.${field.type}`;
|
|
80
|
+
|
|
81
|
+
return definition + `\n${fieldDefinition},`;
|
|
82
|
+
}, '');
|
|
71
83
|
|
|
72
84
|
return formatCodeBlock(code, { indent: 8 });
|
|
73
85
|
}
|
|
74
86
|
|
|
75
87
|
protected assertSoukaiInstalled(): void {
|
|
76
|
-
if (!File.contains('package.json', '"soukai"')) {
|
|
77
|
-
Log.fail(
|
|
88
|
+
if (!File.contains('package.json', '"soukai"') && !File.contains('package.json', '"@aerogel/plugin-soukai"')) {
|
|
89
|
+
Log.fail(`
|
|
90
|
+
Soukai is not installed yet! You can install it doing the following:
|
|
91
|
+
|
|
92
|
+
1. Run the following command:
|
|
93
|
+
npm install soukai @aerogel/plugin-soukai@next
|
|
94
|
+
|
|
95
|
+
2. Add this to your plugins array in src/main.ts:
|
|
96
|
+
soukai({ models: import.meta.glob('@/models/*', { eager: true }) })
|
|
97
|
+
`);
|
|
78
98
|
}
|
|
79
99
|
}
|
|
80
100
|
|
package/src/lib/App.ts
CHANGED
|
@@ -5,9 +5,13 @@ import Log from '@/lib/Log';
|
|
|
5
5
|
import Template from '@/lib/Template';
|
|
6
6
|
import { basePath } from '@/lib/utils';
|
|
7
7
|
|
|
8
|
+
export interface Options {
|
|
9
|
+
local?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export default class App {
|
|
9
13
|
|
|
10
|
-
constructor(
|
|
14
|
+
constructor(protected name: string, protected options: Options = {}) {}
|
|
11
15
|
|
|
12
16
|
public create(path: string): void {
|
|
13
17
|
if (File.exists(path) && (!File.isDirectory(path) || !File.isEmptyDirectory(path))) {
|
|
@@ -19,6 +23,9 @@ export default class App {
|
|
|
19
23
|
name: this.name,
|
|
20
24
|
slug: stringToSlug(this.name),
|
|
21
25
|
},
|
|
26
|
+
local: this.options.local && {
|
|
27
|
+
aerogelPath: basePath('../'),
|
|
28
|
+
},
|
|
22
29
|
});
|
|
23
30
|
}
|
|
24
31
|
|
package/src/lib/Log.mock.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { facade } from '@noeldemartin/utils';
|
|
3
3
|
|
|
4
4
|
import { LogService } from './Log';
|
|
5
5
|
|
|
@@ -11,14 +11,22 @@ export class LogServiceMock extends LogService {
|
|
|
11
11
|
expect(this.logs, `Expected message "${message}" to have been logged`).toContain(message);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
this.logs.
|
|
14
|
+
public expectLogLength(count: number): void {
|
|
15
|
+
expect(this.logs, `Expected log to have length ${count}`).toHaveLength(count);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected logLine(message: string): void {
|
|
19
|
+
this.logs.push(message);
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
public fail(message: string): void {
|
|
19
23
|
throw new Error(`Fail: ${message}`);
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
public reset(): void {
|
|
27
|
+
this.logs = [];
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
protected stdout(): void {
|
|
23
31
|
//
|
|
24
32
|
}
|
package/src/lib/Log.test.ts
CHANGED
|
@@ -5,12 +5,11 @@ import LogMock from '@/lib/Log.mock';
|
|
|
5
5
|
|
|
6
6
|
import Log from './Log';
|
|
7
7
|
|
|
8
|
+
const info = hex('#00ffff');
|
|
9
|
+
|
|
8
10
|
describe('Log', () => {
|
|
9
11
|
|
|
10
12
|
it('renders markdown bold', () => {
|
|
11
|
-
// Arrange
|
|
12
|
-
const info = hex('#00ffff');
|
|
13
|
-
|
|
14
13
|
// Act
|
|
15
14
|
Log.info('Foo **bar**');
|
|
16
15
|
|
|
@@ -18,4 +17,21 @@ describe('Log', () => {
|
|
|
18
17
|
LogMock.expectLogged(info(`Foo ${bold('bar')}`));
|
|
19
18
|
});
|
|
20
19
|
|
|
20
|
+
it('renders multiline messages', () => {
|
|
21
|
+
// Act
|
|
22
|
+
Log.info(`
|
|
23
|
+
This is multiline,
|
|
24
|
+
but the indentation should be respected.
|
|
25
|
+
|
|
26
|
+
As well as the new lines.
|
|
27
|
+
`);
|
|
28
|
+
|
|
29
|
+
// Assert
|
|
30
|
+
LogMock.expectLogLength(4);
|
|
31
|
+
LogMock.expectLogged(info('This is multiline,'));
|
|
32
|
+
LogMock.expectLogged(info(' but the indentation should be respected.'));
|
|
33
|
+
LogMock.expectLogged(info(''));
|
|
34
|
+
LogMock.expectLogged(info('As well as the new lines.'));
|
|
35
|
+
});
|
|
36
|
+
|
|
21
37
|
});
|
package/src/lib/Log.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { facade, stringMatchAll } from '@noeldemartin/utils';
|
|
2
2
|
import { bold, hex } from 'chalk';
|
|
3
3
|
import { clearLine, cursorTo } from 'readline';
|
|
4
4
|
|
|
@@ -28,28 +28,22 @@ export class LogService {
|
|
|
28
28
|
return result;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public info(
|
|
32
|
-
|
|
33
|
-
this.log(this.renderInfo(this.renderMarkdown(message)));
|
|
34
|
-
});
|
|
31
|
+
public info(message: string): void {
|
|
32
|
+
this.log(this.renderMarkdown(message), this.renderInfo);
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
public error(
|
|
38
|
-
|
|
39
|
-
this.log(this.renderError(this.renderMarkdown(message)));
|
|
40
|
-
});
|
|
35
|
+
public error(message: string): void {
|
|
36
|
+
this.log(this.renderMarkdown(message), this.renderError);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
public fail(
|
|
44
|
-
this.error(
|
|
39
|
+
public fail(message: string): void {
|
|
40
|
+
this.error(message);
|
|
45
41
|
|
|
46
42
|
process.exit(1);
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
public success(
|
|
50
|
-
|
|
51
|
-
this.log(this.renderSuccess(this.renderMarkdown(message)));
|
|
52
|
-
});
|
|
45
|
+
public success(message: string): void {
|
|
46
|
+
this.log(this.renderMarkdown(message), this.renderSuccess);
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
protected renderMarkdown(message: string): string {
|
|
@@ -62,9 +56,29 @@ export class LogService {
|
|
|
62
56
|
return message;
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
protected log(
|
|
59
|
+
protected log(message: string, formatMessage?: (message: string) => string): void {
|
|
60
|
+
this.formatMessage(message).forEach((line) => {
|
|
61
|
+
this.logLine(formatMessage ? formatMessage(line) : line);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected formatMessage(message: string): string[] {
|
|
66
|
+
if (message[0] === '\n') {
|
|
67
|
+
message = message.slice(1).trimEnd();
|
|
68
|
+
|
|
69
|
+
const lines = message.split('\n');
|
|
70
|
+
const firstLetter = message.trim()[0] ?? '';
|
|
71
|
+
const indentation = lines.find((line) => line.trim().length > 0)?.indexOf(firstLetter) ?? 0;
|
|
72
|
+
|
|
73
|
+
return lines.map((line) => line.slice(indentation));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return [message];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected logLine(line: string): void {
|
|
66
80
|
// eslint-disable-next-line no-console
|
|
67
|
-
|
|
81
|
+
console.log(line);
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
protected stdout(message: string): void {
|
package/src/lib/utils.ts
CHANGED
package/src/testing/setup.ts
CHANGED
|
@@ -17,6 +17,8 @@ Shell.setMockInstance(ShellMock);
|
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
|
19
19
|
FileMock.reset();
|
|
20
|
+
LogMock.reset();
|
|
21
|
+
|
|
20
22
|
File.mock();
|
|
21
23
|
Log.mock();
|
|
22
24
|
Shell.mock();
|
|
@@ -29,7 +31,7 @@ vi.mock('@/lib/utils', async () => {
|
|
|
29
31
|
|
|
30
32
|
return {
|
|
31
33
|
...utils,
|
|
32
|
-
basePath(path: string) {
|
|
34
|
+
basePath(path: string = '') {
|
|
33
35
|
return resolve(__dirname, '../../', path);
|
|
34
36
|
},
|
|
35
37
|
};
|
|
@@ -15,28 +15,28 @@
|
|
|
15
15
|
"test:serve-app": "vite --port 5001"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@aerogel/core": "next",
|
|
19
|
-
"@aerogel/plugin-i18n": "next",
|
|
18
|
+
"@aerogel/core": "<% #local %>file:<% &local.aerogelPath %>/core<% /local %><% ^local %>next<% /local %>",
|
|
19
|
+
"@aerogel/plugin-i18n": "<% #local %>file:<% &local.aerogelPath %>/plugin-i18n<% /local %><% ^local %>next<% /local %>",
|
|
20
|
+
"@aerogel/plugin-soukai": "<% #local %>file:<% &local.aerogelPath %>/plugin-soukai<% /local %><% ^local %>next<% /local %>",
|
|
20
21
|
"@intlify/unplugin-vue-i18n": "^0.12.2",
|
|
22
|
+
"@noeldemartin/utils": "next",
|
|
21
23
|
"@tailwindcss/forms": "^0.5.3",
|
|
22
24
|
"@tailwindcss/typography": "^0.5.9",
|
|
23
|
-
"soukai": "^0.5.1",
|
|
24
25
|
"tailwindcss": "^3.3.2",
|
|
25
26
|
"vue": "^3.3.0",
|
|
26
|
-
"vue-i18n": "9.3.0-beta.19"
|
|
27
|
-
"vue-router": "^4.2.1"
|
|
27
|
+
"vue-i18n": "9.3.0-beta.19"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@aerogel/cli": "next",
|
|
31
|
-
"@aerogel/cypress": "next",
|
|
32
|
-
"@aerogel/vite": "next",
|
|
33
|
-
"@noeldemartin/utils": "0.4.0-next.ac00beaecf32bb02ed8e335225d7948d946d73bd",
|
|
30
|
+
"@aerogel/cli": "<% #local %>file:<% &local.aerogelPath %>/cli<% /local %><% ^local %>next<% /local %>",
|
|
31
|
+
"@aerogel/cypress": "<% #local %>file:<% &local.aerogelPath %>/cypress<% /local %><% ^local %>next<% /local %>",
|
|
32
|
+
"@aerogel/vite": "<% #local %>file:<% &local.aerogelPath %>/vite<% /local %><% ^local %>next<% /local %>",
|
|
34
33
|
"@total-typescript/ts-reset": "^0.4.2",
|
|
35
34
|
"@types/node": "^20.3.1",
|
|
36
35
|
"autoprefixer": "^10.4.14",
|
|
37
36
|
"concurrently": "^8.2.0",
|
|
38
37
|
"cypress": "^12.17.0",
|
|
39
38
|
"start-server-and-test": "^2.0.0",
|
|
39
|
+
"unplugin-icons": "^0.16.3",
|
|
40
40
|
"unplugin-vue-components": "^0.24.1",
|
|
41
41
|
"vite": "^4.3.0",
|
|
42
42
|
"vitest": "^0.33.0"
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import i18n from '@aerogel/plugin-i18n';
|
|
2
|
+
import soukai from '@aerogel/plugin-soukai';
|
|
2
3
|
import { bootstrapApplication } from '@aerogel/core';
|
|
3
4
|
|
|
4
5
|
import './assets/styles.css';
|
|
5
6
|
import App from './App.vue';
|
|
6
7
|
|
|
7
8
|
bootstrapApplication(App, {
|
|
8
|
-
plugins: [
|
|
9
|
+
plugins: [
|
|
10
|
+
i18n({ messages: import.meta.glob('@/lang/*.yaml') }),
|
|
11
|
+
soukai({ models: import.meta.glob('@/models/*', { eager: true }) }),
|
|
12
|
+
],
|
|
9
13
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @type {import('tailwindcss').Config} */
|
|
2
2
|
module.exports = {
|
|
3
|
-
content: ['./index.html', './src/**/*.{vue,ts}', '
|
|
3
|
+
content: ['./index.html', './src/**/*.{vue,ts}', './node_modules/@aerogel/core/dist/**/*.js'],
|
|
4
4
|
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
|
|
5
5
|
};
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import Aerogel, { AerogelResolver } from '@aerogel/vite';
|
|
2
2
|
import Components from 'unplugin-vue-components/vite';
|
|
3
3
|
import I18n from '@intlify/unplugin-vue-i18n/vite';
|
|
4
|
+
import Icons from 'unplugin-icons/vite';
|
|
5
|
+
import IconsResolver from 'unplugin-icons/resolver';
|
|
4
6
|
import { resolve } from 'path';
|
|
5
7
|
|
|
6
8
|
export default {
|
|
7
9
|
plugins: [
|
|
8
|
-
I18n({ include: resolve(__dirname, './src/lang/**/*.yaml') }),
|
|
9
10
|
Aerogel(),
|
|
10
11
|
Components({
|
|
11
12
|
dirs: ['src/pages'],
|
|
12
13
|
dts: false,
|
|
13
|
-
resolvers: [AerogelResolver()],
|
|
14
|
+
resolvers: [AerogelResolver(), IconsResolver()],
|
|
14
15
|
}),
|
|
16
|
+
I18n({ include: resolve(__dirname, './src/lang/**/*.yaml') }),
|
|
17
|
+
Icons(),
|
|
15
18
|
],
|
|
16
19
|
resolve: {
|
|
17
20
|
alias: {
|