@sakana-y/vue-grab-cli 0.0.1 → 0.1.1

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/bin.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- const e=require(`./init-BY4F7nfe.cjs`);let t=require(`events`);function n(e){return e==null?[]:Array.isArray(e)?e:[e]}function r(e,t,n,r){var i,a=e[t],o=~r.string.indexOf(t)?n==null||n===!0?``:String(n):typeof n==`boolean`?n:~r.boolean.indexOf(t)?n===`false`?!1:n===`true`||(e._.push((i=+n,i*0==0?i:n)),!!n):(i=+n,i*0==0?i:n);e[t]=a==null?o:Array.isArray(a)?a.concat(o):[a,o]}function i(e,t){e||=[],t||={};var i,a,o,s,c,l={_:[]},u=0,d=0,f=0,p=e.length;let m=t.alias!==void 0,h=t.unknown!==void 0,g=t.default!==void 0;if(t.alias=t.alias||{},t.string=n(t.string),t.boolean=n(t.boolean),m)for(i in t.alias)for(a=t.alias[i]=n(t.alias[i]),u=0;u<a.length;u++)(t.alias[a[u]]=a.concat(i)).splice(u,1);for(u=t.boolean.length;u-- >0;)for(a=t.alias[t.boolean[u]]||[],d=a.length;d-- >0;)t.boolean.push(a[d]);for(u=t.string.length;u-- >0;)for(a=t.alias[t.string[u]]||[],d=a.length;d-- >0;)t.string.push(a[d]);if(g){for(i in t.default)if(s=typeof t.default[i],a=t.alias[i]=t.alias[i]||[],t[s]!==void 0)for(t[s].push(i),u=0;u<a.length;u++)t[s].push(a[u])}let _=h?Object.keys(t.alias):[];for(u=0;u<p;u++){if(o=e[u],o===`--`){l._=l._.concat(e.slice(++u));break}for(d=0;d<o.length&&o.charCodeAt(d)===45;d++);if(d===0)l._.push(o);else if(o.substring(d,d+3)===`no-`){if(s=o.substring(d+3),h&&!~_.indexOf(s))return t.unknown(o);l[s]=!1}else{for(f=d+1;f<o.length&&o.charCodeAt(f)!==61;f++);for(s=o.substring(d,f),c=o.substring(++f)||u+1===p||(``+e[u+1]).charCodeAt(0)===45||e[++u],a=d===2?[s]:s,f=0;f<a.length;f++){if(s=a[f],h&&!~_.indexOf(s))return t.unknown(`-`.repeat(d)+s);r(l,s,f+1<a.length||c,t)}}}if(g)for(i in t.default)l[i]===void 0&&(l[i]=t.default[i]);if(m)for(i in l)for(a=t.alias[i]||[];a.length>0;)l[a.shift()]=l[i];return l}var a=e=>e.replace(/[<[].+/,``).trim(),o=e=>{let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,r=[],i=e=>{let t=!1,n=e[1];return n.startsWith(`...`)&&(n=n.slice(3),t=!0),{required:e[0].startsWith(`<`),value:n,variadic:t}},a;for(;a=t.exec(e);)r.push(i(a));let o;for(;o=n.exec(e);)r.push(i(o));return r},s=e=>{let t={alias:{},boolean:[]};for(let[n,r]of e.entries())r.names.length>1&&(t.alias[r.names[0]]=r.names.slice(1)),r.isBoolean&&(r.negated&&e.some((e,t)=>t!==n&&e.names.some(e=>r.names.includes(e))&&typeof e.required==`boolean`)||t.boolean.push(r.names[0]));return t},c=e=>e.sort((e,t)=>e.length>t.length?-1:1)[0],l=(e,t)=>e.length>=t?e:`${e}${` `.repeat(t-e.length)}`,u=e=>e.replace(/([a-z])-([a-z])/g,(e,t,n)=>t+n.toUpperCase()),d=(e,t,n)=>{let r=0,i=t.length,a=e,o;for(;r<i;++r)o=a[t[r]],a=a[t[r]]=r===i-1?n:o??(~t[r+1].indexOf(`.`)||!(+t[r+1]>-1)?{}:[])},f=(e,t)=>{for(let n of Object.keys(t)){let r=t[n];r.shouldTransform&&(e[n]=Array.prototype.concat.call([],e[n]),typeof r.transformFunction==`function`&&(e[n]=e[n].map(r.transformFunction)))}},p=e=>{let t=/([^\\\/]+)$/.exec(e);return t?t[1]:``},m=e=>e.split(`.`).map((e,t)=>t===0?u(e):e).join(`.`),h=class extends Error{constructor(e){super(e),this.name=this.constructor.name,typeof Error.captureStackTrace==`function`?Error.captureStackTrace(this,this.constructor):this.stack=Error(e).stack}},g=class{constructor(e,t,n){this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replace(/\.\*/g,``),this.negated=!1,this.names=a(e).split(`,`).map(e=>{let t=e.trim().replace(/^-{1,2}/,``);return t.startsWith(`no-`)&&(this.negated=!0,t=t.replace(/^no-/,``)),m(t)}).sort((e,t)=>e.length>t.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null&&(this.config.default=!0),e.includes(`<`)?this.required=!0:e.includes(`[`)?this.required=!1:this.isBoolean=!0}},_=process.argv,v=`${process.platform}-${process.arch} node-${process.version}`,y=class{constructor(e,t,n={},r){this.rawName=e,this.description=t,this.config=n,this.cli=r,this.options=[],this.aliasNames=[],this.name=a(e),this.args=o(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t=`-v, --version`){return this.versionNumber=e,this.option(t,`Display version number`),this}example(e){return this.examples.push(e),this}option(e,t,n){let r=new g(e,t,n);return this.options.push(r),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===``||this.aliasNames.includes(`!`)}get isGlobalCommand(){return this instanceof b}hasOption(e){return e=e.split(`.`)[0],this.options.find(t=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:r,helpCallback:i}=this.cli.globalCommand,a=[{body:`${e}${n?`/${n}`:``}`}];if(a.push({title:`Usage`,body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let n=c(t.map(e=>e.rawName));a.push({title:`Commands`,body:t.map(e=>` ${l(e.rawName,n.length)} ${e.description}`).join(`
2
+ require(`./init-BNCDwtX-.cjs`);let e=require(`events`);function t(e){return e==null?[]:Array.isArray(e)?e:[e]}function n(e,t,n,r){var i,a=e[t],o=~r.string.indexOf(t)?n==null||n===!0?``:String(n):typeof n==`boolean`?n:~r.boolean.indexOf(t)?n===`false`?!1:n===`true`||(e._.push((i=+n,i*0==0?i:n)),!!n):(i=+n,i*0==0?i:n);e[t]=a==null?o:Array.isArray(a)?a.concat(o):[a,o]}function r(e,r){e||=[],r||={};var i,a,o,s,c,l={_:[]},u=0,d=0,f=0,p=e.length;let m=r.alias!==void 0,h=r.unknown!==void 0,g=r.default!==void 0;if(r.alias=r.alias||{},r.string=t(r.string),r.boolean=t(r.boolean),m)for(i in r.alias)for(a=r.alias[i]=t(r.alias[i]),u=0;u<a.length;u++)(r.alias[a[u]]=a.concat(i)).splice(u,1);for(u=r.boolean.length;u-- >0;)for(a=r.alias[r.boolean[u]]||[],d=a.length;d-- >0;)r.boolean.push(a[d]);for(u=r.string.length;u-- >0;)for(a=r.alias[r.string[u]]||[],d=a.length;d-- >0;)r.string.push(a[d]);if(g){for(i in r.default)if(s=typeof r.default[i],a=r.alias[i]=r.alias[i]||[],r[s]!==void 0)for(r[s].push(i),u=0;u<a.length;u++)r[s].push(a[u])}let _=h?Object.keys(r.alias):[];for(u=0;u<p;u++){if(o=e[u],o===`--`){l._=l._.concat(e.slice(++u));break}for(d=0;d<o.length&&o.charCodeAt(d)===45;d++);if(d===0)l._.push(o);else if(o.substring(d,d+3)===`no-`){if(s=o.substring(d+3),h&&!~_.indexOf(s))return r.unknown(o);l[s]=!1}else{for(f=d+1;f<o.length&&o.charCodeAt(f)!==61;f++);for(s=o.substring(d,f),c=o.substring(++f)||u+1===p||(``+e[u+1]).charCodeAt(0)===45||e[++u],a=d===2?[s]:s,f=0;f<a.length;f++){if(s=a[f],h&&!~_.indexOf(s))return r.unknown(`-`.repeat(d)+s);n(l,s,f+1<a.length||c,r)}}}if(g)for(i in r.default)l[i]===void 0&&(l[i]=r.default[i]);if(m)for(i in l)for(a=r.alias[i]||[];a.length>0;)l[a.shift()]=l[i];return l}var i=e=>e.replace(/[<[].+/,``).trim(),a=e=>{let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,r=[],i=e=>{let t=!1,n=e[1];return n.startsWith(`...`)&&(n=n.slice(3),t=!0),{required:e[0].startsWith(`<`),value:n,variadic:t}},a;for(;a=t.exec(e);)r.push(i(a));let o;for(;o=n.exec(e);)r.push(i(o));return r},o=e=>{let t={alias:{},boolean:[]};for(let[n,r]of e.entries())r.names.length>1&&(t.alias[r.names[0]]=r.names.slice(1)),r.isBoolean&&(r.negated&&e.some((e,t)=>t!==n&&e.names.some(e=>r.names.includes(e))&&typeof e.required==`boolean`)||t.boolean.push(r.names[0]));return t},s=e=>e.sort((e,t)=>e.length>t.length?-1:1)[0],c=(e,t)=>e.length>=t?e:`${e}${` `.repeat(t-e.length)}`,l=e=>e.replace(/([a-z])-([a-z])/g,(e,t,n)=>t+n.toUpperCase()),u=(e,t,n)=>{let r=0,i=t.length,a=e,o;for(;r<i;++r)o=a[t[r]],a=a[t[r]]=r===i-1?n:o??(~t[r+1].indexOf(`.`)||!(+t[r+1]>-1)?{}:[])},d=(e,t)=>{for(let n of Object.keys(t)){let r=t[n];r.shouldTransform&&(e[n]=Array.prototype.concat.call([],e[n]),typeof r.transformFunction==`function`&&(e[n]=e[n].map(r.transformFunction)))}},f=e=>{let t=/([^\\\/]+)$/.exec(e);return t?t[1]:``},p=e=>e.split(`.`).map((e,t)=>t===0?l(e):e).join(`.`),m=class extends Error{constructor(e){super(e),this.name=this.constructor.name,typeof Error.captureStackTrace==`function`?Error.captureStackTrace(this,this.constructor):this.stack=Error(e).stack}},h=class{constructor(e,t,n){this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replace(/\.\*/g,``),this.negated=!1,this.names=i(e).split(`,`).map(e=>{let t=e.trim().replace(/^-{1,2}/,``);return t.startsWith(`no-`)&&(this.negated=!0,t=t.replace(/^no-/,``)),p(t)}).sort((e,t)=>e.length>t.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null&&(this.config.default=!0),e.includes(`<`)?this.required=!0:e.includes(`[`)?this.required=!1:this.isBoolean=!0}},g=process.argv,_=`${process.platform}-${process.arch} node-${process.version}`,v=class{constructor(e,t,n={},r){this.rawName=e,this.description=t,this.config=n,this.cli=r,this.options=[],this.aliasNames=[],this.name=i(e),this.args=a(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t=`-v, --version`){return this.versionNumber=e,this.option(t,`Display version number`),this}example(e){return this.examples.push(e),this}option(e,t,n){let r=new h(e,t,n);return this.options.push(r),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===``||this.aliasNames.includes(`!`)}get isGlobalCommand(){return this instanceof y}hasOption(e){return e=e.split(`.`)[0],this.options.find(t=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:r,helpCallback:i}=this.cli.globalCommand,a=[{body:`${e}${n?`/${n}`:``}`}];if(a.push({title:`Usage`,body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let n=s(t.map(e=>e.rawName));a.push({title:`Commands`,body:t.map(e=>` ${c(e.rawName,n.length)} ${e.description}`).join(`
3
3
  `)}),a.push({title:"For more info, run any command with the `--help` flag",body:t.map(t=>` $ ${e}${t.name===``?``:` ${t.name}`} --help`).join(`
4
- `)})}let o=this.isGlobalCommand?r:[...this.options,...r||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand&&(o=o.filter(e=>e.name!==`version`)),o.length>0){let e=c(o.map(e=>e.rawName));a.push({title:`Options`,body:o.map(t=>` ${l(t.rawName,e.length)} ${t.description} ${t.config.default===void 0?``:`(default: ${t.config.default})`}`).join(`
4
+ `)})}let o=this.isGlobalCommand?r:[...this.options,...r||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand&&(o=o.filter(e=>e.name!==`version`)),o.length>0){let e=s(o.map(e=>e.rawName));a.push({title:`Options`,body:o.map(t=>` ${c(t.rawName,e.length)} ${t.description} ${t.config.default===void 0?``:`(default: ${t.config.default})`}`).join(`
5
5
  `)})}this.examples.length>0&&a.push({title:`Examples`,body:this.examples.map(t=>typeof t==`function`?t(e):t).join(`
6
6
  `)}),i&&(a=i(a)||a),console.log(a.map(e=>e.title?`${e.title}:
7
7
  ${e.body}`:e.body).join(`
8
8
 
9
- `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;t&&console.log(`${e}/${t} ${v}`)}checkRequiredArgs(){let e=this.args.filter(e=>e.required).length;if(this.cli.args.length<e)throw new h(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!==`--`&&!this.hasOption(n)&&!t.hasOption(n))throw new h(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let t of n){let r=e[t.name.split(`.`)[0]];if(t.required){let e=n.some(e=>e.negated&&e.names.includes(t.name));if(r===!0||r===!1&&!e)throw new h(`option \`${t.rawName}\` value is missing`)}}}},b=class extends y{constructor(e){super(`@@global@@`,``,{},e)}},x=Object.assign,S=class extends t.EventEmitter{constructor(e=``){super(),this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new b(this),this.globalCommand.usage(`<command> [options]`)}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let r=new y(e,t||``,n,this);return r.globalCommand=this.globalCommand,this.commands.push(r),r}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option(`-h, --help`,`Display this message`),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t=`-v, --version`){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,r){return this.args=e,this.options=t,n&&(this.matchedCommand=n),r&&(this.matchedCommandName=r),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=_,{run:t=!0}={}){this.rawArgs=e,this.name||=e[1]?p(e[1]):`cli`;let n=!0;for(let t of this.commands){let r=this.mri(e.slice(2),t),i=r.args[0];if(t.isMatched(i)){n=!1;let e=x(x({},r),{args:r.args.slice(1)});this.setParsedInfo(e,t,i),this.emit(`command:${i}`,t)}}if(n){for(let t of this.commands)if(t.name===``){n=!1;let r=this.mri(e.slice(2),t);this.setParsedInfo(r,t),this.emit(`command:!`,t)}}if(n){let t=this.mri(e.slice(2));this.setParsedInfo(t)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),t=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),t=!1,this.unsetMatchedCommand());let r={args:this.args,options:this.options};return t&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit(`command:*`),r}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],r=s(n),a=[],o=e.indexOf(`--`);o>-1&&(a=e.slice(o+1),e=e.slice(0,o));let c=i(e,r);c=Object.keys(c).reduce((e,t)=>x(x({},e),{[m(t)]:c[t]}),{_:[]});let l=c._,u={"--":a},p=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,h=Object.create(null);for(let e of n){if(!p&&e.config.default!==void 0)for(let t of e.names)u[t]=e.config.default;Array.isArray(e.config.type)&&h[e.name]===void 0&&(h[e.name]=Object.create(null),h[e.name].shouldTransform=!0,h[e.name].transformFunction=e.config.type[0])}for(let e of Object.keys(c))e!==`_`&&(d(u,e.split(`.`),c[e]),f(u,h));return{args:l,options:u}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let r=[];return n.args.forEach((t,n)=>{t.variadic?r.push(e.slice(n)):r.push(e[n])}),r.push(t),n.commandAction.apply(this,r)}},C=(e=``)=>new S(e),w=`0.0.1`,T=C(`vue-grab`);T.command(`init`,`Initialize vue-grab in your project`).option(`-y, --yes`,`Skip prompts and use defaults`).action(async t=>{await e.t(t)}),T.help(),T.version(w),T.parse();
9
+ `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;t&&console.log(`${e}/${t} ${_}`)}checkRequiredArgs(){let e=this.args.filter(e=>e.required).length;if(this.cli.args.length<e)throw new m(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!==`--`&&!this.hasOption(n)&&!t.hasOption(n))throw new m(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let t of n){let r=e[t.name.split(`.`)[0]];if(t.required){let e=n.some(e=>e.negated&&e.names.includes(t.name));if(r===!0||r===!1&&!e)throw new m(`option \`${t.rawName}\` value is missing`)}}}},y=class extends v{constructor(e){super(`@@global@@`,``,{},e)}},b=Object.assign,x=class extends e.EventEmitter{constructor(e=``){super(),this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new y(this),this.globalCommand.usage(`<command> [options]`)}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let r=new v(e,t||``,n,this);return r.globalCommand=this.globalCommand,this.commands.push(r),r}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option(`-h, --help`,`Display this message`),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t=`-v, --version`){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,r){return this.args=e,this.options=t,n&&(this.matchedCommand=n),r&&(this.matchedCommandName=r),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=g,{run:t=!0}={}){this.rawArgs=e,this.name||=e[1]?f(e[1]):`cli`;let n=!0;for(let t of this.commands){let r=this.mri(e.slice(2),t),i=r.args[0];if(t.isMatched(i)){n=!1;let e=b(b({},r),{args:r.args.slice(1)});this.setParsedInfo(e,t,i),this.emit(`command:${i}`,t)}}if(n){for(let t of this.commands)if(t.name===``){n=!1;let r=this.mri(e.slice(2),t);this.setParsedInfo(r,t),this.emit(`command:!`,t)}}if(n){let t=this.mri(e.slice(2));this.setParsedInfo(t)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),t=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),t=!1,this.unsetMatchedCommand());let r={args:this.args,options:this.options};return t&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit(`command:*`),r}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],i=o(n),a=[],s=e.indexOf(`--`);s>-1&&(a=e.slice(s+1),e=e.slice(0,s));let c=r(e,i);c=Object.keys(c).reduce((e,t)=>b(b({},e),{[p(t)]:c[t]}),{_:[]});let l=c._,f={"--":a},m=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,h=Object.create(null);for(let e of n){if(!m&&e.config.default!==void 0)for(let t of e.names)f[t]=e.config.default;Array.isArray(e.config.type)&&h[e.name]===void 0&&(h[e.name]=Object.create(null),h[e.name].shouldTransform=!0,h[e.name].transformFunction=e.config.type[0])}for(let e of Object.keys(c))e!==`_`&&(u(f,e.split(`.`),c[e]),d(f,h));return{args:l,options:f}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let r=[];return n.args.forEach((t,n)=>{t.variadic?r.push(e.slice(n)):r.push(e[n])}),r.push(t),n.commandAction.apply(this,r)}},S=(e=``)=>new x(e),C=`0.1.1`,w=S(`vue-grab`);w.command(`init`,`Initialize vue-grab in your project`).option(`-y, --yes`,`Skip prompts and use defaults`).option(`--dry-run`,`Show the planned changes without writing files or installing packages`).option(`--skip-install`,`Do not install @sakana-y/vue-grab`).action(async e=>{try{let{initProject:t}=await Promise.resolve().then(()=>require(`./init-BNCDwtX-.cjs`)).then(e=>e.n),n=await t(e),r=n.main.status===`changed`||n.vite.status===`changed`||n.install.needed&&!n.install.skipped;n.cancelReason===`non-interactive`&&r&&(process.exitCode=1)}catch(e){console.error(e instanceof Error?e.message:String(e)),process.exitCode=1}}),w.help(),w.version(C),w.parse();
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
package/dist/bin.mjs CHANGED
@@ -1,25 +1,24 @@
1
1
  #!/usr/bin/env node
2
- import { t as e } from "./init-TuWkkzkd.js";
3
- import { EventEmitter as t } from "events";
2
+ import { EventEmitter as e } from "events";
4
3
  //#region ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
5
- function n(e) {
4
+ function t(e) {
6
5
  return e == null ? [] : Array.isArray(e) ? e : [e];
7
6
  }
8
- function r(e, t, n, r) {
7
+ function n(e, t, n, r) {
9
8
  var i, a = e[t], o = ~r.string.indexOf(t) ? n == null || n === !0 ? "" : String(n) : typeof n == "boolean" ? n : ~r.boolean.indexOf(t) ? n === "false" ? !1 : n === "true" || (e._.push((i = +n, i * 0 == 0 ? i : n)), !!n) : (i = +n, i * 0 == 0 ? i : n);
10
9
  e[t] = a == null ? o : Array.isArray(a) ? a.concat(o) : [a, o];
11
10
  }
12
- function i(e, t) {
13
- e ||= [], t ||= {};
11
+ function r(e, r) {
12
+ e ||= [], r ||= {};
14
13
  var i, a, o, s, c, l = { _: [] }, u = 0, d = 0, f = 0, p = e.length;
15
- let m = t.alias !== void 0, h = t.unknown !== void 0, g = t.default !== void 0;
16
- if (t.alias = t.alias || {}, t.string = n(t.string), t.boolean = n(t.boolean), m) for (i in t.alias) for (a = t.alias[i] = n(t.alias[i]), u = 0; u < a.length; u++) (t.alias[a[u]] = a.concat(i)).splice(u, 1);
17
- for (u = t.boolean.length; u-- > 0;) for (a = t.alias[t.boolean[u]] || [], d = a.length; d-- > 0;) t.boolean.push(a[d]);
18
- for (u = t.string.length; u-- > 0;) for (a = t.alias[t.string[u]] || [], d = a.length; d-- > 0;) t.string.push(a[d]);
14
+ let m = r.alias !== void 0, h = r.unknown !== void 0, g = r.default !== void 0;
15
+ if (r.alias = r.alias || {}, r.string = t(r.string), r.boolean = t(r.boolean), m) for (i in r.alias) for (a = r.alias[i] = t(r.alias[i]), u = 0; u < a.length; u++) (r.alias[a[u]] = a.concat(i)).splice(u, 1);
16
+ for (u = r.boolean.length; u-- > 0;) for (a = r.alias[r.boolean[u]] || [], d = a.length; d-- > 0;) r.boolean.push(a[d]);
17
+ for (u = r.string.length; u-- > 0;) for (a = r.alias[r.string[u]] || [], d = a.length; d-- > 0;) r.string.push(a[d]);
19
18
  if (g) {
20
- for (i in t.default) if (s = typeof t.default[i], a = t.alias[i] = t.alias[i] || [], t[s] !== void 0) for (t[s].push(i), u = 0; u < a.length; u++) t[s].push(a[u]);
19
+ for (i in r.default) if (s = typeof r.default[i], a = r.alias[i] = r.alias[i] || [], r[s] !== void 0) for (r[s].push(i), u = 0; u < a.length; u++) r[s].push(a[u]);
21
20
  }
22
- let _ = h ? Object.keys(t.alias) : [];
21
+ let _ = h ? Object.keys(r.alias) : [];
23
22
  for (u = 0; u < p; u++) {
24
23
  if (o = e[u], o === "--") {
25
24
  l._ = l._.concat(e.slice(++u));
@@ -28,21 +27,21 @@ function i(e, t) {
28
27
  for (d = 0; d < o.length && o.charCodeAt(d) === 45; d++);
29
28
  if (d === 0) l._.push(o);
30
29
  else if (o.substring(d, d + 3) === "no-") {
31
- if (s = o.substring(d + 3), h && !~_.indexOf(s)) return t.unknown(o);
30
+ if (s = o.substring(d + 3), h && !~_.indexOf(s)) return r.unknown(o);
32
31
  l[s] = !1;
33
32
  } else {
34
33
  for (f = d + 1; f < o.length && o.charCodeAt(f) !== 61; f++);
35
34
  for (s = o.substring(d, f), c = o.substring(++f) || u + 1 === p || ("" + e[u + 1]).charCodeAt(0) === 45 || e[++u], a = d === 2 ? [s] : s, f = 0; f < a.length; f++) {
36
- if (s = a[f], h && !~_.indexOf(s)) return t.unknown("-".repeat(d) + s);
37
- r(l, s, f + 1 < a.length || c, t);
35
+ if (s = a[f], h && !~_.indexOf(s)) return r.unknown("-".repeat(d) + s);
36
+ n(l, s, f + 1 < a.length || c, r);
38
37
  }
39
38
  }
40
39
  }
41
- if (g) for (i in t.default) l[i] === void 0 && (l[i] = t.default[i]);
42
- if (m) for (i in l) for (a = t.alias[i] || []; a.length > 0;) l[a.shift()] = l[i];
40
+ if (g) for (i in r.default) l[i] === void 0 && (l[i] = r.default[i]);
41
+ if (m) for (i in l) for (a = r.alias[i] || []; a.length > 0;) l[a.shift()] = l[i];
43
42
  return l;
44
43
  }
45
- var a = (e) => e.replace(/[<[].+/, "").trim(), o = (e) => {
44
+ var i = (e) => e.replace(/[<[].+/, "").trim(), a = (e) => {
46
45
  let t = /<([^>]+)>/g, n = /\[([^\]]+)\]/g, r = [], i = (e) => {
47
46
  let t = !1, n = e[1];
48
47
  return n.startsWith("...") && (n = n.slice(3), t = !0), {
@@ -55,38 +54,38 @@ var a = (e) => e.replace(/[<[].+/, "").trim(), o = (e) => {
55
54
  let o;
56
55
  for (; o = n.exec(e);) r.push(i(o));
57
56
  return r;
58
- }, s = (e) => {
57
+ }, o = (e) => {
59
58
  let t = {
60
59
  alias: {},
61
60
  boolean: []
62
61
  };
63
62
  for (let [n, r] of e.entries()) r.names.length > 1 && (t.alias[r.names[0]] = r.names.slice(1)), r.isBoolean && (r.negated && e.some((e, t) => t !== n && e.names.some((e) => r.names.includes(e)) && typeof e.required == "boolean") || t.boolean.push(r.names[0]));
64
63
  return t;
65
- }, c = (e) => e.sort((e, t) => e.length > t.length ? -1 : 1)[0], l = (e, t) => e.length >= t ? e : `${e}${" ".repeat(t - e.length)}`, u = (e) => e.replace(/([a-z])-([a-z])/g, (e, t, n) => t + n.toUpperCase()), d = (e, t, n) => {
64
+ }, s = (e) => e.sort((e, t) => e.length > t.length ? -1 : 1)[0], c = (e, t) => e.length >= t ? e : `${e}${" ".repeat(t - e.length)}`, l = (e) => e.replace(/([a-z])-([a-z])/g, (e, t, n) => t + n.toUpperCase()), u = (e, t, n) => {
66
65
  let r = 0, i = t.length, a = e, o;
67
66
  for (; r < i; ++r) o = a[t[r]], a = a[t[r]] = r === i - 1 ? n : o ?? (~t[r + 1].indexOf(".") || !(+t[r + 1] > -1) ? {} : []);
68
- }, f = (e, t) => {
67
+ }, d = (e, t) => {
69
68
  for (let n of Object.keys(t)) {
70
69
  let r = t[n];
71
70
  r.shouldTransform && (e[n] = Array.prototype.concat.call([], e[n]), typeof r.transformFunction == "function" && (e[n] = e[n].map(r.transformFunction)));
72
71
  }
73
- }, p = (e) => {
72
+ }, f = (e) => {
74
73
  let t = /([^\\\/]+)$/.exec(e);
75
74
  return t ? t[1] : "";
76
- }, m = (e) => e.split(".").map((e, t) => t === 0 ? u(e) : e).join("."), h = class extends Error {
75
+ }, p = (e) => e.split(".").map((e, t) => t === 0 ? l(e) : e).join("."), m = class extends Error {
77
76
  constructor(e) {
78
77
  super(e), this.name = this.constructor.name, typeof Error.captureStackTrace == "function" ? Error.captureStackTrace(this, this.constructor) : this.stack = Error(e).stack;
79
78
  }
80
- }, g = class {
79
+ }, h = class {
81
80
  constructor(e, t, n) {
82
- this.rawName = e, this.description = t, this.config = Object.assign({}, n), e = e.replace(/\.\*/g, ""), this.negated = !1, this.names = a(e).split(",").map((e) => {
81
+ this.rawName = e, this.description = t, this.config = Object.assign({}, n), e = e.replace(/\.\*/g, ""), this.negated = !1, this.names = i(e).split(",").map((e) => {
83
82
  let t = e.trim().replace(/^-{1,2}/, "");
84
- return t.startsWith("no-") && (this.negated = !0, t = t.replace(/^no-/, "")), m(t);
83
+ return t.startsWith("no-") && (this.negated = !0, t = t.replace(/^no-/, "")), p(t);
85
84
  }).sort((e, t) => e.length > t.length ? 1 : -1), this.name = this.names[this.names.length - 1], this.negated && this.config.default == null && (this.config.default = !0), e.includes("<") ? this.required = !0 : e.includes("[") ? this.required = !1 : this.isBoolean = !0;
86
85
  }
87
- }, _ = process.argv, v = `${process.platform}-${process.arch} node-${process.version}`, y = class {
86
+ }, g = process.argv, _ = `${process.platform}-${process.arch} node-${process.version}`, v = class {
88
87
  constructor(e, t, n = {}, r) {
89
- this.rawName = e, this.description = t, this.config = n, this.cli = r, this.options = [], this.aliasNames = [], this.name = a(e), this.args = o(e), this.examples = [];
88
+ this.rawName = e, this.description = t, this.config = n, this.cli = r, this.options = [], this.aliasNames = [], this.name = i(e), this.args = a(e), this.examples = [];
90
89
  }
91
90
  usage(e) {
92
91
  return this.usageText = e, this;
@@ -104,7 +103,7 @@ var a = (e) => e.replace(/[<[].+/, "").trim(), o = (e) => {
104
103
  return this.examples.push(e), this;
105
104
  }
106
105
  option(e, t, n) {
107
- let r = new g(e, t, n);
106
+ let r = new h(e, t, n);
108
107
  return this.options.push(r), this;
109
108
  }
110
109
  alias(e) {
@@ -120,7 +119,7 @@ var a = (e) => e.replace(/[<[].+/, "").trim(), o = (e) => {
120
119
  return this.name === "" || this.aliasNames.includes("!");
121
120
  }
122
121
  get isGlobalCommand() {
123
- return this instanceof b;
122
+ return this instanceof y;
124
123
  }
125
124
  hasOption(e) {
126
125
  return e = e.split(".")[0], this.options.find((t) => t.names.includes(e));
@@ -131,10 +130,10 @@ var a = (e) => e.replace(/[<[].+/, "").trim(), o = (e) => {
131
130
  title: "Usage",
132
131
  body: ` $ ${e} ${this.usageText || this.rawName}`
133
132
  }), (this.isGlobalCommand || this.isDefaultCommand) && t.length > 0) {
134
- let n = c(t.map((e) => e.rawName));
133
+ let n = s(t.map((e) => e.rawName));
135
134
  a.push({
136
135
  title: "Commands",
137
- body: t.map((e) => ` ${l(e.rawName, n.length)} ${e.description}`).join("\n")
136
+ body: t.map((e) => ` ${c(e.rawName, n.length)} ${e.description}`).join("\n")
138
137
  }), a.push({
139
138
  title: "For more info, run any command with the `--help` flag",
140
139
  body: t.map((t) => ` $ ${e}${t.name === "" ? "" : ` ${t.name}`} --help`).join("\n")
@@ -142,10 +141,10 @@ var a = (e) => e.replace(/[<[].+/, "").trim(), o = (e) => {
142
141
  }
143
142
  let o = this.isGlobalCommand ? r : [...this.options, ...r || []];
144
143
  if (!this.isGlobalCommand && !this.isDefaultCommand && (o = o.filter((e) => e.name !== "version")), o.length > 0) {
145
- let e = c(o.map((e) => e.rawName));
144
+ let e = s(o.map((e) => e.rawName));
146
145
  a.push({
147
146
  title: "Options",
148
- body: o.map((t) => ` ${l(t.rawName, e.length)} ${t.description} ${t.config.default === void 0 ? "" : `(default: ${t.config.default})`}`).join("\n")
147
+ body: o.map((t) => ` ${c(t.rawName, e.length)} ${t.description} ${t.config.default === void 0 ? "" : `(default: ${t.config.default})`}`).join("\n")
149
148
  });
150
149
  }
151
150
  this.examples.length > 0 && a.push({
@@ -156,16 +155,16 @@ ${e.body}` : e.body).join("\n\n"));
156
155
  }
157
156
  outputVersion() {
158
157
  let { name: e } = this.cli, { versionNumber: t } = this.cli.globalCommand;
159
- t && console.log(`${e}/${t} ${v}`);
158
+ t && console.log(`${e}/${t} ${_}`);
160
159
  }
161
160
  checkRequiredArgs() {
162
161
  let e = this.args.filter((e) => e.required).length;
163
- if (this.cli.args.length < e) throw new h(`missing required args for command \`${this.rawName}\``);
162
+ if (this.cli.args.length < e) throw new m(`missing required args for command \`${this.rawName}\``);
164
163
  }
165
164
  checkUnknownOptions() {
166
165
  let { options: e, globalCommand: t } = this.cli;
167
166
  if (!this.config.allowUnknownOptions) {
168
- for (let n of Object.keys(e)) if (n !== "--" && !this.hasOption(n) && !t.hasOption(n)) throw new h(`Unknown option \`${n.length > 1 ? `--${n}` : `-${n}`}\``);
167
+ for (let n of Object.keys(e)) if (n !== "--" && !this.hasOption(n) && !t.hasOption(n)) throw new m(`Unknown option \`${n.length > 1 ? `--${n}` : `-${n}`}\``);
169
168
  }
170
169
  }
171
170
  checkOptionValue() {
@@ -174,23 +173,23 @@ ${e.body}` : e.body).join("\n\n"));
174
173
  let r = e[t.name.split(".")[0]];
175
174
  if (t.required) {
176
175
  let e = n.some((e) => e.negated && e.names.includes(t.name));
177
- if (r === !0 || r === !1 && !e) throw new h(`option \`${t.rawName}\` value is missing`);
176
+ if (r === !0 || r === !1 && !e) throw new m(`option \`${t.rawName}\` value is missing`);
178
177
  }
179
178
  }
180
179
  }
181
- }, b = class extends y {
180
+ }, y = class extends v {
182
181
  constructor(e) {
183
182
  super("@@global@@", "", {}, e);
184
183
  }
185
- }, x = Object.assign, S = class extends t {
184
+ }, b = Object.assign, x = class extends e {
186
185
  constructor(e = "") {
187
- super(), this.name = e, this.commands = [], this.rawArgs = [], this.args = [], this.options = {}, this.globalCommand = new b(this), this.globalCommand.usage("<command> [options]");
186
+ super(), this.name = e, this.commands = [], this.rawArgs = [], this.args = [], this.options = {}, this.globalCommand = new y(this), this.globalCommand.usage("<command> [options]");
188
187
  }
189
188
  usage(e) {
190
189
  return this.globalCommand.usage(e), this;
191
190
  }
192
191
  command(e, t, n) {
193
- let r = new y(e, t || "", n, this);
192
+ let r = new v(e, t || "", n, this);
194
193
  return r.globalCommand = this.globalCommand, this.commands.push(r), r;
195
194
  }
196
195
  option(e, t, n) {
@@ -217,14 +216,14 @@ ${e.body}` : e.body).join("\n\n"));
217
216
  unsetMatchedCommand() {
218
217
  this.matchedCommand = void 0, this.matchedCommandName = void 0;
219
218
  }
220
- parse(e = _, { run: t = !0 } = {}) {
221
- this.rawArgs = e, this.name ||= e[1] ? p(e[1]) : "cli";
219
+ parse(e = g, { run: t = !0 } = {}) {
220
+ this.rawArgs = e, this.name ||= e[1] ? f(e[1]) : "cli";
222
221
  let n = !0;
223
222
  for (let t of this.commands) {
224
223
  let r = this.mri(e.slice(2), t), i = r.args[0];
225
224
  if (t.isMatched(i)) {
226
225
  n = !1;
227
- let e = x(x({}, r), { args: r.args.slice(1) });
226
+ let e = b(b({}, r), { args: r.args.slice(1) });
228
227
  this.setParsedInfo(e, t, i), this.emit(`command:${i}`, t);
229
228
  }
230
229
  }
@@ -247,19 +246,19 @@ ${e.body}` : e.body).join("\n\n"));
247
246
  return t && this.runMatchedCommand(), !this.matchedCommand && this.args[0] && this.emit("command:*"), r;
248
247
  }
249
248
  mri(e, t) {
250
- let n = [...this.globalCommand.options, ...t ? t.options : []], r = s(n), a = [], o = e.indexOf("--");
251
- o > -1 && (a = e.slice(o + 1), e = e.slice(0, o));
252
- let c = i(e, r);
253
- c = Object.keys(c).reduce((e, t) => x(x({}, e), { [m(t)]: c[t] }), { _: [] });
254
- let l = c._, u = { "--": a }, p = t && t.config.ignoreOptionDefaultValue ? t.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue, h = Object.create(null);
249
+ let n = [...this.globalCommand.options, ...t ? t.options : []], i = o(n), a = [], s = e.indexOf("--");
250
+ s > -1 && (a = e.slice(s + 1), e = e.slice(0, s));
251
+ let c = r(e, i);
252
+ c = Object.keys(c).reduce((e, t) => b(b({}, e), { [p(t)]: c[t] }), { _: [] });
253
+ let l = c._, f = { "--": a }, m = t && t.config.ignoreOptionDefaultValue ? t.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue, h = Object.create(null);
255
254
  for (let e of n) {
256
- if (!p && e.config.default !== void 0) for (let t of e.names) u[t] = e.config.default;
255
+ if (!m && e.config.default !== void 0) for (let t of e.names) f[t] = e.config.default;
257
256
  Array.isArray(e.config.type) && h[e.name] === void 0 && (h[e.name] = Object.create(null), h[e.name].shouldTransform = !0, h[e.name].transformFunction = e.config.type[0]);
258
257
  }
259
- for (let e of Object.keys(c)) e !== "_" && (d(u, e.split("."), c[e]), f(u, h));
258
+ for (let e of Object.keys(c)) e !== "_" && (u(f, e.split("."), c[e]), d(f, h));
260
259
  return {
261
260
  args: l,
262
- options: u
261
+ options: f
263
262
  };
264
263
  }
265
264
  runMatchedCommand() {
@@ -271,8 +270,13 @@ ${e.body}` : e.body).join("\n\n"));
271
270
  t.variadic ? r.push(e.slice(n)) : r.push(e[n]);
272
271
  }), r.push(t), n.commandAction.apply(this, r);
273
272
  }
274
- }, C = (e = "") => new S(e), w = "0.0.1", T = C("vue-grab");
275
- T.command("init", "Initialize vue-grab in your project").option("-y, --yes", "Skip prompts and use defaults").action(async (t) => {
276
- await e(t);
277
- }), T.help(), T.version(w), T.parse();
273
+ }, S = (e = "") => new x(e), C = "0.1.1", w = S("vue-grab");
274
+ w.command("init", "Initialize vue-grab in your project").option("-y, --yes", "Skip prompts and use defaults").option("--dry-run", "Show the planned changes without writing files or installing packages").option("--skip-install", "Do not install @sakana-y/vue-grab").action(async (e) => {
275
+ try {
276
+ let { initProject: t } = await import("./init-BuQE50ix.js").then((e) => e.n), n = await t(e), r = n.main.status === "changed" || n.vite.status === "changed" || n.install.needed && !n.install.skipped;
277
+ n.cancelReason === "non-interactive" && r && (process.exitCode = 1);
278
+ } catch (e) {
279
+ console.error(e instanceof Error ? e.message : String(e)), process.exitCode = 1;
280
+ }
281
+ }), w.help(), w.version(C), w.parse();
278
282
  //#endregion
@@ -0,0 +1,35 @@
1
+ export interface InitOptions {
2
+ yes?: boolean;
3
+ dryRun?: boolean;
4
+ skipInstall?: boolean;
5
+ /** Test-only override. Defaults to process.cwd(). */
6
+ cwd?: string;
7
+ }
8
+ export type InitStepStatus = "changed" | "unchanged" | "manual" | "missing";
9
+ export type InitCancelReason = "non-interactive" | "prompt-declined";
10
+ export interface InitFileStep {
11
+ path?: string;
12
+ status: InitStepStatus;
13
+ message: string;
14
+ }
15
+ export interface InitInstallStep {
16
+ needed: boolean;
17
+ skipped: boolean;
18
+ packageManager: PackageManager;
19
+ command: string;
20
+ }
21
+ export interface InitResult {
22
+ cwd: string;
23
+ supported: boolean;
24
+ packageManager: PackageManager;
25
+ install: InitInstallStep;
26
+ main: InitFileStep;
27
+ vite: InitFileStep;
28
+ applied: boolean;
29
+ dryRun: boolean;
30
+ cancelReason?: InitCancelReason;
31
+ }
32
+ type PackageManager = "pnpm" | "npm" | "yarn" | "bun";
33
+ export declare function initProject(options?: InitOptions): Promise<InitResult>;
34
+ export {};
35
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC5E,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED,KAAK,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;AAmbtD,wBAAsB,WAAW,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAwHhF"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./init-BY4F7nfe.cjs`);exports.initProject=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./init-BNCDwtX-.cjs`);exports.initProject=e.t;
@@ -0,0 +1,3 @@
1
+ export { initProject } from './commands/init';
2
+ export type { InitCancelReason, InitFileStep, InitInstallStep, InitOptions, InitResult, } from './commands/init';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,WAAW,EACX,UAAU,GACX,MAAM,iBAAiB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./init-TuWkkzkd.js";
1
+ import { t as e } from "./init-BuQE50ix.js";
2
2
  export { e as initProject };
@@ -0,0 +1,15 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let u=require(`node:child_process`),d=require(`node:fs/promises`),f=require(`node:path`);f=l(f);let p=require(`node:readline/promises`);var m=o(((e,t)=>{var n=String,r=function(){return{isColorSupported:!1,reset:n,bold:n,dim:n,italic:n,underline:n,inverse:n,hidden:n,strikethrough:n,black:n,red:n,green:n,yellow:n,blue:n,magenta:n,cyan:n,white:n,gray:n,bgBlack:n,bgRed:n,bgGreen:n,bgYellow:n,bgBlue:n,bgMagenta:n,bgCyan:n,bgWhite:n,blackBright:n,redBright:n,greenBright:n,yellowBright:n,blueBright:n,magentaBright:n,cyanBright:n,whiteBright:n,bgBlackBright:n,bgRedBright:n,bgGreenBright:n,bgYellowBright:n,bgBlueBright:n,bgMagentaBright:n,bgCyanBright:n,bgWhiteBright:n}};t.exports=r(),t.exports.createColors=r})),h=s({initProject:()=>V}),g=l(m(),1),_=`@sakana-y/vue-grab`,v=[`src/main.ts`,`src/main.js`],y=[`vite.config.ts`,`vite.config.mts`,`vite.config.js`,`vite.config.mjs`];function b(e,t){return!!(e.dependencies?.[t]??e.devDependencies?.[t]??e.peerDependencies?.[t])}async function x(e){let t=[[`pnpm-lock.yaml`,`pnpm`],[`package-lock.json`,`npm`],[`npm-shrinkwrap.json`,`npm`],[`yarn.lock`,`yarn`],[`bun.lockb`,`bun`],[`bun.lock`,`bun`]],n=await Promise.all(t.map(([t])=>(0,d.access)(f.default.join(e,t)).then(()=>!0,()=>!1)));return t.find((e,t)=>n[t])?.[1]??`npm`}function S(e){switch(e){case`pnpm`:return{command:`pnpm`,args:[`add`,`-D`,_]};case`yarn`:return{command:`yarn`,args:[`add`,`-D`,_]};case`bun`:return{command:`bun`,args:[`add`,`-d`,_]};case`npm`:return{command:`npm`,args:[`install`,`-D`,_]}}}function C(e,t){return[e,...t].join(` `)}async function w(e,t){async function n(r){let i=t[r];if(i!==void 0)try{return{relativePath:i,content:await(0,d.readFile)(f.default.join(e,i),`utf8`)}}catch(e){if(e.code!==`ENOENT`)throw e;return n(r+1)}}return n(0)}function T(e){return e.includes(`\r
2
+ `)?`\r
3
+ `:`
4
+ `}function E(e,t){return t.replace(/\n/g,T(e))}function D(e,t){let n=T(e),r=e.split(/\r?\n/),i=0;for(let e=0;e<r.length;e+=1)/^\s*import\s/.test(r[e])&&(i=e+1);return r.splice(i,0,t),r.join(n)}function O(e){if(/createVueGrab\s*\(/.test(e))return{status:`unchanged`,message:`Vue Grab runtime setup already exists in the app entrypoint.`};let t=e.match(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*createApp\s*\(/);if(!t)return{status:`manual`,message:`Could not find a simple createApp() assignment.`};let n=t[1],r=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),i=RegExp(`(^[ \\t]*)${r}\\.mount\\s*\\(`,`m`),a=e.match(i);if(!a||a.index==null)return{status:`manual`,message:`Could not find ${n}.mount(...) in the app entrypoint.`};let o=D(e,`import { createVueGrab } from "${_}";`),s=o.match(i);if(!s||s.index==null)return{status:`manual`,message:`Could not find ${n}.mount(...) after import insertion.`};let c=s[1]??``,l=E(o,`${c}if (import.meta.env.DEV) {
5
+ ${c} ${n}.use(
6
+ ${c} createVueGrab({
7
+ ${c} floatingButton: { enabled: true },
8
+ ${c} }),
9
+ ${c} );
10
+ ${c}}
11
+
12
+ `);return o=o.slice(0,s.index)+l+o.slice(s.index),{status:`changed`,content:o,message:`Added dev-only createVueGrab() setup.`}}function k(e,t){let n=0,r,i=!1,a=!1;for(let o=t;o<e.length;o+=1){let t=e[o],s=e[o+1],c=e[o-1];if(i){t===`
13
+ `&&(i=!1);continue}if(a){t===`*`&&s===`/`&&(a=!1,o+=1);continue}if(r){t===r&&c!==`\\`&&(r=void 0);continue}if(t===`/`&&s===`/`){i=!0,o+=1;continue}if(t===`/`&&s===`*`){a=!0,o+=1;continue}if(t===`'`||t===`"`||t==="`"){r=t;continue}if(t===`[`&&(n+=1),t===`]`&&(--n,n===0))return o}}function A(e,t){let n=e.lastIndexOf(`
14
+ `,t)+1;return e.slice(n,t).match(/^[ \t]*/)?.[0]??``}function j(e,t,n){let r=T(e),i=e.slice(t+1,n);if(!i.includes(`
15
+ `)&&!i.includes(`\r`)){let r=i.trim().replace(/,\s*$/,``),a=r?`${r}, vueGrabPlugin()`:`vueGrabPlugin()`;return e.slice(0,t+1)+a+e.slice(n)}let a=e.slice(0,n).replace(/\s*$/,``),o=e.slice(a.length,n),s=a.endsWith(`[`)||a.endsWith(`,`)?``:`,`,c=`${A(e,n)} `;return a+s+r+c+`vueGrabPlugin(),`+o+e.slice(n)}function M(e){if(/vueGrabPlugin\s*\(/.test(e)||e.includes(`${_}/vite`))return{status:`unchanged`,message:`Vue Grab Vite plugin already exists.`};let t=e.match(/\bplugins\s*:\s*\[/);if(!t||t.index==null)return{status:`manual`,message:`Could not find a simple Vite plugins array.`};let n=e.indexOf(`[`,t.index),r=k(e,n);return r==null?{status:`manual`,message:`Could not find the end of the Vite plugins array.`}:{status:`changed`,content:D(j(e,n,r),`import { vueGrabPlugin } from "${_}/vite";`),message:`Added vueGrabPlugin() to Vite dev server config.`}}function N(e,t){let n=[{needed:e.status===`manual`||e.status===`missing`,label:`Manual app setup needed:`,lines:[` import { createVueGrab } from "${_}";`,` if (import.meta.env.DEV) app.use(createVueGrab({ floatingButton: { enabled: true } }));`]},{needed:t.status===`manual`||t.status===`missing`,label:`Manual Vite setup needed:`,lines:[` import { vueGrabPlugin } from "${_}/vite";`,` plugins: [vue(), vueGrabPlugin()]`]}];for(let e of n)if(e.needed){console.log(g.default.yellow(e.label));for(let t of e.lines)console.log(t)}}async function P(){if(!process.stdin.isTTY)return console.log(g.default.yellow(`Non-interactive terminal detected. Re-run with --yes to apply changes.`)),`non-interactive`;let e=(0,p.createInterface)({input:process.stdin,output:process.stdout});try{let t=await e.question(`Apply these changes? (Y/n) `);return/^n(o)?$/i.test(t.trim())?`prompt-declined`:void 0}finally{e.close()}}async function F(e,t,n){await new Promise((r,i)=>{let a=(0,u.spawn)(t,n,{cwd:e,stdio:`inherit`,shell:process.platform===`win32`});a.on(`error`,i),a.on(`close`,e=>{if(e===0){r();return}i(Error(`${C(t,n)} exited with code ${e}`))})})}async function I(e){try{return JSON.parse(await(0,d.readFile)(f.default.join(e,`package.json`),`utf8`))}catch{return}}function L(e,t,n){return!e||!t?{status:`missing`,message:n}:{path:e,status:t.status,message:t.message}}function R(e,t,n,r){return t?e?{path:e,status:`manual`,message:r}:{status:`missing`,message:n}:{path:e,status:e?`manual`:`missing`,message:`Could not read package.json.`}}var z={changed:g.default.green,unchanged:g.default.cyan,manual:g.default.yellow,missing:g.default.yellow};function B(e,t){let n=t.path?` ${g.default.dim(t.path)}`:``,r=z[t.status];console.log(`${r(t.status.padEnd(9))} ${e}${n} - ${t.message}`)}async function V(e={}){let t=f.default.resolve(e.cwd??process.cwd()),[n,r,i,a]=await Promise.all([x(t),I(t),w(t,v),w(t,y)]),o=S(n),s=r?b(r,`vue`):!1,c=r?b(r,`vite`):!1,l=r?b(r,_):!1,u=i?.relativePath,p=a?.relativePath,m=!!(r&&s&&c&&u&&p);console.log(g.default.cyan(`vue-grab`)+` - Initializing...`);let h=!l,T={needed:h,skipped:h&&(!!e.skipInstall||!!e.dryRun),packageManager:n,command:C(o.command,o.args)};if(!m){let i={cwd:t,supported:!1,packageManager:n,install:T,main:R(u,r,`Could not find src/main.ts or src/main.js.`,`This does not look like a supported Vite + Vue app entrypoint.`),vite:R(p,r,`Could not find a Vite config.`,`This does not look like a supported Vite + Vue config.`),applied:!1,dryRun:!!e.dryRun};return console.log(g.default.yellow(`Unsupported project shape. Vue Grab init currently supports Vite + Vue apps.`)),N(i.main,i.vite),i}if(!u||!p||!i||!a)throw Error(`Internal: supported project missing entrypoint paths.`);let E=[],D=O(i.content),k=M(a.content),A=L(u,D,`Could not find src/main.ts or src/main.js.`),j=L(p,k,`Could not find a Vite config.`);if(D.status===`changed`&&D.content!=null&&E.push({path:u,content:D.content}),k.status===`changed`&&k.content!=null&&E.push({path:p,content:k.content}),T.needed){let e=T.skipped?`planned`:`will run`;console.log(`${g.default.green(`install `)} ${T.command} (${e})`)}else console.log(`${g.default.cyan(`unchanged`)} ${_} already installed.`);B(`entry`,A),B(`vite`,j),N(A,j);let z={cwd:t,supported:!0,packageManager:n,install:T,main:A,vite:j,applied:!1,dryRun:!!e.dryRun};if(e.dryRun)return console.log(g.default.yellow(`Dry run only. No files were changed and no packages were installed.`)),z;if(!e.yes){let e=await P();if(e)return z.cancelReason=e,console.log(g.default.yellow(`Canceled.`)),z}return await Promise.all(E.map(e=>(0,d.writeFile)(f.default.join(t,e.path),e.content,`utf8`))),T.needed&&!e.skipInstall?await F(t,o.command,o.args):T.needed&&e.skipInstall&&console.log(g.default.yellow(`Skipped install. Run ${T.command} when you are ready.`)),z.applied=!0,console.log(g.default.green(`Done!`)),z}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return V}});
@@ -0,0 +1,397 @@
1
+ import { spawn as e } from "node:child_process";
2
+ import { access as t, readFile as n, writeFile as r } from "node:fs/promises";
3
+ import i from "node:path";
4
+ import { createInterface as a } from "node:readline/promises";
5
+ //#region \0rolldown/runtime.js
6
+ var o = Object.create, s = Object.defineProperty, c = Object.getOwnPropertyDescriptor, l = Object.getOwnPropertyNames, u = Object.getPrototypeOf, d = Object.prototype.hasOwnProperty, f = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), p = (e, t) => {
7
+ let n = {};
8
+ for (var r in e) s(n, r, {
9
+ get: e[r],
10
+ enumerable: !0
11
+ });
12
+ return t || s(n, Symbol.toStringTag, { value: "Module" }), n;
13
+ }, m = (e, t, n, r) => {
14
+ if (t && typeof t == "object" || typeof t == "function") for (var i = l(t), a = 0, o = i.length, u; a < o; a++) u = i[a], !d.call(e, u) && u !== n && s(e, u, {
15
+ get: ((e) => t[e]).bind(null, u),
16
+ enumerable: !(r = c(t, u)) || r.enumerable
17
+ });
18
+ return e;
19
+ }, h = (e, t, n) => (n = e == null ? {} : o(u(e)), m(t || !e || !e.__esModule ? s(n, "default", {
20
+ value: e,
21
+ enumerable: !0
22
+ }) : n, e)), g = /* @__PURE__ */ f(((e, t) => {
23
+ var n = String, r = function() {
24
+ return {
25
+ isColorSupported: !1,
26
+ reset: n,
27
+ bold: n,
28
+ dim: n,
29
+ italic: n,
30
+ underline: n,
31
+ inverse: n,
32
+ hidden: n,
33
+ strikethrough: n,
34
+ black: n,
35
+ red: n,
36
+ green: n,
37
+ yellow: n,
38
+ blue: n,
39
+ magenta: n,
40
+ cyan: n,
41
+ white: n,
42
+ gray: n,
43
+ bgBlack: n,
44
+ bgRed: n,
45
+ bgGreen: n,
46
+ bgYellow: n,
47
+ bgBlue: n,
48
+ bgMagenta: n,
49
+ bgCyan: n,
50
+ bgWhite: n,
51
+ blackBright: n,
52
+ redBright: n,
53
+ greenBright: n,
54
+ yellowBright: n,
55
+ blueBright: n,
56
+ magentaBright: n,
57
+ cyanBright: n,
58
+ whiteBright: n,
59
+ bgBlackBright: n,
60
+ bgRedBright: n,
61
+ bgGreenBright: n,
62
+ bgYellowBright: n,
63
+ bgBlueBright: n,
64
+ bgMagentaBright: n,
65
+ bgCyanBright: n,
66
+ bgWhiteBright: n
67
+ };
68
+ };
69
+ t.exports = r(), t.exports.createColors = r;
70
+ })), _ = /* @__PURE__ */ p({ initProject: () => U }), v = /* @__PURE__ */ h(g(), 1), y = "@sakana-y/vue-grab", b = ["src/main.ts", "src/main.js"], x = [
71
+ "vite.config.ts",
72
+ "vite.config.mts",
73
+ "vite.config.js",
74
+ "vite.config.mjs"
75
+ ];
76
+ function S(e, t) {
77
+ return !!(e.dependencies?.[t] ?? e.devDependencies?.[t] ?? e.peerDependencies?.[t]);
78
+ }
79
+ async function C(e) {
80
+ let n = [
81
+ ["pnpm-lock.yaml", "pnpm"],
82
+ ["package-lock.json", "npm"],
83
+ ["npm-shrinkwrap.json", "npm"],
84
+ ["yarn.lock", "yarn"],
85
+ ["bun.lockb", "bun"],
86
+ ["bun.lock", "bun"]
87
+ ], r = await Promise.all(n.map(([n]) => t(i.join(e, n)).then(() => !0, () => !1)));
88
+ return n.find((e, t) => r[t])?.[1] ?? "npm";
89
+ }
90
+ function w(e) {
91
+ switch (e) {
92
+ case "pnpm": return {
93
+ command: "pnpm",
94
+ args: [
95
+ "add",
96
+ "-D",
97
+ y
98
+ ]
99
+ };
100
+ case "yarn": return {
101
+ command: "yarn",
102
+ args: [
103
+ "add",
104
+ "-D",
105
+ y
106
+ ]
107
+ };
108
+ case "bun": return {
109
+ command: "bun",
110
+ args: [
111
+ "add",
112
+ "-d",
113
+ y
114
+ ]
115
+ };
116
+ case "npm": return {
117
+ command: "npm",
118
+ args: [
119
+ "install",
120
+ "-D",
121
+ y
122
+ ]
123
+ };
124
+ }
125
+ }
126
+ function T(e, t) {
127
+ return [e, ...t].join(" ");
128
+ }
129
+ async function E(e, t) {
130
+ async function r(a) {
131
+ let o = t[a];
132
+ if (o !== void 0) try {
133
+ return {
134
+ relativePath: o,
135
+ content: await n(i.join(e, o), "utf8")
136
+ };
137
+ } catch (e) {
138
+ if (e.code !== "ENOENT") throw e;
139
+ return r(a + 1);
140
+ }
141
+ }
142
+ return r(0);
143
+ }
144
+ function D(e) {
145
+ return e.includes("\r\n") ? "\r\n" : "\n";
146
+ }
147
+ function O(e, t) {
148
+ return t.replace(/\n/g, D(e));
149
+ }
150
+ function k(e, t) {
151
+ let n = D(e), r = e.split(/\r?\n/), i = 0;
152
+ for (let e = 0; e < r.length; e += 1) /^\s*import\s/.test(r[e]) && (i = e + 1);
153
+ return r.splice(i, 0, t), r.join(n);
154
+ }
155
+ function A(e) {
156
+ if (/createVueGrab\s*\(/.test(e)) return {
157
+ status: "unchanged",
158
+ message: "Vue Grab runtime setup already exists in the app entrypoint."
159
+ };
160
+ let t = e.match(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*createApp\s*\(/);
161
+ if (!t) return {
162
+ status: "manual",
163
+ message: "Could not find a simple createApp() assignment."
164
+ };
165
+ let n = t[1], r = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), i = RegExp(`(^[ \\t]*)${r}\\.mount\\s*\\(`, "m"), a = e.match(i);
166
+ if (!a || a.index == null) return {
167
+ status: "manual",
168
+ message: `Could not find ${n}.mount(...) in the app entrypoint.`
169
+ };
170
+ let o = k(e, `import { createVueGrab } from "${y}";`), s = o.match(i);
171
+ if (!s || s.index == null) return {
172
+ status: "manual",
173
+ message: `Could not find ${n}.mount(...) after import insertion.`
174
+ };
175
+ let c = s[1] ?? "", l = O(o, `${c}if (import.meta.env.DEV) {
176
+ ${c} ${n}.use(
177
+ ${c} createVueGrab({
178
+ ${c} floatingButton: { enabled: true },
179
+ ${c} }),
180
+ ${c} );
181
+ ${c}}
182
+
183
+ `);
184
+ return o = o.slice(0, s.index) + l + o.slice(s.index), {
185
+ status: "changed",
186
+ content: o,
187
+ message: "Added dev-only createVueGrab() setup."
188
+ };
189
+ }
190
+ function j(e, t) {
191
+ let n = 0, r, i = !1, a = !1;
192
+ for (let o = t; o < e.length; o += 1) {
193
+ let t = e[o], s = e[o + 1], c = e[o - 1];
194
+ if (i) {
195
+ t === "\n" && (i = !1);
196
+ continue;
197
+ }
198
+ if (a) {
199
+ t === "*" && s === "/" && (a = !1, o += 1);
200
+ continue;
201
+ }
202
+ if (r) {
203
+ t === r && c !== "\\" && (r = void 0);
204
+ continue;
205
+ }
206
+ if (t === "/" && s === "/") {
207
+ i = !0, o += 1;
208
+ continue;
209
+ }
210
+ if (t === "/" && s === "*") {
211
+ a = !0, o += 1;
212
+ continue;
213
+ }
214
+ if (t === "'" || t === "\"" || t === "`") {
215
+ r = t;
216
+ continue;
217
+ }
218
+ if (t === "[" && (n += 1), t === "]" && (--n, n === 0)) return o;
219
+ }
220
+ }
221
+ function M(e, t) {
222
+ let n = e.lastIndexOf("\n", t) + 1;
223
+ return e.slice(n, t).match(/^[ \t]*/)?.[0] ?? "";
224
+ }
225
+ function N(e, t, n) {
226
+ let r = D(e), i = e.slice(t + 1, n);
227
+ if (!i.includes("\n") && !i.includes("\r")) {
228
+ let r = i.trim().replace(/,\s*$/, ""), a = r ? `${r}, vueGrabPlugin()` : "vueGrabPlugin()";
229
+ return e.slice(0, t + 1) + a + e.slice(n);
230
+ }
231
+ let a = e.slice(0, n).replace(/\s*$/, ""), o = e.slice(a.length, n), s = a.endsWith("[") || a.endsWith(",") ? "" : ",", c = `${M(e, n)} `;
232
+ return a + s + r + c + "vueGrabPlugin()," + o + e.slice(n);
233
+ }
234
+ function P(e) {
235
+ if (/vueGrabPlugin\s*\(/.test(e) || e.includes(`${y}/vite`)) return {
236
+ status: "unchanged",
237
+ message: "Vue Grab Vite plugin already exists."
238
+ };
239
+ let t = e.match(/\bplugins\s*:\s*\[/);
240
+ if (!t || t.index == null) return {
241
+ status: "manual",
242
+ message: "Could not find a simple Vite plugins array."
243
+ };
244
+ let n = e.indexOf("[", t.index), r = j(e, n);
245
+ return r == null ? {
246
+ status: "manual",
247
+ message: "Could not find the end of the Vite plugins array."
248
+ } : {
249
+ status: "changed",
250
+ content: k(N(e, n, r), `import { vueGrabPlugin } from "${y}/vite";`),
251
+ message: "Added vueGrabPlugin() to Vite dev server config."
252
+ };
253
+ }
254
+ function F(e, t) {
255
+ let n = [{
256
+ needed: e.status === "manual" || e.status === "missing",
257
+ label: "Manual app setup needed:",
258
+ lines: [` import { createVueGrab } from "${y}";`, " if (import.meta.env.DEV) app.use(createVueGrab({ floatingButton: { enabled: true } }));"]
259
+ }, {
260
+ needed: t.status === "manual" || t.status === "missing",
261
+ label: "Manual Vite setup needed:",
262
+ lines: [` import { vueGrabPlugin } from "${y}/vite";`, " plugins: [vue(), vueGrabPlugin()]"]
263
+ }];
264
+ for (let e of n) if (e.needed) {
265
+ console.log(v.default.yellow(e.label));
266
+ for (let t of e.lines) console.log(t);
267
+ }
268
+ }
269
+ async function I() {
270
+ if (!process.stdin.isTTY) return console.log(v.default.yellow("Non-interactive terminal detected. Re-run with --yes to apply changes.")), "non-interactive";
271
+ let e = a({
272
+ input: process.stdin,
273
+ output: process.stdout
274
+ });
275
+ try {
276
+ let t = await e.question("Apply these changes? (Y/n) ");
277
+ return /^n(o)?$/i.test(t.trim()) ? "prompt-declined" : void 0;
278
+ } finally {
279
+ e.close();
280
+ }
281
+ }
282
+ async function L(t, n, r) {
283
+ await new Promise((i, a) => {
284
+ let o = e(n, r, {
285
+ cwd: t,
286
+ stdio: "inherit",
287
+ shell: process.platform === "win32"
288
+ });
289
+ o.on("error", a), o.on("close", (e) => {
290
+ if (e === 0) {
291
+ i();
292
+ return;
293
+ }
294
+ a(/* @__PURE__ */ Error(`${T(n, r)} exited with code ${e}`));
295
+ });
296
+ });
297
+ }
298
+ async function R(e) {
299
+ try {
300
+ return JSON.parse(await n(i.join(e, "package.json"), "utf8"));
301
+ } catch {
302
+ return;
303
+ }
304
+ }
305
+ function z(e, t, n) {
306
+ return !e || !t ? {
307
+ status: "missing",
308
+ message: n
309
+ } : {
310
+ path: e,
311
+ status: t.status,
312
+ message: t.message
313
+ };
314
+ }
315
+ function B(e, t, n, r) {
316
+ return t ? e ? {
317
+ path: e,
318
+ status: "manual",
319
+ message: r
320
+ } : {
321
+ status: "missing",
322
+ message: n
323
+ } : {
324
+ path: e,
325
+ status: e ? "manual" : "missing",
326
+ message: "Could not read package.json."
327
+ };
328
+ }
329
+ var V = {
330
+ changed: v.default.green,
331
+ unchanged: v.default.cyan,
332
+ manual: v.default.yellow,
333
+ missing: v.default.yellow
334
+ };
335
+ function H(e, t) {
336
+ let n = t.path ? ` ${v.default.dim(t.path)}` : "", r = V[t.status];
337
+ console.log(`${r(t.status.padEnd(9))} ${e}${n} - ${t.message}`);
338
+ }
339
+ async function U(e = {}) {
340
+ let t = i.resolve(e.cwd ?? process.cwd()), [n, a, o, s] = await Promise.all([
341
+ C(t),
342
+ R(t),
343
+ E(t, b),
344
+ E(t, x)
345
+ ]), c = w(n), l = a ? S(a, "vue") : !1, u = a ? S(a, "vite") : !1, d = a ? S(a, y) : !1, f = o?.relativePath, p = s?.relativePath, m = !!(a && l && u && f && p);
346
+ console.log(v.default.cyan("vue-grab") + " - Initializing...");
347
+ let h = !d, g = {
348
+ needed: h,
349
+ skipped: h && (!!e.skipInstall || !!e.dryRun),
350
+ packageManager: n,
351
+ command: T(c.command, c.args)
352
+ };
353
+ if (!m) {
354
+ let r = {
355
+ cwd: t,
356
+ supported: !1,
357
+ packageManager: n,
358
+ install: g,
359
+ main: B(f, a, "Could not find src/main.ts or src/main.js.", "This does not look like a supported Vite + Vue app entrypoint."),
360
+ vite: B(p, a, "Could not find a Vite config.", "This does not look like a supported Vite + Vue config."),
361
+ applied: !1,
362
+ dryRun: !!e.dryRun
363
+ };
364
+ return console.log(v.default.yellow("Unsupported project shape. Vue Grab init currently supports Vite + Vue apps.")), F(r.main, r.vite), r;
365
+ }
366
+ if (!f || !p || !o || !s) throw Error("Internal: supported project missing entrypoint paths.");
367
+ let _ = [], D = A(o.content), O = P(s.content), k = z(f, D, "Could not find src/main.ts or src/main.js."), j = z(p, O, "Could not find a Vite config.");
368
+ if (D.status === "changed" && D.content != null && _.push({
369
+ path: f,
370
+ content: D.content
371
+ }), O.status === "changed" && O.content != null && _.push({
372
+ path: p,
373
+ content: O.content
374
+ }), g.needed) {
375
+ let e = g.skipped ? "planned" : "will run";
376
+ console.log(`${v.default.green("install ")} ${g.command} (${e})`);
377
+ } else console.log(`${v.default.cyan("unchanged")} ${y} already installed.`);
378
+ H("entry", k), H("vite", j), F(k, j);
379
+ let M = {
380
+ cwd: t,
381
+ supported: !0,
382
+ packageManager: n,
383
+ install: g,
384
+ main: k,
385
+ vite: j,
386
+ applied: !1,
387
+ dryRun: !!e.dryRun
388
+ };
389
+ if (e.dryRun) return console.log(v.default.yellow("Dry run only. No files were changed and no packages were installed.")), M;
390
+ if (!e.yes) {
391
+ let e = await I();
392
+ if (e) return M.cancelReason = e, console.log(v.default.yellow("Canceled.")), M;
393
+ }
394
+ return await Promise.all(_.map((e) => r(i.join(t, e.path), e.content, "utf8"))), g.needed && !e.skipInstall ? await L(t, c.command, c.args) : g.needed && e.skipInstall && console.log(v.default.yellow(`Skipped install. Run ${g.command} when you are ready.`)), M.applied = !0, console.log(v.default.green("Done!")), M;
395
+ }
396
+ //#endregion
397
+ export { _ as n, U as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sakana-y/vue-grab-cli",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "vue-grab": "./dist/bin.mjs"
@@ -27,8 +27,10 @@
27
27
  "picocolors": "^1.1.0"
28
28
  },
29
29
  "devDependencies": {
30
+ "@types/node": "^22.0.0",
30
31
  "typescript": "~5.9.3",
31
32
  "vite": "^8.0.0",
33
+ "vite-plugin-dts": "^4.5.0",
32
34
  "vitest": "^4.1.0"
33
35
  },
34
36
  "scripts": {
@@ -1 +0,0 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),l=c(o(((e,t)=>{var n=String,r=function(){return{isColorSupported:!1,reset:n,bold:n,dim:n,italic:n,underline:n,inverse:n,hidden:n,strikethrough:n,black:n,red:n,green:n,yellow:n,blue:n,magenta:n,cyan:n,white:n,gray:n,bgBlack:n,bgRed:n,bgGreen:n,bgYellow:n,bgBlue:n,bgMagenta:n,bgCyan:n,bgWhite:n,blackBright:n,redBright:n,greenBright:n,yellowBright:n,blueBright:n,magentaBright:n,cyanBright:n,whiteBright:n,bgBlackBright:n,bgRedBright:n,bgGreenBright:n,bgYellowBright:n,bgBlueBright:n,bgMagentaBright:n,bgCyanBright:n,bgWhiteBright:n}};t.exports=r(),t.exports.createColors=r}))(),1);async function u(e={}){console.log(l.default.cyan(`vue-grab`)+` — Initializing...`),console.log(l.default.green(`Done!`))}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return u}});
@@ -1,64 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), s = (e, i, o, s) => {
3
- if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
4
- get: ((e) => i[e]).bind(null, d),
5
- enumerable: !(s = n(i, d)) || s.enumerable
6
- });
7
- return e;
8
- }, c = /* @__PURE__ */ ((n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
9
- value: n,
10
- enumerable: !0
11
- }) : a, n)))((/* @__PURE__ */ o(((e, t) => {
12
- var n = String, r = function() {
13
- return {
14
- isColorSupported: !1,
15
- reset: n,
16
- bold: n,
17
- dim: n,
18
- italic: n,
19
- underline: n,
20
- inverse: n,
21
- hidden: n,
22
- strikethrough: n,
23
- black: n,
24
- red: n,
25
- green: n,
26
- yellow: n,
27
- blue: n,
28
- magenta: n,
29
- cyan: n,
30
- white: n,
31
- gray: n,
32
- bgBlack: n,
33
- bgRed: n,
34
- bgGreen: n,
35
- bgYellow: n,
36
- bgBlue: n,
37
- bgMagenta: n,
38
- bgCyan: n,
39
- bgWhite: n,
40
- blackBright: n,
41
- redBright: n,
42
- greenBright: n,
43
- yellowBright: n,
44
- blueBright: n,
45
- magentaBright: n,
46
- cyanBright: n,
47
- whiteBright: n,
48
- bgBlackBright: n,
49
- bgRedBright: n,
50
- bgGreenBright: n,
51
- bgYellowBright: n,
52
- bgBlueBright: n,
53
- bgMagentaBright: n,
54
- bgCyanBright: n,
55
- bgWhiteBright: n
56
- };
57
- };
58
- t.exports = r(), t.exports.createColors = r;
59
- })))(), 1);
60
- async function l(e = {}) {
61
- console.log(c.default.cyan("vue-grab") + " — Initializing..."), console.log(c.default.green("Done!"));
62
- }
63
- //#endregion
64
- export { l as t };