create-hyperbook 0.3.9 → 0.4.0
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/create-hyperbook.js +1 -1
- package/package.json +8 -7
package/dist/create-hyperbook.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(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},s=(n,r,
|
|
2
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(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},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("chalk");c=s(c);let l=require("prompts");l=s(l);let u=require("os");u=s(u);let d=require("path");d=s(d);let f=require("fs");f=s(f);let p=require("child_process"),m=require("url");async function h(e){try{return await f.default.promises.access(e,(f.default.constants||f.default).W_OK),!0}catch{return!1}}async function g(e,t={recursive:!0}){await f.default.promises.mkdir(e,t)}function _(e){let t=[`.DS_Store`,`.git`,`.gitattributes`,`.gitignore`,`.gitlab-ci.yml`,`.hg`,`.hgcheck`,`.hgignore`,`.idea`,`.npmignore`,`.travis.yml`,`LICENSE`,`Thumbs.db`,`npm-debug.log`,`yarn-debug.log`,`yarn-error.log`];return f.default.readdirSync(e).filter(e=>!t.includes(e)).filter(e=>!/\.iml$/.test(e)).length===0}function v(e){try{(0,p.execSync)(`git --version`,{stdio:`ignore`});try{return(0,p.execSync)(`git rev-parse --is-inside-work-tree`,{stdio:`ignore`}),!1}catch{}try{return(0,p.execSync)(`hg --cwd . root`,{stdio:`ignore`}),!1}catch{}return(0,p.execSync)(`git init`,{stdio:`ignore`,cwd:e}),(0,p.execSync)(`git checkout -b main`,{stdio:`ignore`,cwd:e}),(0,p.execSync)(`git add -A`,{stdio:`ignore`,cwd:e}),(0,p.execSync)(`git commit -m "Initial commit from Hyperbook"`,{stdio:`ignore`,cwd:e}),!0}catch{return!1}}async function y(e){let{bookPath:t,name:n,description:r=``,author:i=``,authorUrl:a=``,license:o=`cc-by`,language:s=`en`,template:c=`default`}=e;if(!t||t.trim()===``)return{success:!1,root:``,bookName:``,error:`Book path is required`};let l=d.default.resolve(t.trim());if(!await h(d.default.dirname(l)))return{success:!1,root:l,bookName:``,error:`The book path is not writable, please check folder permissions.`};let p=n||d.default.basename(l);try{await g(l)}catch(e){return{success:!1,root:l,bookName:p,error:`Failed to create directory: ${e}`}}if(!_(l))return{success:!1,root:l,bookName:p,error:`Directory is not empty`};let m={name:p,version:`0.0.0`,logo:`/logo.png`,description:r,license:o,author:{name:i,url:a},language:s};try{f.default.writeFileSync(d.default.join(l,`hyperbook.json`),JSON.stringify(m,null,2)+u.default.EOL)}catch(e){return{success:!1,root:l,bookName:p,error:`Failed to write hyperbook.json: ${e}`}}try{let e=c?d.default.join(__dirname,`./templates/${c}`):d.default.join(__dirname,`./templates/default`);f.default.existsSync(e)&&await b(e,l)}catch(e){return{success:!1,root:l,bookName:p,error:`Failed to copy template files: ${e}`}}return v(l),{success:!0,root:l,bookName:p}}async function b(e,t){let n=await f.default.promises.readdir(e,{withFileTypes:!0});for(let r of n){let n=d.default.join(e,r.name),i=d.default.join(t,r.name);r.name===`gitignore`?i=d.default.join(t,`.gitignore`):r.name===`README-template.md`&&(i=d.default.join(t,`README.md`)),r.isDirectory()?(await f.default.promises.mkdir(i,{recursive:!0}),await b(n,i)):await f.default.promises.copyFile(n,i)}}async function x(){console.log(),console.log(c.default.bold(`Welcome to Hyperbook!`)),console.log();let e=process.argv[2];if(typeof e==`string`&&(e=e.trim()),!e){let t=await(0,l.default)({type:`text`,name:`path`,message:`What is your book named?`,initial:`my-book`});typeof t.path==`string`&&(e=t.path.trim())}e||(console.log(),console.log(`Please specify the book directory:`),console.log(` ${c.default.cyan(`npm create hyperbook`)} ${c.default.green(`<book-directory>`)}`),console.log(),console.log(`For example:`),console.log(` ${c.default.cyan(`npm create hyperbook`)} ${c.default.green(`my-new-book`)}`),console.log(),process.exit(1));let{description:t}=await(0,l.default)({type:`text`,name:`description`,message:`What is your book about?`,initial:``}),{author:n}=await(0,l.default)({type:`text`,name:`author`,message:`Who is the author of the book?`,initial:``}),{authorUrl:r}=await(0,l.default)({type:`text`,name:`authorUrl`,message:`What is the link to the authors homepage?`,initial:``}),{license:i}=await(0,l.default)({type:`select`,name:`license`,message:`Pick a license for your book!`,choices:[{title:`Creative Commons Zero (CC0)`,value:`cc0`},{title:`Creative Commons Attribution (CC BY)`,value:`cc-by`},{title:`Creative Commons Attribution-ShareAlike (CC BY-SA)`,value:`cc-by-sa`},{title:`Creative Commons Attribution-NoDerivs (CC BY-ND)`,value:`cc-by-nd`},{title:`Creative Commons Attribution-NonCommercial (CC BY-NC)`,value:`cc-by-nc`},{title:`Creative Commons Attribution-NonCommercial-ShareAlike (CC BY-NC-SA)`,value:`cc-by-nc-sa`},{title:`Creative Commons Attribution-NonCommercial-NoDervis (CC BY-NC-ND)`,value:`cc-by-nc-nd`},{title:`Custom`,value:`custom`}]});i===`custom`&&(i=(await(0,l.default)({type:`text`,name:`license`,message:`Which custom license you want to use?`})).license);let{language:a}=await(0,l.default)({type:`text`,name:`language`,message:`In which language is your book written? Provide a short code, e.g.: en or de`,initial:`en`}),o=d.default.join((0,m.fileURLToPath)(require("url").pathToFileURL(__filename).href),`templates`),s=[`default`];try{f.default.existsSync(o)&&(s=f.default.readdirSync(o,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name))}catch{s=[`default`]}let u=`default`;if(s.length>1){let{selectedTemplate:e}=await(0,l.default)({type:`select`,name:`selectedTemplate`,message:`Which template would you like to use?`,choices:s.map(e=>({title:e.charAt(0).toUpperCase()+e.slice(1),value:e})),initial:0});u=e||`default`}console.log(),console.log(`Creating a new hyperbook...`),console.log();let p=await y({bookPath:e,description:t,author:n,authorUrl:r,license:i,language:a,template:u});p.success||(console.error(c.default.red(`Error creating hyperbook:`),p.error),process.exit(1)),console.log(`${c.default.green(`Success!`)} Created ${p.bookName} at ${p.root}`),console.log(`Inside that directory, you can run several commands:`),console.log(),console.log(c.default.cyan(` hyperbook dev`)),console.log(` Starts the development server.`),console.log(),console.log(c.default.cyan(` hyperbook build`)),console.log(` Builds the book for production.`),console.log(),console.log(`We suggest that you begin by typing:`),console.log();let h=process.cwd(),g=p.bookName,_;_=h&&p.root.startsWith(h)?g:p.root,console.log(c.default.cyan(` cd`),_),console.log(` ${c.default.cyan(`hyperbook dev`)}`),console.log()}x().catch(e=>{console.error(c.default.red(`An error occurred:`),e),process.exit(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-hyperbook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared logic for creating new Hyperbook projects",
|
|
5
5
|
"platform": "node",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,16 +18,17 @@
|
|
|
18
18
|
"templates"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"chalk": "^
|
|
21
|
+
"chalk": "^6.0.0",
|
|
22
22
|
"prompts": "^2.4.2",
|
|
23
|
-
"@hyperbook/types": "0.
|
|
23
|
+
"@hyperbook/types": "0.24.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/node": "26.2.0",
|
|
26
27
|
"@types/prompts": "^2.4.9",
|
|
27
|
-
"rimraf": "6.
|
|
28
|
-
"tsdown": "^0.
|
|
29
|
-
"typescript": "
|
|
30
|
-
"vitest": "4.
|
|
28
|
+
"rimraf": "6.1.3",
|
|
29
|
+
"tsdown": "^0.22.14",
|
|
30
|
+
"typescript": "6.0.3",
|
|
31
|
+
"vitest": "4.1.10"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "rimraf dist && pnpm build:create && pnpm build:pkg && pnpm build:types && node postbuild.mjs",
|