chayns-toolkit 2.0.0 → 2.0.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/lib/cli.js +2 -2
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ attempted value: ${s}
|
|
|
29
29
|
<!-- The React Devtools connection script -->
|
|
30
30
|
<script src="http://localhost:8097"><\/script>
|
|
31
31
|
${d.substring(B)}`}if(d){let B=t==="production"?{removeComments:!0,collapseWhitespace:!0,removeRedundantAttributes:!0,useShortDoctype:!0,removeEmptyAttributes:!0,removeStyleLinkTypeAttributes:!0,keepClosingSlash:!0,minifyJS:!0,minifyCSS:!0,minifyURLs:!0}:void 0;g.push(new El.default({templateContent:d,minify:B}))}if(e&&g.push(new Cl.BundleAnalyzerPlugin),t==="production"&&g.push(new xl.CleanWebpackPlugin),ml(t),t==="development"&&g.push(new vl.default({overlay:!1})),!c)throw Error("The name field in package.json has to be provided.");!n&&t!=="development"&&g.push(new Ri.default({filename:`static/css/${c}.[contenthash].css`,chunkFilename:`static/css/${c}.[chunkhash].chunk.css`}));let m=t!=="production",x=Xt({packageJson:s}),_=Sl.createHash("md5").update([JSON.stringify(x),process.env.BABEL_ENV,process.env.NODE_ENV,bl.version].join("--")).digest("hex"),w=[];j.hasFile("jsconfig.json")?w.push(new Fi.default({configFile:"jsconfig.json",extensions:[".js",".jsx"]})):j.hasFile("tsconfig.json")&&w.push(new Fi.default({extensions:[".js",".jsx",".ts",".tsx"]}));function O(B){let b=this.domAPI.moduleCss||document.querySelector(".module-css:not(.injected)");this.domAPI.moduleCss=b,b?(b.appendChild(B),b.classList.add("injected")):document.head.appendChild(B)}return{entry:!h||!l||j.hasFile("src/index.js")||j.hasFile("src/index.jsx")||j.hasFile("src/index.ts")||j.hasFile("src/index.tsx")?{index:j.resolvePath("src/index")}:{},mode:t,target:t==="development"?"web":"browserslist",devtool:m?"eval-cheap-source-map":!1,context:j.resolvePath("."),output:{path:i!=null?i:j.resolvePath("build/"),hashDigestLength:12,filename:qv({mode:t,filename:r,singleBundle:n,packageName:c}),assetModuleFilename:"static/media/[hash][ext][query]",chunkLoadingGlobal:h&&l?`webpackChunk${c==null?void 0:c.split("-").join("_")}__${process.env.BUILD_ENV||process.env.NODE_ENV}__${process.env.VERSION}`:void 0},resolve:{extensions:[".js",".jsx",".ts",".tsx"],plugins:w},module:{rules:[{test:/\.(js|jsx)$/,use:require.resolve("source-map-loader"),include:/node_modules\/chayns-components/},{test:/\.(js|jsx|ts|tsx)$/,use:{loader:require.resolve("babel-loader"),options:{presets:[["chayns-toolkit/babel",x]],babelrc:!1,configFile:!1,compact:t==="production",cacheDirectory:!0,cacheIdentifier:_}},exclude:/node_modules/},{test:/\.(css|scss)/,use:[t==="development"||n?{loader:require.resolve("style-loader"),options:u?{insert:O}:void 0}:Ri.default.loader,{loader:require.resolve("css-loader"),options:{modules:{auto:!0,localIdentName:t==="development"?"[path][name]__[local]":"[hash:base64]",exportLocalsConvention:"camelCase"}}},{loader:require.resolve("postcss-loader"),options:{postcssOptions:{plugins:[["postcss-preset-env",{autoprefixer:{flexbox:"no-2009"},stage:2}],"postcss-flexbugs-fixes",t==="production"&&"cssnano",a&&["postcss-prefix-selector",{prefix:`.${c}`}]].filter(Boolean)}}},require.resolve("sass-loader")]},{test:/\.(png|jpe?g|gif|webp)$/i,type:"asset",parser:{dataUrlCondition:{maxSize:10*1024}}},{test:/\.svg$/,use:require.resolve("@svgr/webpack")}]},plugins:g,optimization:{splitChunks:l||n?!1:{chunks:"all"}},performance:!1}}function qv({mode:t,filename:e,singleBundle:r,packageName:n}){let i=r?"":"static/js/",s=e.replace("[package]",(0,Al.paramCase)(n));return t==="development"?`${i}[name].bundle.js`:i+s}var _t=F(Hr()),D={path(t){return _t.default.hex("#16BDCA")(`\`${tn(t)}\``)},command(t){return _t.default.hex("#AC94FA")(`\`${tn(t)}\``)},code(t){return _t.default.hex("#76A9FA")(`\`${tn(t)}\``)},alt(t){return _t.default.hex("#97A6BA")(tn(t))},number(t){return _t.default.hex("#F17EB8")(t)}};function tn(t){return kv(t)?t[0]:t}function kv(t){return Array.isArray(t)}var Rg=F(require("webpack"));var J=F(Cg()),NT=J.object({host:J.string().max(255).default("adaptive").required(),port:J.number().positive().max(65535).default(1234).required(),cert:J.string().notRequired(),key:J.string().notRequired()}).required().noUnknown(),HT=J.object({singleBundle:J.boolean().default(!1).required(),filename:J.string().default("[package].[contenthash].js").required(),path:J.string().notRequired(),injectCssInPage:J.boolean().notRequired(),prefixCss:J.boolean().notRequired(),exposeModules:J.object().notRequired(),injectChaynsCss:J.boolean().notRequired(),apiVersion:J.number().notRequired()}).required().noUnknown(),Og=J.object({development:NT,output:HT,webpack:J.mixed().notRequired().default(null).test("is-function-or-null","${path} is not a function or null",t=>typeof t=="function"||t===null),jest:J.mixed().notRequired().default(null).test("is-function-or-null","${path} is not a function or null",t=>typeof t=="function"||t===null),webpackDev:J.mixed().notRequired().default(null)}).required().noUnknown();async function Pg(){var e;let t={};if(j.hasFile(wr))t=await Promise.resolve().then(()=>F(require(j.resolvePath(wr))));else if(j.hasFile(Tg)){let r=(e=await j.readFile(Tg))!=null?e:"{}";t=JSON.parse(r)}try{let r=await Og.validate(t),{host:n,cert:i,key:s}=r.development;if(n==="adaptive"){let o=Boolean(i&&s);r.development.host=o?"0.0.0.0":"localhost"}return r}catch(r){let n=r,i="";throw n.errors.length&&n.errors.forEach(s=>{i+=`- ${s}
|
|
32
|
-
`}),Error(i)}}var Tg="chayns-toolkit.json",wr="toolkit.config.js";function Er({config:t,dev:e,modifier:r}){if(!r)return t;let n=r(t,{webpack:Rg.default,dev:e});if(n===void 0)throw Error(`The webpack customization function in your ${D.path(wr)} returned nothing.`);if(typeof n!="object")throw Error(`The webpack customization function in your ${D.path(wr)} returned an invalid configuration.`);return n}var Ar=F(Hr()),q={info(t){console.info(`${Ar.default.hex("#76A9FA")("info ")} - ${t}`)},hint(t){console.info(`${Ar.default.hex("#31C48D")("hint ")} - ${t}`)},warn(t){console.info(`${Ar.default.hex("#FACA15")("warn ")} - ${t}`)},error(t){console.info(`${Ar.default.hex("#F98080")("error")} - ${t}`)},blank(t){console.info(` ${t}`)},exit(t){console.info(""),t?process.exit(t):process.exit()}};function Fg(t){return new Promise((e,r)=>{t.run((n,i)=>{n?r(n):i?e(i):r(Error("No stats available."))})})}function qg(t){return new Promise((e,r)=>{t.close(n=>{n?r(n):e()})})}var Mt=()=>{let t=new URL("https
|
|
32
|
+
`}),Error(i)}}var Tg="chayns-toolkit.json",wr="toolkit.config.js";function Er({config:t,dev:e,modifier:r}){if(!r)return t;let n=r(t,{webpack:Rg.default,dev:e});if(n===void 0)throw Error(`The webpack customization function in your ${D.path(wr)} returned nothing.`);if(typeof n!="object")throw Error(`The webpack customization function in your ${D.path(wr)} returned an invalid configuration.`);return n}var Ar=F(Hr()),q={info(t){console.info(`${Ar.default.hex("#76A9FA")("info ")} - ${t}`)},hint(t){console.info(`${Ar.default.hex("#31C48D")("hint ")} - ${t}`)},warn(t){console.info(`${Ar.default.hex("#FACA15")("warn ")} - ${t}`)},error(t){console.info(`${Ar.default.hex("#F98080")("error")} - ${t}`)},blank(t){console.info(` ${t}`)},exit(t){console.info(""),t?process.exit(t):process.exit()}};function Fg(t){return new Promise((e,r)=>{t.run((n,i)=>{n?r(n):i?e(i):r(Error("No stats available."))})})}function qg(t){return new Promise((e,r)=>{t.close(n=>{n?r(n):e()})})}var Mt=()=>{let t=new URL("https://$.chayns.net/css/".replace("$","api")),e=new URLSearchParams(window.location.search.toLowerCase());t.searchParams.set("siteId",e.get("siteid")||""),e.has("colormode")&&t.searchParams.set("colormode",e.get("colormode")||"");let r="hidden",n=o=>{document.documentElement.style.visibility=o?"":r,document.documentElement.style.overflow=o?"":r};n(!1);let i=document.getElementsByTagName("HEAD")[0],s=document.createElement("link");return s.rel="stylesheet",s.type="text/css",s.href=t.toString(),s.onload=()=>{n(!0)},s.onerror=()=>{n(!0)},i.appendChild(s),""};function Dg({analyze:t}){return async({config:e,packageJson:r})=>{var u;process.env.BABEL_ENV="production",process.env.NODE_ENV="production";let n=await en({mode:"production",analyze:t,outputFilename:e.output.filename,singleBundle:e.output.singleBundle,path:e.output.path,packageJson:r,prefixCss:e.output.prefixCss,injectCssInPage:e.output.injectCssInPage,injectChaynsCss:e.output.injectChaynsCss,exposeModules:e.output.exposeModules,apiVersion:e.output.apiVersion});if(typeof e.webpack=="function"){let l=e.webpack;n=Er({config:n,dev:!1,modifier:l})}n.plugins=(u=n.plugins)==null?void 0:u.map(l=>{var f,h;return typeof l=="object"&&typeof l.userOptions=="object"&&(((f=l.userOptions)==null?void 0:f.template)?l.userOptions.templateParameters={CHAYNS_TOOLKIT_CSS_TAG:`<script>(${Mt.toString()})()<\/script>`}:((h=l.userOptions)==null?void 0:h.templateContent)&&(l.userOptions.templateContent=l.userOptions.templateContent.replace("<%= CHAYNS_TOOLKIT_CSS_TAG %>",`<script>(${Mt.toString()})()<\/script>`))),l});let i=(0,Mg.default)(n),s=Date.now();q.info("Bundling your code...");let o=await Fg(i),a=(Date.now()-s)/1e3;if(await qg(i),o==null?void 0:o.hasErrors())q.error(`Compilation failed.
|
|
33
33
|
`),o.compilation.errors.forEach(l=>{console.error(l)});else{let l=o==null?void 0:o.toJson(),{assets:f}=l;if(q.info(`Finished build in ${D.number(a.toFixed(2))} seconds. These files were emitted:`),console.info(""),f){let h=new kg.default(ee(H({},BT),{colAligns:["left","right"]}));f.forEach(c=>{let g="B",d=c.size;c.size>1e6?(g="mB",d=c.size/1e6):c.size>1e3&&(g="kB",d=c.size/1e3);let m=`${d.toLocaleString("en-US",{maximumFractionDigits:2})} ${g}`,x=" ";c.size>5e5&&(x=Hs.default.yellow("!")),c.size>1e6&&(x=Hs.default.redBright("!")),h.push([c.name,m,x])}),console.info(h.toString())}}}}var BT={chars:{top:"","top-mid":"","top-left":"","top-right":"",bottom:"","bottom-mid":"","bottom-left":"","bottom-right":"",left:"","left-mid":"",mid:"","mid-mid":"",right:"","right-mid":"",middle:" "},style:{"padding-left":0,"padding-right":0}};var jg=F(require("child_process")),$g=F(require("path")),Lg=F(require("webpack")),Ig=F(require("webpack-dev-server"));var rt={install(t,e,r=!1){let n="npm i ";return t==="yarn"&&(n="yarn add "),Array.isArray(e)?n+=e.join(" "):n+=e,r&&(n+=" -D"),D.command(n)},remove(t,e){let r=t==="yarn"?"yarn remove ":"npm remove ";return r+=Array.isArray(e)?e.join(" "):e,D.command(r)},move(t,e,r){let n=Array.isArray(e)?e.join(" "):e;return t==="yarn"?D.command(`yarn remove ${n} && yarn add ${n}${r==="dev"?" -D":""}`):D.command(`npm install ${n}${r==="dev"?" -D":""}`)}};function Ng({devtools:t}){return async({config:e,packageJson:r,packageManager:n})=>{var g;process.env.BABEL_ENV="development",process.env.NODE_ENV="development";let{port:i,host:s,cert:o,key:a}=e.development,u=await en({analyze:!1,mode:"development",outputFilename:e.output.filename,singleBundle:e.output.singleBundle,packageJson:r,injectDevtoolsScript:t,prefixCss:e.output.prefixCss,injectCssInPage:e.output.injectCssInPage,injectChaynsCss:e.output.injectChaynsCss,exposeModules:e.output.exposeModules,apiVersion:e.output.apiVersion});if(typeof e.webpack=="function"){let d=e.webpack;u=Er({config:u,dev:!0,modifier:d})}u.plugins=(g=u.plugins)==null?void 0:g.map(d=>{var m,x;return typeof d=="object"&&typeof d.userOptions=="object"&&(((m=d.userOptions)==null?void 0:m.template)?d.userOptions.templateParameters={CHAYNS_TOOLKIT_CSS_TAG:`<script>(${Mt.toString()})()<\/script>`}:((x=d.userOptions)==null?void 0:x.templateContent)&&(d.userOptions.templateContent=d.userOptions.templateContent.replace("<%= CHAYNS_TOOLKIT_CSS_TAG %>",`<script>(${Mt.toString()})()<\/script>`))),d}),t&&("react-devtools"in(r.dependencies||{})?(q.error(`You added ${D.code`react-devtools`} as a regular dependency.`),q.blank(`Install it under ${D.code`devDependencies`} by running ${rt.move(n,"react-devtools","dev")}.
|
|
34
34
|
`),process.exit(1)):"react-devtools"in(r.devDependencies||{})||(q.error(`You need to install the ${D.code`react-devtools`} package to use the ${D.command`--devtools`} option.`),q.blank(`Run ${rt.move(n,"react-devtools","dev")} to add it as a ${D.code`devDependency`}.
|
|
35
35
|
`),process.exit(1)),(0,jg.exec)(`node ${$g.join(require.resolve("react-devtools"),"../bin.js")}`));let l=(0,Lg.default)(u),h=Er({config:{historyApiFallback:!0,compress:!0,allowedHosts:"all",host:s,port:i,client:{logging:"none",overlay:!1},server:{type:o&&a?"https":"http",options:{key:a,cert:o}},devMiddleware:{stats:{all:!1,colors:!0,errors:!0,warnings:!0}},hot:!0,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, PATCH, OPTIONS","Access-Control-Allow-Headers":"X-Requested-With, content-type, Authorization"}},dev:!0,modifier:e.webpackDev});new Ig.default(h,l).startCallback(()=>{})}}var Bs=F(require("eslint"));async function Hg(){q.info("Linting your code...");try{let t=new Bs.ESLint({fix:!0,extensions:["js","jsx","ts","tsx"]}),e=await t.lintFiles(["./src"]);await Bs.ESLint.outputFixes(e);let r=e.reduce((s,o)=>s+o.warningCount,0),n=e.reduce((s,o)=>s+o.errorCount,0),i="";(r||n)&&(i=(await t.loadFormatter("pretty")).format(e)),n+r===0?q.info(`No linting errors were found.
|
|
@@ -44,7 +44,7 @@ ${d.substring(B)}`}if(d){let B=t==="production"?{removeComments:!0,collapseWhite
|
|
|
44
44
|
module.exports = `;var Vs=F(require("fs"));function Wg({config:t}){let{cert:e,key:r}=t.development,n=!1;return r&&!e||!r&&e?(q.error(`You have specified the ${D.code(r?"key":"cert")} field in your ${D.path`chayns-toolkit.json`} file, but not ${D.code(r?"cert":"key")}. You need to specify paths in both fields for SSL to work.`),n=!0):(r&&(Vs.existsSync(r)||(q.error(`No file exists at the ${D.code`key`} path specified in ${D.path`chayns-toolkit.json`}.`),n=!0)),e&&(Vs.existsSync(e)||(q.error(`No file exists at the ${D.code`cert`} path specified in ${D.path`chayns-toolkit.json`}.`),n=!0))),n}var zg=F(require("fs")),Kg=F(require("path")),Yg=F(require("util")),VT=(0,Yg.promisify)(zg.readFile);async function Us(t){let e=Kg.resolve("package.json"),r=await VT(e,{encoding:"utf-8"}),n=JSON.parse(r),i=Object.keys(H(H({},n.dependencies),n.devDependencies));return Array.isArray(t)?i.filter(s=>t.some(o=>Jg(o)?o.test(s):o===s)):Jg(t)?i.some(s=>t.test(s)):i.includes(t)}function Jg(t){return Object.prototype.toString.call(t)==="[object RegExp]"}async function Xg(t){let e=await Us("@types/react"),r=await Us("@types/react-dom"),n=[!e&&"@types/react",!r&&"@types/react-dom"].filter(Boolean);if(n.length>0){let i=n.map(s=>D.code(s)).join(" and ");q.hint(`You should install the ${i} package${n.length>0?"s":""} to get TypeScript support for React.
|
|
45
45
|
`),t!==void 0&&q.blank(`Install them by running ${rt.install(t,n,!0)}`)}}async function Zg(){var n;if(!j.hasFile("tsconfig.json"))return!0;let r=((n=await j.readFile("tsconfig.json"))!=null?n:"").replace(/\s/gi,"");return r===""||r==="{}"}var ub=F(ab());async function lb(){return j.hasFile("tsconfig.json")?!0:(await(0,ub.default)("src/**/*.{ts,tsx}")).length>0}async function cb({packageJson:t,packageManager:e}){let r=Xr(t,"typescript"),n=await Zg();return r?(await Xg(e),n&&await fb(),!1):await lb()?(n&&await fb(),q.error(`To use TypeScript, you have to install the ${D.code`typescript`} package by running ${rt.install(e,"typescript",!0)}.`),!0):!1}async function fb(){await j.writeFile("tsconfig.json",JSON.stringify(Hk,void 0,4)),q.info(`Seems like you want to use TypeScript. A ${D.path`tsconfig.json`} file has been set up for you.`)}var Hk={compilerOptions:{allowJs:!0,allowSyntheticDefaultImports:!0,checkJs:!1,esModuleInterop:!0,experimentalDecorators:!0,isolatedModules:!0,jsx:"react",lib:["DOM","ESNext"],noEmit:!0,skipLibCheck:!0,strict:!0}};var ai=F(require("tcp-port-used"));async function pb({config:t}){let{port:e,host:r}=t.development;if(await(0,ai.check)(e,r)){q.warn(`The port ${D.number(e)} on host ${D.code(r)} is already in use. Waiting for it to free up...`);try{return await(0,ai.waitUntilFreeOnHost)(e,r,500,6e4),q.info("Is has freed up. Starting the development server..."),!1}catch{return q.error("The port did not free up within 60 seconds."),!0}}return!1}function hb(){let t=Bk.some(r=>j.hasFile(r)),e=Gk.some(r=>j.hasFile(r));if(t&&e&&(q.warn(`You have both ${D.path`package-lock.json`} and ${D.path`yarn.lock`} files in your project.
|
|
46
46
|
`),q.blank("Decide on wether you want to use Yarn or NPM and remove one of the lockfiles.")),t)return"npm";if(e)return"yarn"}var Bk=["./package-lock.json","../package-lock.json","../../package-lock.json"],Gk=["./yarn.lock","../yarn.lock","../../yarn.lock"];async function db(){let t=await j.readFile("package.json");if(t===null)throw Error("No package.json file was found.");return JSON.parse(t)}async function ui(...t){let e;try{e=await Pg()}catch(s){let o=s;q.error(`An error occured while loading the ${D.path`chayns-toolkit.json`} file:
|
|
47
|
-
`),q.blank(o.message);return}let[r,n]=await Promise.all([db(),hb()]),i=!0;for(let s of t)if(i){for(let o of s)await o({config:e,packageJson:r,packageManager:n})&&(i=!1);t.indexOf(s)!==t.length-1&&q.blank("")}}var Ut=new mb.Command;Ut.version("2.0.
|
|
47
|
+
`),q.blank(o.message);return}let[r,n]=await Promise.all([db(),hb()]),i=!0;for(let s of t)if(i){for(let o of s)await o({config:e,packageJson:r,packageManager:n})&&(i=!1);t.indexOf(s)!==t.length-1&&q.blank("")}}var Ut=new mb.Command;Ut.version("2.0.1","-v, --version","output the version number");Ut.command("dev").description("start up a development server with hot module replacement").option("-d, --devtools","open react-devtools in a separate window",!1).action(async t=>{await ui([Ug,cb,Wg,pb],[Ng({devtools:t.devtools})])});Ut.command("build").description("bundles your code for production").option("-a, --analyze","analyze your bundle size",!1).action(async t=>{try{await ui([Dg({analyze:t.analyze})])}catch(e){q.error(e)}console.info("")});Ut.command("lint").description("lints your code for possible errors").action(async()=>{await Hg(),console.info("")});Ut.command("test").description("executes all Jest tests for this project").option("-w, --watch","watch for changes to rerun tests",!1).option("--setupFile <path>","file that should be executed before the tests are initialized","").action(async t=>{try{await ui([Vg(t)])}catch(e){q.error(e)}console.info("")});Ut.parse(process.argv);
|
|
48
48
|
/*!
|
|
49
49
|
* fill-range <https://github.com/jonschlinkert/fill-range>
|
|
50
50
|
*
|