{"id":7432,"date":"2023-10-19T15:45:19","date_gmt":"2023-10-19T07:45:19","guid":{"rendered":"https:\/\/www.appbyme.cn\/myapp\/?p=7432"},"modified":"2023-10-19T15:45:19","modified_gmt":"2023-10-19T07:45:19","slug":"nodejs%e6%89%93%e5%8c%85dmg%e6%9c%89%e5%93%aa%e4%ba%9b%e6%96%b9%e6%b3%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.appbyme.cn\/myapp\/2023\/7432\/","title":{"rendered":"nodejs\u6253\u5305dmg\u6709\u54ea\u4e9b\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p>\u5728 macOS \u7cfb\u7edf\u4e2d\uff0cdmg \u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5b89\u88c5\u5305\u683c\u5f0f\u3002\u5728 Node.js \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e93\u6765\u6253\u5305 dmg\uff0c\u4f8b\u5982 appdmg\u3001electron-builder \u7b49\u3002\u672c\u6587\u5c06\u4ece\u539f\u7406\u548c\u4f7f\u7528\u4e24\u4e2a\u65b9\u9762\u4ecb\u7ecd Node.js \u6253\u5305 dmg\u3002<\/p>\n<p>## \u539f\u7406<\/p>\n<p>dmg \u662f macOS \u7cfb\u7edf\u4e2d\u7684\u4e00\u79cd\u955c\u50cf\u6587\u4ef6\u683c\u5f0f\uff0c\u7c7b\u4f3c\u4e8e Windows \u4e2d\u7684 iso \u6587\u4ef6\u3002dmg \u53ef\u4ee5\u5c06\u591a\u4e2a\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u538b\u7f29\u548c\u52a0\u5bc6\uff0c\u65b9\u4fbf\u7528\u6237\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002<\/p>\n<p>\u5728 Node.js \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e93\u6765\u6253\u5305 dmg\uff0c\u4f8b\u5982 appdmg\u3001electron-builder \u7b49\u3002\u8fd9\u4e9b\u5e93\u7684\u672c\u8d28\u90fd\u662f\u901a\u8fc7\u8c03\u7528 macOS \u7cfb\u7edf\u4e2d\u7684\u4e00\u4e9b\u547d\u4ee4\u884c\u5de5\u5177\u6765\u5b8c\u6210 dmg \u6253\u5305\u7684\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0c\u6253\u5305 dmg \u7684\u8fc7\u7a0b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<p>1. \u521b\u5efa\u4e00\u4e2a\u7a7a\u7684 dmg \u6587\u4ef6\uff0c\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u521b\u5efa\u3002\u4f8b\u5982\uff1a<\/p>\n<p>   &#8220;`bash<\/p>\n<p>   hdiutil create -fs HFS+ -srcfolder \/path\/to\/files -volname &#8220;My App&#8221; myapp.dmg<\/p>\n<p>   &#8220;`<\/p>\n<p>   \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 \/path\/to\/files \u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u540d\u4e3a myapp.dmg \u7684 dmg \u6587\u4ef6\uff0c\u5176\u4e2d -fs \u6307\u5b9a\u4e86\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\uff0c-srcfolder \u6307\u5b9a\u4e86\u8981\u6253\u5305\u7684\u6587\u4ef6\u5939\uff0c-volname \u6307\u5b9a\u4e86 dmg \u6587\u4ef6\u7684\u5377\u6807\uff08\u5373\u663e\u793a\u5728 Finder \u7a97\u53e3\u4e2d\u7684\u540d\u79f0\uff09\u3002<\/p>\n<p>2. \u6302\u8f7d dmg \u6587\u4ef6\uff0c\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u6302\u8f7d\u3002\u4f8b\u5982\uff1a<\/p>\n<p>   &#8220;`bash<\/p>\n<p>   hdiutil attach myapp.dmg<\/p>\n<p>   &#8220;`<\/p>\n<p>   \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 myapp.dmg \u6587\u4ef6\u6302\u8f7d\u5230 macOS \u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 Finder \u6253\u5f00\u3002<\/p>\n<p>3. \u5c06\u9700\u8981\u5b89\u88c5\u7684\u6587\u4ef6\u590d\u5236\u5230 dmg \u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 cp \u547d\u4ee4\u6216\u8005\u5176\u4ed6\u65b9\u5f0f\u8fdb\u884c\u3002\u4f8b\u5982\uff1a<\/p>\n<p>   &#8220;`bash<\/p>\n<p>   cp \/path\/to\/myapp.app \/Volumes\/My\\ App\/<\/p>\n<p>   &#8220;`<\/p>\n<p>   \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 \/path\/to\/myapp.app \u6587\u4ef6\u590d\u5236\u5230\u6302\u8f7d\u7684 dmg \u6587\u4ef6\u4e2d\u7684 My App \u76ee\u5f55\u4e0b\u3002<\/p>\n<p>4. \u5378\u8f7d dmg \u6587\u4ef6\uff0c\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u5378\u8f7d\u3002\u4f8b\u5982\uff1a<\/p>\n<p>   &#8220;`bash<\/p>\n<p>   hdiutil detach \/Volumes\/My\\ App\/<\/p>\n<p>   &#8220;`<\/p>\n<p>   \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5378\u8f7d My App \u76ee\u5f55\uff0c\u4f7f\u5f97 dmg \u6587\u4ef6\u53ef\u4ee5\u6b63\u5e38\u5173\u95ed\u548c\u4fdd\u5b58\u3002<\/p>\n<p>5. \u5bf9 dmg \u6587\u4ef6\u8fdb\u884c\u538b\u7f29\u548c\u52a0\u5bc6\u3002\u8fd9\u4e2a\u6b65\u9aa4\u53ef\u4ee5\u4f7f\u7528 hdiutil \u547d\u4ee4\u884c\u5de5\u5177\u5b8c\u6210\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5de5\u5177\u5b8c\u6210\u3002\u4f8b\u5982\uff1a<\/p>\n<p>   &#8220;`bash<\/p>\n<p>   hdiutil convert myapp.dmg -format UDZO -o myapp-compressed.dmg<\/p>\n<p>   &#8220;`<\/p>\n<p>   \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06 myapp.dmg \u6587\u4ef6\u8f6c\u6362\u6210 UDZO \u683c\u5f0f\uff08\u5373\u538b\u7f29\u548c\u52a0\u5bc6\uff09\uff0c\u5e76\u4fdd\u5b58\u4e3a myapp-compressed.dmg \u6587\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f Node.js \u6253\u5305 dmg \u7684\u57fa\u672c\u539f\u7406\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 appdmg \u548c electron-builder \u4e24\u4e2a\u5e93\u6765\u6253\u5305 dmg\u3002<\/p>\n<p>## \u4f7f\u7528 appdmg<\/p>\n<p>appdmg \u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684 Node.js \u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u6253\u5305 dmg\u3002\u5b83\u7684\u4f7f\u7528\u65b9\u5f0f\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u7f16\u5199\u4e00\u4e2a JSON \u914d\u7f6e\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a config.json \u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`json<\/p>\n<p>{<\/p>\n<p>  &#8220;title&#8221;: &#8220;My App&#8221;,<\/p>\n<p>  &#8220;icon&#8221;: &#8220;path\/to\/icon.icns&#8221;,<\/p>\n<p>  &#8220;background&#8221;: &#8220;path\/to\/background.png&#8221;,<\/p>\n<p>  &#8220;contents&#8221;: [<\/p>\n<p>    {<\/p>\n<p>      &#8220;x&#8221;: 192,<\/p>\n<p>      &#8220;y&#8221;: 344,<\/p>\n<p>      &#8220;type&#8221;: &#8220;file&#8221;,<\/p>\n<p>      &#8220;path&#8221;: &#8220;path\/to\/myapp.app&#8221;<\/p>\n<p>    },<\/p>\n<p>    {<\/p>\n<p>      &#8220;x&#8221;: 448,<\/p>\n<p>      &#8220;y&#8221;: 344,<\/p>\n<p>      &#8220;type&#8221;: &#8220;link&#8221;,<\/p>\n<p>      &#8220;path&#8221;: &#8220;\/Applications&#8221;<\/p>\n<p>    }<\/p>\n<p>  ],<\/p>\n<p>  &#8220;window&#8221;: {<\/p>\n<p>    &#8220;size&#8221;: {<\/p>\n<p>      &#8220;width&#8221;: 540,<\/p>\n<p>      &#8220;height&#8221;: 380<\/p>\n<p>    }<\/p>\n<p>  }<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u4e00\u4e9b\u5fc5\u8981\u7684\u4fe1\u606f\uff0c\u4f8b\u5982\u6807\u9898\u3001\u56fe\u6807\u3001\u80cc\u666f\u3001\u5b89\u88c5\u6587\u4ef6\u7b49\u7b49\u3002\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u8c03\u7528 appdmg \u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<p>&#8220;`javascript<\/p>\n<p>const appdmg = re<a href=\"https:\/\/exe.yimenapp.com\/tool-649.html\">exe\u6587\u4ef6\u8f6f\u4ef6<\/a>quire(&#8216;appdmg&#8217;);<\/p>\n<p>const dmg = appdmg({<\/p>\n<p>  source: &#8216;path\/to\/config.json&#8217;,<\/p>\n<p>  target: &#8216;path\/to\/myapp.dmg&#8217;<\/p>\n<p>});<\/p>\n<p>dmg.on(&#8216;finish&#8217;, () =&gt; {<\/p>\n<p>  console.log(&#8216;dmg created&#8217;);<\/p>\n<p>});<\/p>\n<p>dmg.on(&#8216;error&#8217;, err =&gt; {<\/p>\n<p>  console.error(err);<\/p>\n<p>});<\/p>\n<p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/17\/14\/25192485619.jpg\" \/><\/figure>\n<\/p>\n<p>&#8220;`<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u4f1a\u8bfb\u53d6 config.json \u6587\u4ef6\uff0c\u5e76\u5c06\u6253\u5305\u540e\u7684 dmg \u6587\u4ef6\u4fdd\u5b58\u4e3a myapp.dmg\u3002<\/p>\n<p>\u4f7f\u7528 appdmg \u6253\u5305 dmg \u975e\u5e38\u7b80\u5355\uff0c\u4f46\u662f\u5b83\u7684\u529f\u80fd\u6bd4\u8f83\u6709\u9650\uff0c\u65e0\u6cd5\u6ee1\u8db3\u4e00\u4e9b\u9ad8\u7ea7\u9700\u6c42\u3002\u5982\u679c\u9700\u8981\u66f4\u591a\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 electron-builder\u3002<\/p>\n<p>## \u4f7f\u7528 electron-builde<a href=\"https:\/\/exe.yimenapp.com\/tool-373.html\">\u6587\u4ef6\u5939\u5c01\u88c5exe\u53ef\u6267\u884c\u6587\u4ef6<\/a>r<\/p>\n<p>electron-builder \u662f\u4e00\u4e2a\u57fa\u4e8e Electron \u7684\u6253\u5305\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u6253\u5305\u5404\u79cd\u7c7b\u578b\u7684\u5e94\u7528\u7a0b\u5e8f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 macOS \u7cfb\u7edf\u4e2d\uff0cdmg \u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5b89\u88c5\u5305\u683c\u5f0f\u3002\u5728 Node.js \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e93\u6765\u6253\u5305 dmg\uff0c\u4f8b\u5982 appdmg\u3001electron-builder \u7b49\u3002\u672c\u6587\u5c06\u4ece\u539f\u7406\u548c\u4f7f\u7528\u4e24\u4e2a\u65b9\u9762<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[13072,8505,79,276,87],"topic":[],"class_list":["post-7432","post","type-post","status-publish","format-standard","hentry","category-diannao","tag-mac","tag-urlexe","tag-79","tag-276","tag-87"],"_links":{"self":[{"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/posts\/7432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/comments?post=7432"}],"version-history":[{"count":0,"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/posts\/7432\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/media?parent=7432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/categories?post=7432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/tags?post=7432"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.appbyme.cn\/myapp\/wp-json\/wp\/v2\/topic?post=7432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}