@aerogel/cli 0.0.0-next.b85327579d32f21c6a9fa21142f0165cdd320d7e → 0.0.0-next.f16bd1d894543c5303039c49f6f33488a1ffe931
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/generate-component.ts +5 -7
- package/src/commands/generate-model.ts +2 -2
- package/src/commands/generate-service.ts +2 -2
- package/src/commands/install.test.ts +2 -2
- package/src/lib/App.ts +2 -2
- package/src/lib/utils/paths.ts +4 -0
- package/src/plugins/Plugin.ts +1 -1
- package/src/plugins/Solid.ts +1 -1
- package/src/plugins/Soukai.ts +1 -1
- package/src/testing/setup.ts +5 -0
- package/templates/app/vite.config.ts +3 -2
- package/noeldemartin.config.js +0 -14
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");require("core-js/modules/esnext.async-iterator.reduce.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var i=require("@noeldemartin/utils"),s=require("fs"),n=require("path");require("core-js/modules/esnext.async-iterator.for-each.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"),a=require("readline"),o=require("mustache");require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js");var l=require("ts-morph"),c=require("child_process");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("core-js/modules/esnext.async-iterator.some.js"),require("core-js/modules/esnext.iterator.some.js");var u=d(t);var p=i.facade(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return s.existsSync(e)}isSymlink(e){return s.lstatSync(e).isSymbolicLink()}read(e){return this.isFile(e)?s.readFileSync(e).toString():null}getFiles(e){const t=s.readdirSync(e,{withFileTypes:!0}),i=[];for(const s of t){const t=n.resolve(e,s.name);s.isDirectory()?i.push(...this.getFiles(t)):i.push(t)}return i}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(n.dirname(e))||s.mkdirSync(n.dirname(e),{recursive:!0}),s.writeFileSync(e,t)}});var m=i.facade(new class{constructor(){u.default(this,"renderInfo",r.hex("#00ffff")),u.default(this,"renderSuccess",r.hex("#00ff00")),u.default(this,"renderError",r.hex("#ff0000"))}async animate(e,t){var i=this;const s=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=i.renderInfo(i.renderMarkdown(e)+(s?"...":".".repeat(n%4)))+t;i.stdout(r)};let n=0;s();const r=setInterval((()=>(n++,s())),1e3),a=await t();return clearInterval(r),s("\n",!0),a}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=i.stringMatchAll(e,/\*\*(.*)\*\*/g);for(const i of t)e=e.replace(i[0],r.bold(i[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"),i=e.trim()[0]??"",s=t.find((e=>e.trim().length>0))?.indexOf(i)??0;return t.map((e=>e.slice(s)))}return[e]}logLine(e){console.log(e)}stdout(e){a.cursorTo(process.stdout,0),a.clearLine(process.stdout,0),process.stdout.write(e)}});class g{static instantiate(e,t,i){return new g(e).instantiate(t,i)}constructor(e){u.default(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.getFilenameReplacements(t),n=[];e=`${e}/`.replace(/\/\//,"/");for(const r of p.getFiles(this.path)){const a=Object.entries(i).reduce(((e,t)=>{let[i,s]=t;return e.replaceAll(i,s)}),r.substring(this.path.length+1)),l=s.readFileSync(r).toString(),c=e+(a.endsWith(".template")?a.slice(0,-9):a);p.write(c,o.render(l,t,void 0,["<%","%>"])),n.push(c)}return n}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,s)=>{let[n,r]=s;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${n}.`)):e[`[${t}${n}]`]=i.toString(r),e}),{})}}function f(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(p.contains(n.resolve(__dirname,"../../../package.json"),'"name": "aerogel"'))return n.resolve(__dirname,"../",e);const t=p.read(n.resolve(__dirname,"../../../../package.json")),s=i.stringMatch(t??"",/"@aerogel\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/),r=s?.[1]??m.fail("Could not determine base path");return n.resolve(r,e)}function h(e){return m.fail(`Could not find ${e} pack file, did you run 'npm pack'?`)}function y(e){return p.getFiles(v(e)).find((e=>e.endsWith(".tgz")))??null}function v(e){return f(`../${e}`)}var w=i.facade(new class{constructor(){u.default(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,i)=>{c.exec(e,{cwd:this.cwd??void 0},(e=>{e?i(e):t()}))}))}});class x{constructor(){u.default(this,"project",void 0),u.default(this,"modifiedFiles",void 0),this.project=new l.Project({tsConfigFilePath:"tsconfig.json"}),this.modifiedFiles=new Set,this.project.addSourceFilesAtPaths("src/**/*.ts"),this.project.addSourceFilesAtPaths("tailwind.config.js"),this.project.addSourceFilesAtPaths("vite.config.ts")}addSourceFile(e){this.project.addSourceFilesAtPaths(e)}requireSourceFile(e){return this.project.getSourceFileOrThrow(e)}async format(){await m.animate("Formatting modified files",(async()=>{const e=p.exists("prettier.config.js"),t=p.exists(".eslintrc.js");await Promise.all(i.arrayFrom(this.modifiedFiles).map((async i=>{e&&await w.run(`npx prettier ${i} --write`),t&&await w.run(`npx eslint ${i} --fix`)})))}))}async save(e){await e.save(),this.modifiedFiles.add(e.getFilePath())}}class j{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};u.default(this,"name",void 0),u.default(this,"options",void 0),this.name=e,this.options=t}create(e){!p.exists(e)||p.isDirectory(e)&&p.isEmptyDirectory(e)||m.fail(`Folder at '${e}' already exists!`),g.instantiate(f("templates/app"),e,{app:{name:this.name,slug:i.stringToSlug(this.name)},dependencies:this.getDependencies(),contentPath:this.options.linkedLocal?`${v("core")}/dist/**/*.js`:"./node_modules/@aerogel/core/dist/**/*.js"})}edit(){return new x}getDependencies(){const e=e=>Object.entries(e).reduce(((e,t)=>{let[i,s]=t;return Object.assign(e,{[i]:`file:${s}`})}),{});return this.options.linkedLocal?e({aerogelCli:v("cli"),aerogelCore:v("core"),aerogelCypress:v("cypress"),aerogelPluginI18n:v("plugin-i18n"),aerogelPluginSoukai:v("plugin-soukai"),aerogelVite:v("vite")}):this.options.local?e({aerogelCli:y("cli")??h("cli"),aerogelCore:y("core")??h("core"),aerogelCypress:y("cypress")??h("cypress"),aerogelPluginI18n:y("plugin-i18n")??h("plugin-i18n"),aerogelPluginSoukai:y("plugin-soukai")??h("plugin-soukai"),aerogelVite:y("vite")??h("vite")}):{aerogelCli:"next",aerogelCore:"next",aerogelCypress:"next",aerogelPluginI18n:"next",aerogelPluginSoukai:"next",aerogelVite:"next"}}}class S{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,i]of this.parameters)e=e.argument(`<${t}>`,i);for(const[t,i]of Object.entries(this.options)){const s="string"==typeof i?i:i.description,n="string"==typeof i?"string":i.type??"string";e=e.option("boolean"===n?`--${t}`:`--${t} <${n}>`,s)}e=e.action((function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return t.run.call(t,...i)}))}static async run(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];const s=new this(...t);await s.run()}async run(){}assertAerogelOrDirectory(e){const t=p.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&p.isDirectory(e))return;const i=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";m.fail(`${i} Are you sure this is an Aerogel app?`)}}u.default(S,"command",""),u.default(S,"description",""),u.default(S,"parameters",[]),u.default(S,"options",{});class k extends S{constructor(e,t){super(),u.default(this,"path",void 0),u.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(),m.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){m.info(`Creating **${e}**...`),new j(e,{local:this.options.local,linkedLocal:this.options.local&&!this.options.copy}).create(t)}async installDependencies(){await m.animate("Installing dependencies",(async()=>{await w.run("npm install")}))}async initializeGit(){await m.animate("Initializing git",(async()=>{await w.run("git init"),await w.run("git add ."),await w.run('git commit -m "Start"')}))}}function $(){return new j("")}function C(){return p.isSymlink("node_modules/@aerogel/core")}function A(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return;const s=t.guard??(()=>!0),n=t.validate??(()=>!0),r=i.arrayFrom(t.skip??[]);return e.forEachDescendant(((e,t)=>{if(s(e)&&n(e))return e;const i=e.getKind();r.includes(i)&&t.skip()}))}function F(e,t){if(e&&t(e))return e}u.default(k,"command","create"),u.default(k,"description","Create AerogelJS app"),u.default(k,"parameters",[["path","Application path"]]),u.default(k,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app using local Aerogel packages (used for core development)"},copy:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used in CI)"}});class q extends S{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),u.default(this,"path",void 0),u.default(this,"options",void 0),this.path=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/components"),this.assertHistoireInstalled();const e=new Set,[t,s]=this.parsePathComponents();await this.createComponent(t,s,e),await this.createStory(s,e),await this.declareComponents();const n=i.arrayFrom(e).map((e=>`- ${e}`)).join("\n");m.info(`${s} component created successfully! The following files were created:\n\n${n}`)}assertHistoireInstalled(){this.options.story&&(p.exists("src/main.histoire.ts")||m.fail("Histoire is not installed yet!"))}async createComponent(e,t,i){await m.animate("Creating component",(async()=>{p.exists(`src/components/${this.path}.vue`)&&m.fail(`${this.path} component already exists!`);g.instantiate(f("templates/component"),`src/components/${e}`,{component:{name:t}}).forEach((e=>i.add(e)))}))}async createStory(e,t){this.options.story&&await m.animate("Creating story",(async()=>{g.instantiate(f("templates/component-story"),"src/components",{component:{name:e}}).forEach((e=>t.add(e)))}))}async declareComponents(){const e=$().edit(),t=e.requireSourceFile("vite.config.ts"),i=this.getComponentDirsArray(t);if(!i)return m.fail("Could not find component dirs declaration in vite config!");i.getDescendantsOfKind(l.SyntaxKind.StringLiteral).some((e=>"'src/components'"===e.getText()))||(await m.animate("Updating vite config",(async()=>{i.addElement("'src/components'"),await e.save(t)})),await e.format())}getComponentDirsArray(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>e.getText().startsWith("Components("),skip:l.SyntaxKind.ImportDeclaration});if(!t)return null;const i=A(t,{guard:l.Node.isPropertyAssignment,validate:e=>"dirs"===e.getName()}),s=i?.getInitializer();return l.Node.isArrayLiteralExpression(s)?s:this.declareComponentDirsArray(t)}declareComponentDirsArray(e){const t=A(e,{guard:l.Node.isObjectLiteralExpression}),i=t?.addPropertyAssignment({name:"dirs",initializer:"[]"});return i?.getInitializer()??null}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}function D(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.split("\n"),s=t.indent??0;let n=0,r="";for(const e of i){const t=e.trim(),i=0===t.length;if(0===r.length){if(i)continue;n=e.indexOf(t[0]??""),r+=`${" ".repeat(s)}${t}\n`;continue}if(i){r+="\n";continue}const a=e.indexOf(t[0]??"");r+=`${" ".repeat(s+a-n)}${t}\n`}return r.trimEnd()}u.default(q,"command","generate:component"),u.default(q,"description","Generate an AerogelJS Component"),u.default(q,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),u.default(q,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class I extends S{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),u.default(this,"name",void 0),u.default(this,"options",void 0),this.name=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/models"),p.exists(`src/models/${this.name}.ts`)&&m.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=await m.animate("Creating model",(async()=>g.instantiate(f("templates/model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n")));m.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:i.stringToStudlyCase(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(){p.contains("package.json",'"soukai"')||p.contains("package.json",'"@aerogel/plugin-soukai"')||m.fail("\n Soukai is not installed yet! You can install it running:\n npx ag install soukai\n ")}}u.default(I,"command","generate:model"),u.default(I,"description","Generate an AerogelJS Model"),u.default(I,"parameters",[["name","Model name"]]),u.default(I,"options",{fields:"Create model with the given fields"});class P extends S{constructor(e){super(),u.default(this,"name",void 0),this.name=e}async run(){this.assertAerogelOrDirectory("src/services");const e=new Set,t=$().edit();await this.createService(e),await this.registerService(t),await t.format();const s=i.arrayFrom(e).map((e=>`- ${e}`)).join("\n");m.info(`${this.name} service created successfully! The following files were created:\n\n${s}`)}async createService(e){await m.animate("Creating service",(async()=>{p.exists(`src/services/${this.name}.ts`)&&m.fail(`${this.name} service already exists!`);g.instantiate(f("templates/service"),"src/services",{service:{name:this.name}}).forEach((t=>e.add(t)))}))}async registerService(e){await m.animate("Registering service",(async()=>{p.exists("src/services/index.ts")||await this.createServicesIndex(e);const t=e.requireSourceFile("src/services/index.ts"),s=this.getServicesObject(t);if(!s)return m.fail("Could not find services object in services config, please add it manually.");t.addImportDeclaration({defaultImport:this.name,moduleSpecifier:`./${this.name}`}),s.addPropertyAssignment({name:`$${i.stringToCamelCase(this.name)}`,initializer:this.name}),await e.save(t)}))}async createServicesIndex(e){p.write("src/services/index.ts",D("\n export const services = {};\n\n export type AppServices = typeof services;\n\n declare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends AppServices {}\n }\n ")),e.addSourceFile("src/services/index.ts");const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapOptions(t);if(!i)return m.fail("Could not find options object in bootstrap config, please add the services manually.");i.insertShorthandPropertyAssignment(0,{name:"services"}),t.addImportDeclaration({namedImports:["services"],moduleSpecifier:"./services"}),await e.save(t)}getBootstrapOptions(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:l.SyntaxKind.ImportDeclaration}),i=t?.getArguments()[1];return l.Node.isObjectLiteralExpression(i)?i:null}getServicesObject(e){const t=A(e,{guard:l.Node.isVariableDeclaration,validate:e=>"services"===e.getName()}),i=t?.getInitializer();return l.Node.isObjectLiteralExpression(i)?i:null}}u.default(P,"command","generate:service"),u.default(P,"description","Generate an AerogelJS Service"),u.default(P,"parameters",[["name","Service name"]]);class b{constructor(e){u.default(this,"name",void 0),this.name=e}async install(){this.assertNotInstalled(),await this.installDependencies();{const e=$().edit();await this.updateFiles(e),await e.format()}m.info(`Plugin ${this.name} installed!`)}assertNotInstalled(){p.contains("package.json",`"${this.getNpmPackageName()}"`)&&m.fail(`${this.name} is already installed!`)}async installDependencies(){await m.animate("Installing plugin dependencies",(async()=>{await this.installNpmDependencies()}))}async updateFiles(e){await this.updateBootstrapConfig(e)}async installNpmDependencies(){if(C())await w.run(`npm install file:${v(this.getLocalPackageName())}`);else if(p.contains("package.json","file")){const e=y(this.getLocalPackageName())??h(this.getLocalPackageName());await w.run(`npm install file:${e}`)}else await w.run(`npm install ${this.getNpmPackageName()}@next`)}async updateBootstrapConfig(e){await m.animate("Injecting plugin in bootstrap configuration",(async()=>{const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapPluginsDeclaration(t);if(!i)return m.fail(`\n Could not find plugins array in bootstrap config, please add the following manually:\n\n ${this.getBootstrapConfig()}\n `);t.addImportDeclaration(this.getBootstrapImport()),i.addElement(this.getBootstrapConfig()),await e.save(t)}))}getBootstrapPluginsDeclaration(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:l.SyntaxKind.ImportDeclaration}),i=t?.getArguments()[1],s=F(i,l.Node.isObjectLiteralExpression)?.getProperty("plugins"),n=F(s,l.Node.isPropertyAssignment)?.getInitializer();return l.Node.isArrayLiteralExpression(n)?n:null}getBootstrapImport(){return{defaultImport:this.name,moduleSpecifier:`@aerogel/plugin-${this.name}`}}getNpmPackageName(){return`@aerogel/${this.getLocalPackageName()}`}getLocalPackageName(){return`plugin-${this.name}`}getBootstrapConfig(){return`${this.name}()`}}const N=[new class extends b{constructor(){super("soukai")}async installNpmDependencies(){await w.run("npm install soukai@next"),await super.installNpmDependencies()}getBootstrapConfig(){return"soukai({ models: import.meta.glob('@/models/*', { eager: true }) })"}},new class extends b{constructor(){super("solid")}async updateFiles(e){await this.updateTailwindConfig(e),await super.updateFiles(e)}async installNpmDependencies(){await w.run("npm install soukai-solid@next"),await super.installNpmDependencies()}async updateTailwindConfig(e){await m.animate("Updating tailwind configuration",(async()=>{const t=e.requireSourceFile("tailwind.config.js"),i=this.getTailwindContentArray(t),s=C()?`'${v("plugin-solid")}/dist/**/*.js'`:"'./node_modules/@aerogel/plugin-solid/dist/**/*.js'";if(!i)return m.fail(`\n Could not find content array in tailwind config, please add the following manually:\n\n ${s}\n `);i.addElement(s),await e.save(t)}))}getTailwindContentArray(e){const t=A(e,{guard:l.Node.isPropertyAssignment,validate:e=>"content"===e.getName(),skip:l.SyntaxKind.JSDoc}),i=t?.getInitializer();return l.Node.isArrayLiteralExpression(i)?i:null}}].reduce(((e,t)=>Object.assign(e,{[t.name]:t})),{});class O extends S{constructor(e){super(),u.default(this,"plugin",void 0),this.plugin=N[e]??m.fail(`Plugin '${e}' doesn't exist. Available plugins: ${Object.keys(N).join(", ")}`)}async run(){await this.plugin.install()}}u.default(O,"command","install"),u.default(O,"description","Install an AerogelJS plugin"),u.default(O,"parameters",[["plugin","Plugin to install"]]);var E=i.facade(new class{run(t){const i=new e.Command;i.name("ag").description("AerogelJS CLI").version("0.0.0"),k.define(i),q.define(i),I.define(i),P.define(i),O.define(i),i.parse(t)}});exports.CLI=E;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("commander"),t=require("@babel/runtime/helpers/defineProperty");require("core-js/modules/esnext.async-iterator.reduce.js"),require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.reduce.js");var i=require("@noeldemartin/utils"),s=require("fs"),n=require("path");require("core-js/modules/esnext.async-iterator.for-each.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"),a=require("readline"),o=require("mustache");require("core-js/modules/esnext.set.add-all.js"),require("core-js/modules/esnext.set.delete-all.js"),require("core-js/modules/esnext.set.difference.js"),require("core-js/modules/esnext.set.every.js"),require("core-js/modules/esnext.set.filter.js"),require("core-js/modules/esnext.set.find.js"),require("core-js/modules/esnext.set.intersection.js"),require("core-js/modules/esnext.set.is-disjoint-from.js"),require("core-js/modules/esnext.set.is-subset-of.js"),require("core-js/modules/esnext.set.is-superset-of.js"),require("core-js/modules/esnext.set.join.js"),require("core-js/modules/esnext.set.map.js"),require("core-js/modules/esnext.set.reduce.js"),require("core-js/modules/esnext.set.some.js"),require("core-js/modules/esnext.set.symmetric-difference.js"),require("core-js/modules/esnext.set.union.js");var l=require("ts-morph"),c=require("child_process");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("core-js/modules/esnext.async-iterator.some.js"),require("core-js/modules/esnext.iterator.some.js");var u=d(t);var p=i.facade(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return s.existsSync(e)}isSymlink(e){return s.lstatSync(e).isSymbolicLink()}read(e){return this.isFile(e)?s.readFileSync(e).toString():null}getFiles(e){const t=s.readdirSync(e,{withFileTypes:!0}),i=[];for(const s of t){const t=n.resolve(e,s.name);s.isDirectory()?i.push(...this.getFiles(t)):i.push(t)}return i}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(n.dirname(e))||s.mkdirSync(n.dirname(e),{recursive:!0}),s.writeFileSync(e,t)}});var m=i.facade(new class{constructor(){u.default(this,"renderInfo",r.hex("#00ffff")),u.default(this,"renderSuccess",r.hex("#00ff00")),u.default(this,"renderError",r.hex("#ff0000"))}async animate(e,t){var i=this;const s=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=i.renderInfo(i.renderMarkdown(e)+(s?"...":".".repeat(n%4)))+t;i.stdout(r)};let n=0;s();const r=setInterval((()=>(n++,s())),1e3),a=await t();return clearInterval(r),s("\n",!0),a}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=i.stringMatchAll(e,/\*\*(.*)\*\*/g);for(const i of t)e=e.replace(i[0],r.bold(i[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"),i=e.trim()[0]??"",s=t.find((e=>e.trim().length>0))?.indexOf(i)??0;return t.map((e=>e.slice(s)))}return[e]}logLine(e){console.log(e)}stdout(e){a.cursorTo(process.stdout,0),a.clearLine(process.stdout,0),process.stdout.write(e)}});class g{static instantiate(e,t,i){return new g(e).instantiate(t,i)}constructor(e){u.default(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.getFilenameReplacements(t),n=[];e=`${e}/`.replace(/\/\//,"/");for(const r of p.getFiles(this.path)){const a=Object.entries(i).reduce(((e,t)=>{let[i,s]=t;return e.replaceAll(i,s)}),r.substring(this.path.length+1)),l=s.readFileSync(r).toString(),c=e+(a.endsWith(".template")?a.slice(0,-9):a);p.write(c,o.render(l,t,void 0,["<%","%>"])),n.push(c)}return n}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,s)=>{let[n,r]=s;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${n}.`)):e[`[${t}${n}]`]=i.toString(r),e}),{})}}function f(e){return m.fail(`Could not find ${e} pack file, did you run 'npm pack'?`)}function h(e){return p.getFiles(y(e)).find((e=>e.endsWith(".tgz")))??null}function y(e){return function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(p.contains(n.resolve(__dirname,"../../../package.json"),'"name": "aerogel"'))return n.resolve(__dirname,"../",e);const t=p.read(n.resolve(__dirname,"../../../../package.json")),s=i.stringMatch(t??"",/"@aerogel\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/),r=s?.[1]??m.fail("Could not determine base path");return n.resolve(r,e)}(`../${e}`)}function v(e){return n.resolve(__dirname,`../templates/${e}`)}var x=i.facade(new class{constructor(){u.default(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,i)=>{c.exec(e,{cwd:this.cwd??void 0},(e=>{e?i(e):t()}))}))}});class w{constructor(){u.default(this,"project",void 0),u.default(this,"modifiedFiles",void 0),this.project=new l.Project({tsConfigFilePath:"tsconfig.json"}),this.modifiedFiles=new Set,this.project.addSourceFilesAtPaths("src/**/*.ts"),this.project.addSourceFilesAtPaths("tailwind.config.js"),this.project.addSourceFilesAtPaths("vite.config.ts")}addSourceFile(e){this.project.addSourceFilesAtPaths(e)}requireSourceFile(e){return this.project.getSourceFileOrThrow(e)}async format(){await m.animate("Formatting modified files",(async()=>{const e=p.exists("prettier.config.js"),t=p.exists(".eslintrc.js");await Promise.all(i.arrayFrom(this.modifiedFiles).map((async i=>{e&&await x.run(`npx prettier ${i} --write`),t&&await x.run(`npx eslint ${i} --fix`)})))}))}async save(e){await e.save(),this.modifiedFiles.add(e.getFilePath())}}class j{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};u.default(this,"name",void 0),u.default(this,"options",void 0),this.name=e,this.options=t}create(e){!p.exists(e)||p.isDirectory(e)&&p.isEmptyDirectory(e)||m.fail(`Folder at '${e}' already exists!`),g.instantiate(v("app"),e,{app:{name:this.name,slug:i.stringToSlug(this.name)},dependencies:this.getDependencies(),contentPath:this.options.linkedLocal?`${y("core")}/dist/**/*.js`:"./node_modules/@aerogel/core/dist/**/*.js"})}edit(){return new w}getDependencies(){const e=e=>Object.entries(e).reduce(((e,t)=>{let[i,s]=t;return Object.assign(e,{[i]:`file:${s}`})}),{});return this.options.linkedLocal?e({aerogelCli:y("cli"),aerogelCore:y("core"),aerogelCypress:y("cypress"),aerogelPluginI18n:y("plugin-i18n"),aerogelPluginSoukai:y("plugin-soukai"),aerogelVite:y("vite")}):this.options.local?e({aerogelCli:h("cli")??f("cli"),aerogelCore:h("core")??f("core"),aerogelCypress:h("cypress")??f("cypress"),aerogelPluginI18n:h("plugin-i18n")??f("plugin-i18n"),aerogelPluginSoukai:h("plugin-soukai")??f("plugin-soukai"),aerogelVite:h("vite")??f("vite")}):{aerogelCli:"next",aerogelCore:"next",aerogelCypress:"next",aerogelPluginI18n:"next",aerogelPluginSoukai:"next",aerogelVite:"next"}}}class S{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,i]of this.parameters)e=e.argument(`<${t}>`,i);for(const[t,i]of Object.entries(this.options)){const s="string"==typeof i?i:i.description,n="string"==typeof i?"string":i.type??"string";e=e.option("boolean"===n?`--${t}`:`--${t} <${n}>`,s)}e=e.action((function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return t.run.call(t,...i)}))}static async run(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];const s=new this(...t);await s.run()}async run(){}assertAerogelOrDirectory(e){const t=p.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&p.isDirectory(e))return;const i=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";m.fail(`${i} Are you sure this is an Aerogel app?`)}}u.default(S,"command",""),u.default(S,"description",""),u.default(S,"parameters",[]),u.default(S,"options",{});class $ extends S{constructor(e,t){super(),u.default(this,"path",void 0),u.default(this,"options",void 0),this.path=e,this.options=t}async run(){const e=this.path,t=this.options.name??"Aerogel App";x.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),m.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){m.info(`Creating **${e}**...`),new j(e,{local:this.options.local,linkedLocal:this.options.local&&!this.options.copy}).create(t)}async installDependencies(){await m.animate("Installing dependencies",(async()=>{await x.run("npm install")}))}async initializeGit(){await m.animate("Initializing git",(async()=>{await x.run("git init"),await x.run("git add ."),await x.run('git commit -m "Start"')}))}}function k(){return new j("")}function C(){return p.isSymlink("node_modules/@aerogel/core")}function A(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return;const s=t.guard??(()=>!0),n=t.validate??(()=>!0),r=i.arrayFrom(t.skip??[]);return e.forEachDescendant(((e,t)=>{if(s(e)&&n(e))return e;const i=e.getKind();r.includes(i)&&t.skip()}))}function F(e,t){if(e&&t(e))return e}u.default($,"command","create"),u.default($,"description","Create AerogelJS app"),u.default($,"parameters",[["path","Application path"]]),u.default($,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app using local Aerogel packages (used for core development)"},copy:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used in CI)"}});class q extends S{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),u.default(this,"path",void 0),u.default(this,"options",void 0),this.path=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/components"),this.assertHistoireInstalled();const e=new Set,[t,s]=this.parsePathComponents();await this.createComponent(t,s,e),await this.createStory(s,e),await this.declareComponents();const n=i.arrayFrom(e).map((e=>`- ${e}`)).join("\n");m.info(`${s} component created successfully! The following files were created:\n\n${n}`)}assertHistoireInstalled(){this.options.story&&(p.exists("src/main.histoire.ts")||m.fail("Histoire is not installed yet!"))}async createComponent(e,t,i){await m.animate("Creating component",(async()=>{p.exists(`src/components/${this.path}.vue`)&&m.fail(`${this.path} component already exists!`);g.instantiate(v("component"),`src/components/${e}`,{component:{name:t}}).forEach((e=>i.add(e)))}))}async createStory(e,t){this.options.story&&await m.animate("Creating story",(async()=>{g.instantiate(v("component-story"),"src/components",{component:{name:e}}).forEach((e=>t.add(e)))}))}async declareComponents(){const e=k().edit(),t=e.requireSourceFile("vite.config.ts"),i=this.getComponentDirsArray(t);if(!i)return m.fail("Could not find component dirs declaration in vite config!");i.getDescendantsOfKind(l.SyntaxKind.StringLiteral).some((e=>"'src/components'"===e.getText()))||(await m.animate("Updating vite config",(async()=>{i.addElement("'src/components'"),await e.save(t)})),await e.format())}getComponentDirsArray(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>e.getText().startsWith("Components("),skip:l.SyntaxKind.ImportDeclaration});if(!t)return null;const i=A(t,{guard:l.Node.isPropertyAssignment,validate:e=>"dirs"===e.getName()}),s=i?.getInitializer();return l.Node.isArrayLiteralExpression(s)?s:this.declareComponentDirsArray(t)}declareComponentDirsArray(e){const t=A(e,{guard:l.Node.isObjectLiteralExpression}),i=t?.addPropertyAssignment({name:"dirs",initializer:"[]"});return i?.getInitializer()??null}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}function D(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.split("\n"),s=t.indent??0;let n=0,r="";for(const e of i){const t=e.trim(),i=0===t.length;if(0===r.length){if(i)continue;n=e.indexOf(t[0]??""),r+=`${" ".repeat(s)}${t}\n`;continue}if(i){r+="\n";continue}const a=e.indexOf(t[0]??"");r+=`${" ".repeat(s+a-n)}${t}\n`}return r.trimEnd()}u.default(q,"command","generate:component"),u.default(q,"description","Generate an AerogelJS Component"),u.default(q,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),u.default(q,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class I extends S{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};super(),u.default(this,"name",void 0),u.default(this,"options",void 0),this.name=e,this.options=t}async run(){this.assertAerogelOrDirectory("src/models"),p.exists(`src/models/${this.name}.ts`)&&m.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=await m.animate("Creating model",(async()=>g.instantiate(v("model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n")));m.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:i.stringToStudlyCase(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(){p.contains("package.json",'"soukai"')||p.contains("package.json",'"@aerogel/plugin-soukai"')||m.fail("\n Soukai is not installed yet! You can install it running:\n npx ag install soukai\n ")}}u.default(I,"command","generate:model"),u.default(I,"description","Generate an AerogelJS Model"),u.default(I,"parameters",[["name","Model name"]]),u.default(I,"options",{fields:"Create model with the given fields"});class P extends S{constructor(e){super(),u.default(this,"name",void 0),this.name=e}async run(){this.assertAerogelOrDirectory("src/services");const e=new Set,t=k().edit();await this.createService(e),await this.registerService(t),await t.format();const s=i.arrayFrom(e).map((e=>`- ${e}`)).join("\n");m.info(`${this.name} service created successfully! The following files were created:\n\n${s}`)}async createService(e){await m.animate("Creating service",(async()=>{p.exists(`src/services/${this.name}.ts`)&&m.fail(`${this.name} service already exists!`);g.instantiate(v("service"),"src/services",{service:{name:this.name}}).forEach((t=>e.add(t)))}))}async registerService(e){await m.animate("Registering service",(async()=>{p.exists("src/services/index.ts")||await this.createServicesIndex(e);const t=e.requireSourceFile("src/services/index.ts"),s=this.getServicesObject(t);if(!s)return m.fail("Could not find services object in services config, please add it manually.");t.addImportDeclaration({defaultImport:this.name,moduleSpecifier:`./${this.name}`}),s.addPropertyAssignment({name:`$${i.stringToCamelCase(this.name)}`,initializer:this.name}),await e.save(t)}))}async createServicesIndex(e){p.write("src/services/index.ts",D("\n export const services = {};\n\n export type AppServices = typeof services;\n\n declare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends AppServices {}\n }\n ")),e.addSourceFile("src/services/index.ts");const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapOptions(t);if(!i)return m.fail("Could not find options object in bootstrap config, please add the services manually.");i.insertShorthandPropertyAssignment(0,{name:"services"}),t.addImportDeclaration({namedImports:["services"],moduleSpecifier:"./services"}),await e.save(t)}getBootstrapOptions(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:l.SyntaxKind.ImportDeclaration}),i=t?.getArguments()[1];return l.Node.isObjectLiteralExpression(i)?i:null}getServicesObject(e){const t=A(e,{guard:l.Node.isVariableDeclaration,validate:e=>"services"===e.getName()}),i=t?.getInitializer();return l.Node.isObjectLiteralExpression(i)?i:null}}u.default(P,"command","generate:service"),u.default(P,"description","Generate an AerogelJS Service"),u.default(P,"parameters",[["name","Service name"]]);class b{constructor(e){u.default(this,"name",void 0),this.name=e}async install(){this.assertNotInstalled(),await this.installDependencies();{const e=k().edit();await this.updateFiles(e),await e.format()}m.info(`Plugin ${this.name} installed!`)}assertNotInstalled(){p.contains("package.json",`"${this.getNpmPackageName()}"`)&&m.fail(`${this.name} is already installed!`)}async installDependencies(){await m.animate("Installing plugin dependencies",(async()=>{await this.installNpmDependencies()}))}async updateFiles(e){await this.updateBootstrapConfig(e)}async installNpmDependencies(){if(C())await x.run(`npm install file:${y(this.getLocalPackageName())}`);else if(p.contains("package.json","file")){const e=h(this.getLocalPackageName())??f(this.getLocalPackageName());await x.run(`npm install file:${e}`)}else await x.run(`npm install ${this.getNpmPackageName()}@next --save-exact`)}async updateBootstrapConfig(e){await m.animate("Injecting plugin in bootstrap configuration",(async()=>{const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapPluginsDeclaration(t);if(!i)return m.fail(`\n Could not find plugins array in bootstrap config, please add the following manually:\n\n ${this.getBootstrapConfig()}\n `);t.addImportDeclaration(this.getBootstrapImport()),i.addElement(this.getBootstrapConfig()),await e.save(t)}))}getBootstrapPluginsDeclaration(e){const t=A(e,{guard:l.Node.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:l.SyntaxKind.ImportDeclaration}),i=t?.getArguments()[1],s=F(i,l.Node.isObjectLiteralExpression)?.getProperty("plugins"),n=F(s,l.Node.isPropertyAssignment)?.getInitializer();return l.Node.isArrayLiteralExpression(n)?n:null}getBootstrapImport(){return{defaultImport:this.name,moduleSpecifier:`@aerogel/plugin-${this.name}`}}getNpmPackageName(){return`@aerogel/${this.getLocalPackageName()}`}getLocalPackageName(){return`plugin-${this.name}`}getBootstrapConfig(){return`${this.name}()`}}const N=[new class extends b{constructor(){super("soukai")}async installNpmDependencies(){await x.run("npm install soukai@next --save-exact"),await super.installNpmDependencies()}getBootstrapConfig(){return"soukai({ models: import.meta.glob('@/models/*', { eager: true }) })"}},new class extends b{constructor(){super("solid")}async updateFiles(e){await this.updateTailwindConfig(e),await super.updateFiles(e)}async installNpmDependencies(){await x.run("npm install soukai-solid@next --save-exact"),await super.installNpmDependencies()}async updateTailwindConfig(e){await m.animate("Updating tailwind configuration",(async()=>{const t=e.requireSourceFile("tailwind.config.js"),i=this.getTailwindContentArray(t),s=C()?`'${y("plugin-solid")}/dist/**/*.js'`:"'./node_modules/@aerogel/plugin-solid/dist/**/*.js'";if(!i)return m.fail(`\n Could not find content array in tailwind config, please add the following manually:\n\n ${s}\n `);i.addElement(s),await e.save(t)}))}getTailwindContentArray(e){const t=A(e,{guard:l.Node.isPropertyAssignment,validate:e=>"content"===e.getName(),skip:l.SyntaxKind.JSDoc}),i=t?.getInitializer();return l.Node.isArrayLiteralExpression(i)?i:null}}].reduce(((e,t)=>Object.assign(e,{[t.name]:t})),{});class O extends S{constructor(e){super(),u.default(this,"plugin",void 0),this.plugin=N[e]??m.fail(`Plugin '${e}' doesn't exist. Available plugins: ${Object.keys(N).join(", ")}`)}async run(){await this.plugin.install()}}u.default(O,"command","install"),u.default(O,"description","Install an AerogelJS plugin"),u.default(O,"parameters",[["plugin","Plugin to install"]]);var E=i.facade(new class{run(t){const i=new e.Command;i.name("ag").description("AerogelJS CLI").version("0.0.0"),$.define(i),q.define(i),I.define(i),P.define(i),O.define(i),i.parse(t)}});exports.CLI=E;
|
|
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"core-js/modules/esnext.async-iterator.reduce.js";import"core-js/modules/esnext.iterator.constructor.js";import"core-js/modules/esnext.iterator.reduce.js";import{facade as i,stringMatchAll as s,toString as n,stringMatch as r,arrayFrom as a,stringToSlug as o,stringToStudlyCase as l,stringToCamelCase as c}from"@noeldemartin/utils";import{existsSync as p,lstatSync as d,readFileSync as m,readdirSync as u,mkdirSync as g,writeFileSync as h}from"fs";import{resolve as f,dirname as y}from"path";import"core-js/modules/esnext.async-iterator.for-each.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 w,bold as v}from"chalk";import{cursorTo as j,clearLine as x}from"readline";import{render as $}from"mustache";import"core-js/modules/esnext.set.add-all.js";import"core-js/modules/esnext.set.delete-all.js";import"core-js/modules/esnext.set.difference.js";import"core-js/modules/esnext.set.every.js";import"core-js/modules/esnext.set.filter.js";import"core-js/modules/esnext.set.find.js";import"core-js/modules/esnext.set.intersection.js";import"core-js/modules/esnext.set.is-disjoint-from.js";import"core-js/modules/esnext.set.is-subset-of.js";import"core-js/modules/esnext.set.is-superset-of.js";import"core-js/modules/esnext.set.join.js";import"core-js/modules/esnext.set.map.js";import"core-js/modules/esnext.set.reduce.js";import"core-js/modules/esnext.set.some.js";import"core-js/modules/esnext.set.symmetric-difference.js";import"core-js/modules/esnext.set.union.js";import{Project as k,SyntaxKind as S,Node as C}from"ts-morph";import{exec as A}from"child_process";import"core-js/modules/esnext.async-iterator.some.js";import"core-js/modules/esnext.iterator.some.js";var D=i(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return p(e)}isSymlink(e){return d(e).isSymbolicLink()}read(e){return this.isFile(e)?m(e).toString():null}getFiles(e){const t=u(e,{withFileTypes:!0}),i=[];for(const s of t){const t=f(e,s.name);s.isDirectory()?i.push(...this.getFiles(t)):i.push(t)}return i}isDirectory(e){return this.exists(e)&&d(e).isDirectory()}isFile(e){return this.exists(e)&&d(e).isFile()}isEmptyDirectory(e){return!!this.isDirectory(e)&&0===this.getFiles(e).length}makeDirectory(e){g(e,{recursive:!0})}write(e,t){p(y(e))||g(y(e),{recursive:!0}),h(e,t)}});var F=i(new class{constructor(){t(this,"renderInfo",w("#00ffff")),t(this,"renderSuccess",w("#00ff00")),t(this,"renderError",w("#ff0000"))}async animate(e,t){var i=this;const s=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=i.renderInfo(i.renderMarkdown(e)+(s?"...":".".repeat(n%4)))+t;i.stdout(r)};let n=0;s();const r=setInterval((()=>(n++,s())),1e3),a=await t();return clearInterval(r),s("\n",!0),a}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=s(e,/\*\*(.*)\*\*/g);for(const i of t)e=e.replace(i[0],v(i[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"),i=e.trim()[0]??"",s=t.find((e=>e.trim().length>0))?.indexOf(i)??0;return t.map((e=>e.slice(s)))}return[e]}logLine(e){console.log(e)}stdout(e){j(process.stdout,0),x(process.stdout,0),process.stdout.write(e)}});class I{static instantiate(e,t,i){return new I(e).instantiate(t,i)}constructor(e){t(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.getFilenameReplacements(t),s=[];e=`${e}/`.replace(/\/\//,"/");for(const n of D.getFiles(this.path)){const r=Object.entries(i).reduce(((e,t)=>{let[i,s]=t;return e.replaceAll(i,s)}),n.substring(this.path.length+1)),a=m(n).toString(),o=e+(r.endsWith(".template")?r.slice(0,-9):r);D.write(o,$(a,t,void 0,["<%","%>"])),s.push(o)}return s}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,i)=>{let[s,r]=i;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${s}.`)):e[`[${t}${s}]`]=n(r),e}),{})}}function P(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(D.contains(f(__dirname,"../../../package.json"),'"name": "aerogel"'))return f(__dirname,"../",e);const t=D.read(f(__dirname,"../../../../package.json")),i=r(t??"",/"@aerogel\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/),s=i?.[1]??F.fail("Could not determine base path");return f(s,e)}function b(e){return F.fail(`Could not find ${e} pack file, did you run 'npm pack'?`)}function E(e){return D.getFiles(O(e)).find((e=>e.endsWith(".tgz")))??null}function O(e){return P(`../${e}`)}var N=i(new class{constructor(){t(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,i)=>{A(e,{cwd:this.cwd??void 0},(e=>{e?i(e):t()}))}))}});class L{constructor(){t(this,"project",void 0),t(this,"modifiedFiles",void 0),this.project=new k({tsConfigFilePath:"tsconfig.json"}),this.modifiedFiles=new Set,this.project.addSourceFilesAtPaths("src/**/*.ts"),this.project.addSourceFilesAtPaths("tailwind.config.js"),this.project.addSourceFilesAtPaths("vite.config.ts")}addSourceFile(e){this.project.addSourceFilesAtPaths(e)}requireSourceFile(e){return this.project.getSourceFileOrThrow(e)}async format(){await F.animate("Formatting modified files",(async()=>{const e=D.exists("prettier.config.js"),t=D.exists(".eslintrc.js");await Promise.all(a(this.modifiedFiles).map((async i=>{e&&await N.run(`npx prettier ${i} --write`),t&&await N.run(`npx eslint ${i} --fix`)})))}))}async save(e){await e.save(),this.modifiedFiles.add(e.getFilePath())}}class T{constructor(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(this,"name",void 0),t(this,"options",void 0),this.name=e,this.options=i}create(e){!D.exists(e)||D.isDirectory(e)&&D.isEmptyDirectory(e)||F.fail(`Folder at '${e}' already exists!`),I.instantiate(P("templates/app"),e,{app:{name:this.name,slug:o(this.name)},dependencies:this.getDependencies(),contentPath:this.options.linkedLocal?`${O("core")}/dist/**/*.js`:"./node_modules/@aerogel/core/dist/**/*.js"})}edit(){return new L}getDependencies(){const e=e=>Object.entries(e).reduce(((e,t)=>{let[i,s]=t;return Object.assign(e,{[i]:`file:${s}`})}),{});return this.options.linkedLocal?e({aerogelCli:O("cli"),aerogelCore:O("core"),aerogelCypress:O("cypress"),aerogelPluginI18n:O("plugin-i18n"),aerogelPluginSoukai:O("plugin-soukai"),aerogelVite:O("vite")}):this.options.local?e({aerogelCli:E("cli")??b("cli"),aerogelCore:E("core")??b("core"),aerogelCypress:E("cypress")??b("cypress"),aerogelPluginI18n:E("plugin-i18n")??b("plugin-i18n"),aerogelPluginSoukai:E("plugin-soukai")??b("plugin-soukai"),aerogelVite:E("vite")??b("vite")}):{aerogelCli:"next",aerogelCore:"next",aerogelCypress:"next",aerogelPluginI18n:"next",aerogelPluginSoukai:"next",aerogelVite:"next"}}}class z{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,i]of this.parameters)e=e.argument(`<${t}>`,i);for(const[t,i]of Object.entries(this.options)){const s="string"==typeof i?i:i.description,n="string"==typeof i?"string":i.type??"string";e=e.option("boolean"===n?`--${t}`:`--${t} <${n}>`,s)}e=e.action((function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return t.run.call(t,...i)}))}static async run(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];const s=new this(...t);await s.run()}async run(){}assertAerogelOrDirectory(e){const t=D.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&D.isDirectory(e))return;const i=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";F.fail(`${i} Are you sure this is an Aerogel app?`)}}t(z,"command",""),t(z,"description",""),t(z,"parameters",[]),t(z,"options",{});class B extends z{constructor(e,i){super(),t(this,"path",void 0),t(this,"options",void 0),this.path=e,this.options=i}async run(){const e=this.path,t=this.options.name??"Aerogel App";N.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),F.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){F.info(`Creating **${e}**...`),new T(e,{local:this.options.local,linkedLocal:this.options.local&&!this.options.copy}).create(t)}async installDependencies(){await F.animate("Installing dependencies",(async()=>{await N.run("npm install")}))}async initializeGit(){await F.animate("Initializing git",(async()=>{await N.run("git init"),await N.run("git add ."),await N.run('git commit -m "Start"')}))}}function M(){return new T("")}function q(){return D.isSymlink("node_modules/@aerogel/core")}function _(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return;const i=t.guard??(()=>!0),s=t.validate??(()=>!0),n=a(t.skip??[]);return e.forEachDescendant(((e,t)=>{if(i(e)&&s(e))return e;const r=e.getKind();n.includes(r)&&t.skip()}))}function J(e,t){if(e&&t(e))return e}t(B,"command","create"),t(B,"description","Create AerogelJS app"),t(B,"parameters",[["path","Application path"]]),t(B,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app using local Aerogel packages (used for core development)"},copy:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used in CI)"}});class W extends z{constructor(e){let i=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=i}async run(){this.assertAerogelOrDirectory("src/components"),this.assertHistoireInstalled();const e=new Set,[t,i]=this.parsePathComponents();await this.createComponent(t,i,e),await this.createStory(i,e),await this.declareComponents();const s=a(e).map((e=>`- ${e}`)).join("\n");F.info(`${i} component created successfully! The following files were created:\n\n${s}`)}assertHistoireInstalled(){this.options.story&&(D.exists("src/main.histoire.ts")||F.fail("Histoire is not installed yet!"))}async createComponent(e,t,i){await F.animate("Creating component",(async()=>{D.exists(`src/components/${this.path}.vue`)&&F.fail(`${this.path} component already exists!`);I.instantiate(P("templates/component"),`src/components/${e}`,{component:{name:t}}).forEach((e=>i.add(e)))}))}async createStory(e,t){this.options.story&&await F.animate("Creating story",(async()=>{I.instantiate(P("templates/component-story"),"src/components",{component:{name:e}}).forEach((e=>t.add(e)))}))}async declareComponents(){const e=M().edit(),t=e.requireSourceFile("vite.config.ts"),i=this.getComponentDirsArray(t);if(!i)return F.fail("Could not find component dirs declaration in vite config!");i.getDescendantsOfKind(S.StringLiteral).some((e=>"'src/components'"===e.getText()))||(await F.animate("Updating vite config",(async()=>{i.addElement("'src/components'"),await e.save(t)})),await e.format())}getComponentDirsArray(e){const t=_(e,{guard:C.isCallExpression,validate:e=>e.getText().startsWith("Components("),skip:S.ImportDeclaration});if(!t)return null;const i=_(t,{guard:C.isPropertyAssignment,validate:e=>"dirs"===e.getName()}),s=i?.getInitializer();return C.isArrayLiteralExpression(s)?s:this.declareComponentDirsArray(t)}declareComponentDirsArray(e){const t=_(e,{guard:C.isObjectLiteralExpression}),i=t?.addPropertyAssignment({name:"dirs",initializer:"[]"});return i?.getInitializer()??null}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}function G(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.split("\n"),s=t.indent??0;let n=0,r="";for(const e of i){const t=e.trim(),i=0===t.length;if(0===r.length){if(i)continue;n=e.indexOf(t[0]??""),r+=`${" ".repeat(s)}${t}\n`;continue}if(i){r+="\n";continue}const a=e.indexOf(t[0]??"");r+=`${" ".repeat(s+a-n)}${t}\n`}return r.trimEnd()}t(W,"command","generate:component"),t(W,"description","Generate an AerogelJS Component"),t(W,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),t(W,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class H extends z{constructor(e){let i=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=i}async run(){this.assertAerogelOrDirectory("src/models"),D.exists(`src/models/${this.name}.ts`)&&F.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=await F.animate("Creating model",(async()=>I.instantiate(P("templates/model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n")));F.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,i,s]=e.split(":");return{name:t,type:l(i??"string"),required:"required"===s}})).reduce(((e,t)=>e+`\n${t.required?G(`\n ${t.name}: {\n type: FieldType.${t.type},\n required: true,\n }\n `):`${t.name}: FieldType.${t.type}`},`),"");return G(e,{indent:8})}assertSoukaiInstalled(){D.contains("package.json",'"soukai"')||D.contains("package.json",'"@aerogel/plugin-soukai"')||F.fail("\n Soukai is not installed yet! You can install it running:\n npx ag install soukai\n ")}}t(H,"command","generate:model"),t(H,"description","Generate an AerogelJS Model"),t(H,"parameters",[["name","Model name"]]),t(H,"options",{fields:"Create model with the given fields"});class R extends z{constructor(e){super(),t(this,"name",void 0),this.name=e}async run(){this.assertAerogelOrDirectory("src/services");const e=new Set,t=M().edit();await this.createService(e),await this.registerService(t),await t.format();const i=a(e).map((e=>`- ${e}`)).join("\n");F.info(`${this.name} service created successfully! The following files were created:\n\n${i}`)}async createService(e){await F.animate("Creating service",(async()=>{D.exists(`src/services/${this.name}.ts`)&&F.fail(`${this.name} service already exists!`);I.instantiate(P("templates/service"),"src/services",{service:{name:this.name}}).forEach((t=>e.add(t)))}))}async registerService(e){await F.animate("Registering service",(async()=>{D.exists("src/services/index.ts")||await this.createServicesIndex(e);const t=e.requireSourceFile("src/services/index.ts"),i=this.getServicesObject(t);if(!i)return F.fail("Could not find services object in services config, please add it manually.");t.addImportDeclaration({defaultImport:this.name,moduleSpecifier:`./${this.name}`}),i.addPropertyAssignment({name:`$${c(this.name)}`,initializer:this.name}),await e.save(t)}))}async createServicesIndex(e){D.write("src/services/index.ts",G("\n export const services = {};\n\n export type AppServices = typeof services;\n\n declare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends AppServices {}\n }\n ")),e.addSourceFile("src/services/index.ts");const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapOptions(t);if(!i)return F.fail("Could not find options object in bootstrap config, please add the services manually.");i.insertShorthandPropertyAssignment(0,{name:"services"}),t.addImportDeclaration({namedImports:["services"],moduleSpecifier:"./services"}),await e.save(t)}getBootstrapOptions(e){const t=_(e,{guard:C.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:S.ImportDeclaration}),i=t?.getArguments()[1];return C.isObjectLiteralExpression(i)?i:null}getServicesObject(e){const t=_(e,{guard:C.isVariableDeclaration,validate:e=>"services"===e.getName()}),i=t?.getInitializer();return C.isObjectLiteralExpression(i)?i:null}}t(R,"command","generate:service"),t(R,"description","Generate an AerogelJS Service"),t(R,"parameters",[["name","Service name"]]);class V{constructor(e){t(this,"name",void 0),this.name=e}async install(){this.assertNotInstalled(),await this.installDependencies();{const e=M().edit();await this.updateFiles(e),await e.format()}F.info(`Plugin ${this.name} installed!`)}assertNotInstalled(){D.contains("package.json",`"${this.getNpmPackageName()}"`)&&F.fail(`${this.name} is already installed!`)}async installDependencies(){await F.animate("Installing plugin dependencies",(async()=>{await this.installNpmDependencies()}))}async updateFiles(e){await this.updateBootstrapConfig(e)}async installNpmDependencies(){if(q())await N.run(`npm install file:${O(this.getLocalPackageName())}`);else if(D.contains("package.json","file")){const e=E(this.getLocalPackageName())??b(this.getLocalPackageName());await N.run(`npm install file:${e}`)}else await N.run(`npm install ${this.getNpmPackageName()}@next`)}async updateBootstrapConfig(e){await F.animate("Injecting plugin in bootstrap configuration",(async()=>{const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapPluginsDeclaration(t);if(!i)return F.fail(`\n Could not find plugins array in bootstrap config, please add the following manually:\n\n ${this.getBootstrapConfig()}\n `);t.addImportDeclaration(this.getBootstrapImport()),i.addElement(this.getBootstrapConfig()),await e.save(t)}))}getBootstrapPluginsDeclaration(e){const t=_(e,{guard:C.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:S.ImportDeclaration}),i=t?.getArguments()[1],s=J(i,C.isObjectLiteralExpression)?.getProperty("plugins"),n=J(s,C.isPropertyAssignment)?.getInitializer();return C.isArrayLiteralExpression(n)?n:null}getBootstrapImport(){return{defaultImport:this.name,moduleSpecifier:`@aerogel/plugin-${this.name}`}}getNpmPackageName(){return`@aerogel/${this.getLocalPackageName()}`}getLocalPackageName(){return`plugin-${this.name}`}getBootstrapConfig(){return`${this.name}()`}}const K=[new class extends V{constructor(){super("soukai")}async installNpmDependencies(){await N.run("npm install soukai@next"),await super.installNpmDependencies()}getBootstrapConfig(){return"soukai({ models: import.meta.glob('@/models/*', { eager: true }) })"}},new class extends V{constructor(){super("solid")}async updateFiles(e){await this.updateTailwindConfig(e),await super.updateFiles(e)}async installNpmDependencies(){await N.run("npm install soukai-solid@next"),await super.installNpmDependencies()}async updateTailwindConfig(e){await F.animate("Updating tailwind configuration",(async()=>{const t=e.requireSourceFile("tailwind.config.js"),i=this.getTailwindContentArray(t),s=q()?`'${O("plugin-solid")}/dist/**/*.js'`:"'./node_modules/@aerogel/plugin-solid/dist/**/*.js'";if(!i)return F.fail(`\n Could not find content array in tailwind config, please add the following manually:\n\n ${s}\n `);i.addElement(s),await e.save(t)}))}getTailwindContentArray(e){const t=_(e,{guard:C.isPropertyAssignment,validate:e=>"content"===e.getName(),skip:S.JSDoc}),i=t?.getInitializer();return C.isArrayLiteralExpression(i)?i:null}}].reduce(((e,t)=>Object.assign(e,{[t.name]:t})),{});class U extends z{constructor(e){super(),t(this,"plugin",void 0),this.plugin=K[e]??F.fail(`Plugin '${e}' doesn't exist. Available plugins: ${Object.keys(K).join(", ")}`)}async run(){await this.plugin.install()}}t(U,"command","install"),t(U,"description","Install an AerogelJS plugin"),t(U,"parameters",[["plugin","Plugin to install"]]);var Y=i(new class{run(t){const i=new e;i.name("ag").description("AerogelJS CLI").version("0.0.0"),B.define(i),W.define(i),H.define(i),R.define(i),U.define(i),i.parse(t)}});export{Y as CLI};
|
|
1
|
+
import{Command as e}from"commander";import t from"@babel/runtime/helpers/esm/defineProperty";import"core-js/modules/esnext.async-iterator.reduce.js";import"core-js/modules/esnext.iterator.constructor.js";import"core-js/modules/esnext.iterator.reduce.js";import{facade as i,stringMatchAll as s,toString as n,stringMatch as r,arrayFrom as a,stringToSlug as o,stringToStudlyCase as c,stringToCamelCase as l}from"@noeldemartin/utils";import{existsSync as d,lstatSync as p,readFileSync as m,readdirSync as u,mkdirSync as g,writeFileSync as h}from"fs";import{resolve as f,dirname as y}from"path";import"core-js/modules/esnext.async-iterator.for-each.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 w,bold as v}from"chalk";import{cursorTo as j,clearLine as x}from"readline";import{render as $}from"mustache";import"core-js/modules/esnext.set.add-all.js";import"core-js/modules/esnext.set.delete-all.js";import"core-js/modules/esnext.set.difference.js";import"core-js/modules/esnext.set.every.js";import"core-js/modules/esnext.set.filter.js";import"core-js/modules/esnext.set.find.js";import"core-js/modules/esnext.set.intersection.js";import"core-js/modules/esnext.set.is-disjoint-from.js";import"core-js/modules/esnext.set.is-subset-of.js";import"core-js/modules/esnext.set.is-superset-of.js";import"core-js/modules/esnext.set.join.js";import"core-js/modules/esnext.set.map.js";import"core-js/modules/esnext.set.reduce.js";import"core-js/modules/esnext.set.some.js";import"core-js/modules/esnext.set.symmetric-difference.js";import"core-js/modules/esnext.set.union.js";import{Project as k,SyntaxKind as S,Node as C}from"ts-morph";import{exec as A}from"child_process";import"core-js/modules/esnext.async-iterator.some.js";import"core-js/modules/esnext.iterator.some.js";var D=i(new class{contains(e,t){return!!this.read(e)?.includes(t)}exists(e){return d(e)}isSymlink(e){return p(e).isSymbolicLink()}read(e){return this.isFile(e)?m(e).toString():null}getFiles(e){const t=u(e,{withFileTypes:!0}),i=[];for(const s of t){const t=f(e,s.name);s.isDirectory()?i.push(...this.getFiles(t)):i.push(t)}return i}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){g(e,{recursive:!0})}write(e,t){d(y(e))||g(y(e),{recursive:!0}),h(e,t)}});var F=i(new class{constructor(){t(this,"renderInfo",w("#00ffff")),t(this,"renderSuccess",w("#00ff00")),t(this,"renderError",w("#ff0000"))}async animate(e,t){var i=this;const s=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=i.renderInfo(i.renderMarkdown(e)+(s?"...":".".repeat(n%4)))+t;i.stdout(r)};let n=0;s();const r=setInterval((()=>(n++,s())),1e3),a=await t();return clearInterval(r),s("\n",!0),a}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=s(e,/\*\*(.*)\*\*/g);for(const i of t)e=e.replace(i[0],v(i[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"),i=e.trim()[0]??"",s=t.find((e=>e.trim().length>0))?.indexOf(i)??0;return t.map((e=>e.slice(s)))}return[e]}logLine(e){console.log(e)}stdout(e){j(process.stdout,0),x(process.stdout,0),process.stdout.write(e)}});class I{static instantiate(e,t,i){return new I(e).instantiate(t,i)}constructor(e){t(this,"path",void 0),this.path=e}instantiate(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=this.getFilenameReplacements(t),s=[];e=`${e}/`.replace(/\/\//,"/");for(const n of D.getFiles(this.path)){const r=Object.entries(i).reduce(((e,t)=>{let[i,s]=t;return e.replaceAll(i,s)}),n.substring(this.path.length+1)),a=m(n).toString(),o=e+(r.endsWith(".template")?r.slice(0,-9):r);D.write(o,$(a,t,void 0,["<%","%>"])),s.push(o)}return s}getFilenameReplacements(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(e).reduce(((e,i)=>{let[s,r]=i;return"object"==typeof r?Object.assign(e,this.getFilenameReplacements(r,`${s}.`)):e[`[${t}${s}]`]=n(r),e}),{})}}function P(e){return F.fail(`Could not find ${e} pack file, did you run 'npm pack'?`)}function b(e){return D.getFiles(E(e)).find((e=>e.endsWith(".tgz")))??null}function E(e){return function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(D.contains(f(__dirname,"../../../package.json"),'"name": "aerogel"'))return f(__dirname,"../",e);const t=D.read(f(__dirname,"../../../../package.json")),i=r(t??"",/"@aerogel\/cli": "file:(.*)\/aerogel-cli-[\d.]*\.tgz"/),s=i?.[1]??F.fail("Could not determine base path");return f(s,e)}(`../${e}`)}function O(e){return f(__dirname,`../templates/${e}`)}var N=i(new class{constructor(){t(this,"cwd",null)}setWorkingDirectory(e){this.cwd=e}async run(e){await new Promise(((t,i)=>{A(e,{cwd:this.cwd??void 0},(e=>{e?i(e):t()}))}))}});class L{constructor(){t(this,"project",void 0),t(this,"modifiedFiles",void 0),this.project=new k({tsConfigFilePath:"tsconfig.json"}),this.modifiedFiles=new Set,this.project.addSourceFilesAtPaths("src/**/*.ts"),this.project.addSourceFilesAtPaths("tailwind.config.js"),this.project.addSourceFilesAtPaths("vite.config.ts")}addSourceFile(e){this.project.addSourceFilesAtPaths(e)}requireSourceFile(e){return this.project.getSourceFileOrThrow(e)}async format(){await F.animate("Formatting modified files",(async()=>{const e=D.exists("prettier.config.js"),t=D.exists(".eslintrc.js");await Promise.all(a(this.modifiedFiles).map((async i=>{e&&await N.run(`npx prettier ${i} --write`),t&&await N.run(`npx eslint ${i} --fix`)})))}))}async save(e){await e.save(),this.modifiedFiles.add(e.getFilePath())}}class T{constructor(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(this,"name",void 0),t(this,"options",void 0),this.name=e,this.options=i}create(e){!D.exists(e)||D.isDirectory(e)&&D.isEmptyDirectory(e)||F.fail(`Folder at '${e}' already exists!`),I.instantiate(O("app"),e,{app:{name:this.name,slug:o(this.name)},dependencies:this.getDependencies(),contentPath:this.options.linkedLocal?`${E("core")}/dist/**/*.js`:"./node_modules/@aerogel/core/dist/**/*.js"})}edit(){return new L}getDependencies(){const e=e=>Object.entries(e).reduce(((e,t)=>{let[i,s]=t;return Object.assign(e,{[i]:`file:${s}`})}),{});return this.options.linkedLocal?e({aerogelCli:E("cli"),aerogelCore:E("core"),aerogelCypress:E("cypress"),aerogelPluginI18n:E("plugin-i18n"),aerogelPluginSoukai:E("plugin-soukai"),aerogelVite:E("vite")}):this.options.local?e({aerogelCli:b("cli")??P("cli"),aerogelCore:b("core")??P("core"),aerogelCypress:b("cypress")??P("cypress"),aerogelPluginI18n:b("plugin-i18n")??P("plugin-i18n"),aerogelPluginSoukai:b("plugin-soukai")??P("plugin-soukai"),aerogelVite:b("vite")??P("vite")}):{aerogelCli:"next",aerogelCore:"next",aerogelCypress:"next",aerogelPluginI18n:"next",aerogelPluginSoukai:"next",aerogelVite:"next"}}}class z{static define(e){var t=this;e=e.command(this.command).description(this.description);for(const[t,i]of this.parameters)e=e.argument(`<${t}>`,i);for(const[t,i]of Object.entries(this.options)){const s="string"==typeof i?i:i.description,n="string"==typeof i?"string":i.type??"string";e=e.option("boolean"===n?`--${t}`:`--${t} <${n}>`,s)}e=e.action((function(){for(var e=arguments.length,i=new Array(e),s=0;s<e;s++)i[s]=arguments[s];return t.run.call(t,...i)}))}static async run(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];const s=new this(...t);await s.run()}async run(){}assertAerogelOrDirectory(e){const t=D.read("package.json");if(t?.includes("@aerogel/core"))return;if(e&&D.isDirectory(e))return;const i=e?`${e} folder does not exist.`:"package.json does not contain @aerogel/core.";F.fail(`${i} Are you sure this is an Aerogel app?`)}}t(z,"command",""),t(z,"description",""),t(z,"parameters",[]),t(z,"options",{});class B extends z{constructor(e,i){super(),t(this,"path",void 0),t(this,"options",void 0),this.path=e,this.options=i}async run(){const e=this.path,t=this.options.name??"Aerogel App";N.setWorkingDirectory(e),await this.createApp(t,e),await this.installDependencies(),await this.initializeGit(),F.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){F.info(`Creating **${e}**...`),new T(e,{local:this.options.local,linkedLocal:this.options.local&&!this.options.copy}).create(t)}async installDependencies(){await F.animate("Installing dependencies",(async()=>{await N.run("npm install")}))}async initializeGit(){await F.animate("Initializing git",(async()=>{await N.run("git init"),await N.run("git add ."),await N.run('git commit -m "Start"')}))}}function _(){return new T("")}function M(){return D.isSymlink("node_modules/@aerogel/core")}function q(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)return;const i=t.guard??(()=>!0),s=t.validate??(()=>!0),n=a(t.skip??[]);return e.forEachDescendant(((e,t)=>{if(i(e)&&s(e))return e;const r=e.getKind();n.includes(r)&&t.skip()}))}function J(e,t){if(e&&t(e))return e}t(B,"command","create"),t(B,"description","Create AerogelJS app"),t(B,"parameters",[["path","Application path"]]),t(B,"options",{name:"Application name",local:{type:"boolean",description:"Whether to create an app using local Aerogel packages (used for core development)"},copy:{type:"boolean",description:"Whether to create an app linked to local Aerogel packages (used in CI)"}});class W extends z{constructor(e){let i=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=i}async run(){this.assertAerogelOrDirectory("src/components"),this.assertHistoireInstalled();const e=new Set,[t,i]=this.parsePathComponents();await this.createComponent(t,i,e),await this.createStory(i,e),await this.declareComponents();const s=a(e).map((e=>`- ${e}`)).join("\n");F.info(`${i} component created successfully! The following files were created:\n\n${s}`)}assertHistoireInstalled(){this.options.story&&(D.exists("src/main.histoire.ts")||F.fail("Histoire is not installed yet!"))}async createComponent(e,t,i){await F.animate("Creating component",(async()=>{D.exists(`src/components/${this.path}.vue`)&&F.fail(`${this.path} component already exists!`);I.instantiate(O("component"),`src/components/${e}`,{component:{name:t}}).forEach((e=>i.add(e)))}))}async createStory(e,t){this.options.story&&await F.animate("Creating story",(async()=>{I.instantiate(O("component-story"),"src/components",{component:{name:e}}).forEach((e=>t.add(e)))}))}async declareComponents(){const e=_().edit(),t=e.requireSourceFile("vite.config.ts"),i=this.getComponentDirsArray(t);if(!i)return F.fail("Could not find component dirs declaration in vite config!");i.getDescendantsOfKind(S.StringLiteral).some((e=>"'src/components'"===e.getText()))||(await F.animate("Updating vite config",(async()=>{i.addElement("'src/components'"),await e.save(t)})),await e.format())}getComponentDirsArray(e){const t=q(e,{guard:C.isCallExpression,validate:e=>e.getText().startsWith("Components("),skip:S.ImportDeclaration});if(!t)return null;const i=q(t,{guard:C.isPropertyAssignment,validate:e=>"dirs"===e.getName()}),s=i?.getInitializer();return C.isArrayLiteralExpression(s)?s:this.declareComponentDirsArray(t)}declareComponentDirsArray(e){const t=q(e,{guard:C.isObjectLiteralExpression}),i=t?.addPropertyAssignment({name:"dirs",initializer:"[]"});return i?.getInitializer()??null}parsePathComponents(){const e=this.path.lastIndexOf("/");return-1===e?["",this.path]:[this.path.substring(0,e),this.path.substring(e+1)]}}function G(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.split("\n"),s=t.indent??0;let n=0,r="";for(const e of i){const t=e.trim(),i=0===t.length;if(0===r.length){if(i)continue;n=e.indexOf(t[0]??""),r+=`${" ".repeat(s)}${t}\n`;continue}if(i){r+="\n";continue}const a=e.indexOf(t[0]??"");r+=`${" ".repeat(s+a-n)}${t}\n`}return r.trimEnd()}t(W,"command","generate:component"),t(W,"description","Generate an AerogelJS Component"),t(W,"parameters",[["path","Component path (relative to components folder; extension not necessary)"]]),t(W,"options",{story:{description:"Create component story using Histoire",type:"boolean"}});class H extends z{constructor(e){let i=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=i}async run(){this.assertAerogelOrDirectory("src/models"),D.exists(`src/models/${this.name}.ts`)&&F.fail(`${this.name} model already exists!`),this.assertSoukaiInstalled();const e=await F.animate("Creating model",(async()=>I.instantiate(O("model"),"src/models",{model:{name:this.name,fieldsDefinition:this.getFieldsDefinition()},soukaiImports:this.options.fields?"FieldType, defineModelSchema":"defineModelSchema"}).map((e=>`- ${e}`)).join("\n")));F.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,i,s]=e.split(":");return{name:t,type:c(i??"string"),required:"required"===s}})).reduce(((e,t)=>e+`\n${t.required?G(`\n ${t.name}: {\n type: FieldType.${t.type},\n required: true,\n }\n `):`${t.name}: FieldType.${t.type}`},`),"");return G(e,{indent:8})}assertSoukaiInstalled(){D.contains("package.json",'"soukai"')||D.contains("package.json",'"@aerogel/plugin-soukai"')||F.fail("\n Soukai is not installed yet! You can install it running:\n npx ag install soukai\n ")}}t(H,"command","generate:model"),t(H,"description","Generate an AerogelJS Model"),t(H,"parameters",[["name","Model name"]]),t(H,"options",{fields:"Create model with the given fields"});class R extends z{constructor(e){super(),t(this,"name",void 0),this.name=e}async run(){this.assertAerogelOrDirectory("src/services");const e=new Set,t=_().edit();await this.createService(e),await this.registerService(t),await t.format();const i=a(e).map((e=>`- ${e}`)).join("\n");F.info(`${this.name} service created successfully! The following files were created:\n\n${i}`)}async createService(e){await F.animate("Creating service",(async()=>{D.exists(`src/services/${this.name}.ts`)&&F.fail(`${this.name} service already exists!`);I.instantiate(O("service"),"src/services",{service:{name:this.name}}).forEach((t=>e.add(t)))}))}async registerService(e){await F.animate("Registering service",(async()=>{D.exists("src/services/index.ts")||await this.createServicesIndex(e);const t=e.requireSourceFile("src/services/index.ts"),i=this.getServicesObject(t);if(!i)return F.fail("Could not find services object in services config, please add it manually.");t.addImportDeclaration({defaultImport:this.name,moduleSpecifier:`./${this.name}`}),i.addPropertyAssignment({name:`$${l(this.name)}`,initializer:this.name}),await e.save(t)}))}async createServicesIndex(e){D.write("src/services/index.ts",G("\n export const services = {};\n\n export type AppServices = typeof services;\n\n declare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends AppServices {}\n }\n ")),e.addSourceFile("src/services/index.ts");const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapOptions(t);if(!i)return F.fail("Could not find options object in bootstrap config, please add the services manually.");i.insertShorthandPropertyAssignment(0,{name:"services"}),t.addImportDeclaration({namedImports:["services"],moduleSpecifier:"./services"}),await e.save(t)}getBootstrapOptions(e){const t=q(e,{guard:C.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:S.ImportDeclaration}),i=t?.getArguments()[1];return C.isObjectLiteralExpression(i)?i:null}getServicesObject(e){const t=q(e,{guard:C.isVariableDeclaration,validate:e=>"services"===e.getName()}),i=t?.getInitializer();return C.isObjectLiteralExpression(i)?i:null}}t(R,"command","generate:service"),t(R,"description","Generate an AerogelJS Service"),t(R,"parameters",[["name","Service name"]]);class V{constructor(e){t(this,"name",void 0),this.name=e}async install(){this.assertNotInstalled(),await this.installDependencies();{const e=_().edit();await this.updateFiles(e),await e.format()}F.info(`Plugin ${this.name} installed!`)}assertNotInstalled(){D.contains("package.json",`"${this.getNpmPackageName()}"`)&&F.fail(`${this.name} is already installed!`)}async installDependencies(){await F.animate("Installing plugin dependencies",(async()=>{await this.installNpmDependencies()}))}async updateFiles(e){await this.updateBootstrapConfig(e)}async installNpmDependencies(){if(M())await N.run(`npm install file:${E(this.getLocalPackageName())}`);else if(D.contains("package.json","file")){const e=b(this.getLocalPackageName())??P(this.getLocalPackageName());await N.run(`npm install file:${e}`)}else await N.run(`npm install ${this.getNpmPackageName()}@next --save-exact`)}async updateBootstrapConfig(e){await F.animate("Injecting plugin in bootstrap configuration",(async()=>{const t=e.requireSourceFile("src/main.ts"),i=this.getBootstrapPluginsDeclaration(t);if(!i)return F.fail(`\n Could not find plugins array in bootstrap config, please add the following manually:\n\n ${this.getBootstrapConfig()}\n `);t.addImportDeclaration(this.getBootstrapImport()),i.addElement(this.getBootstrapConfig()),await e.save(t)}))}getBootstrapPluginsDeclaration(e){const t=q(e,{guard:C.isCallExpression,validate:e=>"bootstrapApplication"===e.getExpression().getText(),skip:S.ImportDeclaration}),i=t?.getArguments()[1],s=J(i,C.isObjectLiteralExpression)?.getProperty("plugins"),n=J(s,C.isPropertyAssignment)?.getInitializer();return C.isArrayLiteralExpression(n)?n:null}getBootstrapImport(){return{defaultImport:this.name,moduleSpecifier:`@aerogel/plugin-${this.name}`}}getNpmPackageName(){return`@aerogel/${this.getLocalPackageName()}`}getLocalPackageName(){return`plugin-${this.name}`}getBootstrapConfig(){return`${this.name}()`}}const K=[new class extends V{constructor(){super("soukai")}async installNpmDependencies(){await N.run("npm install soukai@next --save-exact"),await super.installNpmDependencies()}getBootstrapConfig(){return"soukai({ models: import.meta.glob('@/models/*', { eager: true }) })"}},new class extends V{constructor(){super("solid")}async updateFiles(e){await this.updateTailwindConfig(e),await super.updateFiles(e)}async installNpmDependencies(){await N.run("npm install soukai-solid@next --save-exact"),await super.installNpmDependencies()}async updateTailwindConfig(e){await F.animate("Updating tailwind configuration",(async()=>{const t=e.requireSourceFile("tailwind.config.js"),i=this.getTailwindContentArray(t),s=M()?`'${E("plugin-solid")}/dist/**/*.js'`:"'./node_modules/@aerogel/plugin-solid/dist/**/*.js'";if(!i)return F.fail(`\n Could not find content array in tailwind config, please add the following manually:\n\n ${s}\n `);i.addElement(s),await e.save(t)}))}getTailwindContentArray(e){const t=q(e,{guard:C.isPropertyAssignment,validate:e=>"content"===e.getName(),skip:S.JSDoc}),i=t?.getInitializer();return C.isArrayLiteralExpression(i)?i:null}}].reduce(((e,t)=>Object.assign(e,{[t.name]:t})),{});class U extends z{constructor(e){super(),t(this,"plugin",void 0),this.plugin=K[e]??F.fail(`Plugin '${e}' doesn't exist. Available plugins: ${Object.keys(K).join(", ")}`)}async run(){await this.plugin.install()}}t(U,"command","install"),t(U,"description","Install an AerogelJS plugin"),t(U,"parameters",[["plugin","Plugin to install"]]);var Y=i(new class{run(t){const i=new e;i.name("ag").description("AerogelJS CLI").version("0.0.0"),B.define(i),W.define(i),H.define(i),R.define(i),U.define(i),i.parse(t)}});export{Y 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.f16bd1d894543c5303039c49f6f33488a1ffe931",
|
|
5
5
|
"main": "dist/aerogel-cli.cjs.js",
|
|
6
6
|
"module": "dist/aerogel-cli.esm.js",
|
|
7
7
|
"types": "dist/aerogel-cli.d.ts",
|
|
@@ -8,7 +8,7 @@ import Log from '@/lib/Log';
|
|
|
8
8
|
import Template from '@/lib/Template';
|
|
9
9
|
import { app } from '@/lib/utils/app';
|
|
10
10
|
import { editFiles, findDescendant } from '@/lib/utils/edit';
|
|
11
|
-
import {
|
|
11
|
+
import { templatePath } from '@/lib/utils/paths';
|
|
12
12
|
import type { CommandOptions } from '@/commands/Command';
|
|
13
13
|
|
|
14
14
|
export interface Options {
|
|
@@ -74,11 +74,9 @@ export class GenerateComponentCommand extends Command {
|
|
|
74
74
|
Log.fail(`${this.path} component already exists!`);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const componentFiles = Template.instantiate(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{ component: { name: componentName } },
|
|
81
|
-
);
|
|
77
|
+
const componentFiles = Template.instantiate(templatePath('component'), `src/components/${directoryName}`, {
|
|
78
|
+
component: { name: componentName },
|
|
79
|
+
});
|
|
82
80
|
|
|
83
81
|
componentFiles.forEach((file) => files.add(file));
|
|
84
82
|
});
|
|
@@ -90,7 +88,7 @@ export class GenerateComponentCommand extends Command {
|
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
await Log.animate('Creating story', async () => {
|
|
93
|
-
const storyFiles = Template.instantiate(
|
|
91
|
+
const storyFiles = Template.instantiate(templatePath('component-story'), 'src/components', {
|
|
94
92
|
component: { name: componentName },
|
|
95
93
|
});
|
|
96
94
|
|
|
@@ -4,7 +4,7 @@ import Command from '@/commands/Command';
|
|
|
4
4
|
import File from '@/lib/File';
|
|
5
5
|
import Log from '@/lib/Log';
|
|
6
6
|
import Template from '@/lib/Template';
|
|
7
|
-
import {
|
|
7
|
+
import { templatePath } from '@/lib/utils/paths';
|
|
8
8
|
import { formatCodeBlock } from '@/lib/utils/format';
|
|
9
9
|
import type { CommandOptions } from '@/commands/Command';
|
|
10
10
|
|
|
@@ -41,7 +41,7 @@ export class GenerateModelCommand extends Command {
|
|
|
41
41
|
this.assertSoukaiInstalled();
|
|
42
42
|
|
|
43
43
|
const filesList = await Log.animate('Creating model', async () => {
|
|
44
|
-
const files = Template.instantiate(
|
|
44
|
+
const files = Template.instantiate(templatePath('model'), 'src/models', {
|
|
45
45
|
model: {
|
|
46
46
|
name: this.name,
|
|
47
47
|
fieldsDefinition: this.getFieldsDefinition(),
|
|
@@ -7,7 +7,7 @@ import File from '@/lib/File';
|
|
|
7
7
|
import Log from '@/lib/Log';
|
|
8
8
|
import Template from '@/lib/Template';
|
|
9
9
|
import { app } from '@/lib/utils/app';
|
|
10
|
-
import {
|
|
10
|
+
import { templatePath } from '@/lib/utils/paths';
|
|
11
11
|
import { editFiles, findDescendant } from '@/lib/utils/edit';
|
|
12
12
|
import { formatCodeBlock } from '@/lib/utils/format';
|
|
13
13
|
import type { Editor } from '@/lib/Editor';
|
|
@@ -52,7 +52,7 @@ export class GenerateServiceCommand extends Command {
|
|
|
52
52
|
Log.fail(`${this.name} service already exists!`);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const serviceFiles = Template.instantiate(
|
|
55
|
+
const serviceFiles = Template.instantiate(templatePath('service'), 'src/services', {
|
|
56
56
|
service: {
|
|
57
57
|
name: this.name,
|
|
58
58
|
},
|
|
@@ -11,8 +11,8 @@ describe('Install plugin command', () => {
|
|
|
11
11
|
await InstallCommand.run('solid');
|
|
12
12
|
|
|
13
13
|
// Assert
|
|
14
|
-
ShellMock.expectRan('npm install soukai-solid@next');
|
|
15
|
-
ShellMock.expectRan('npm install @aerogel/plugin-solid@next');
|
|
14
|
+
ShellMock.expectRan('npm install soukai-solid@next --save-exact');
|
|
15
|
+
ShellMock.expectRan('npm install @aerogel/plugin-solid@next --save-exact');
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
});
|
package/src/lib/App.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { stringToSlug } from '@noeldemartin/utils';
|
|
|
3
3
|
import File from '@/lib/File';
|
|
4
4
|
import Log from '@/lib/Log';
|
|
5
5
|
import Template from '@/lib/Template';
|
|
6
|
-
import {
|
|
6
|
+
import { packNotFound, packagePackPath, packagePath, templatePath } from '@/lib/utils/paths';
|
|
7
7
|
import { Editor } from '@/lib/Editor';
|
|
8
8
|
|
|
9
9
|
interface Dependencies {
|
|
@@ -29,7 +29,7 @@ export default class App {
|
|
|
29
29
|
Log.fail(`Folder at '${path}' already exists!`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
Template.instantiate(
|
|
32
|
+
Template.instantiate(templatePath('app'), path, {
|
|
33
33
|
app: {
|
|
34
34
|
name: this.name,
|
|
35
35
|
slug: stringToSlug(this.name),
|
package/src/lib/utils/paths.ts
CHANGED
|
@@ -28,3 +28,7 @@ export function packagePackPath(packageName: string): string | null {
|
|
|
28
28
|
export function packagePath(packageName: string): string {
|
|
29
29
|
return basePath(`../${packageName}`);
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
export function templatePath(name: string): string {
|
|
33
|
+
return resolve(__dirname, `../templates/${name}`);
|
|
34
|
+
}
|
package/src/plugins/Plugin.ts
CHANGED
|
@@ -63,7 +63,7 @@ export default abstract class Plugin {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
await Shell.run(`npm install ${this.getNpmPackageName()}@next`);
|
|
66
|
+
await Shell.run(`npm install ${this.getNpmPackageName()}@next --save-exact`);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
protected async updateBootstrapConfig(editor: Editor): Promise<void> {
|
package/src/plugins/Solid.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class Solid extends Plugin {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
protected async installNpmDependencies(): Promise<void> {
|
|
24
|
-
await Shell.run('npm install soukai-solid@next');
|
|
24
|
+
await Shell.run('npm install soukai-solid@next --save-exact');
|
|
25
25
|
await super.installNpmDependencies();
|
|
26
26
|
}
|
|
27
27
|
|
package/src/plugins/Soukai.ts
CHANGED
package/src/testing/setup.ts
CHANGED
|
@@ -55,10 +55,15 @@ vi.mock('@/lib/utils/paths', async () => {
|
|
|
55
55
|
return basePath(`../${packageName}`);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function templatePath(name: string = '') {
|
|
59
|
+
return resolve(__dirname, `../../templates/${name}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
return {
|
|
59
63
|
...original,
|
|
60
64
|
basePath,
|
|
61
65
|
packagePath,
|
|
66
|
+
templatePath,
|
|
62
67
|
};
|
|
63
68
|
});
|
|
64
69
|
|
|
@@ -3,9 +3,10 @@ import Components from 'unplugin-vue-components/vite';
|
|
|
3
3
|
import I18n from '@intlify/unplugin-vue-i18n/vite';
|
|
4
4
|
import Icons from 'unplugin-icons/vite';
|
|
5
5
|
import IconsResolver from 'unplugin-icons/resolver';
|
|
6
|
+
import { defineConfig } from 'vitest/config';
|
|
6
7
|
import { resolve } from 'path';
|
|
7
8
|
|
|
8
|
-
export default {
|
|
9
|
+
export default defineConfig({
|
|
9
10
|
plugins: [
|
|
10
11
|
Aerogel(),
|
|
11
12
|
Components({
|
|
@@ -20,4 +21,4 @@ export default {
|
|
|
20
21
|
'@': resolve(__dirname, './src'),
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
|
-
};
|
|
24
|
+
});
|
package/noeldemartin.config.js
DELETED