create-nextron-app
Advanced tools
Comparing version 3.12.0 to 4.0.0
35
index.js
@@ -14,5 +14,7 @@ #!/usr/bin/env node | ||
'--example': String, | ||
'--branch': String, | ||
'-h': '--help', | ||
'-v': '--version', | ||
'-e': '--example', | ||
'-b': '--branch', | ||
}); | ||
@@ -34,3 +36,3 @@ | ||
{bold $} {cyan create-nextron-app} {underline my-app} | ||
{bold $} {cyan create-nextron-app} {underline my-app} [--example {underline example_folder_name}] | ||
{bold $} {cyan create-nextron-app} {underline my-app} [--example {underline example_folder_name}] [--branch {underline branch_name}] | ||
@@ -42,2 +44,3 @@ {bold OPTIONS} | ||
--example, -e {underline example_folder_name} sets the example as a template | ||
--branch, -b {underline branch_name} sets the branch name | ||
`); | ||
@@ -52,7 +55,9 @@ process.exit(0); | ||
const example = args['--example'] || 'with-javascript'; | ||
const branch = args['--branch'] || 'main'; | ||
try { | ||
spinner.create('Validating existence...'); | ||
await validateExistence(example); | ||
await validateExistence(branch, example); | ||
} catch (error) { | ||
console.error(error); | ||
spinner.fail(`Not found: ${example}`); | ||
@@ -63,5 +68,5 @@ } | ||
spinner.create('Downloading and extracting...'); | ||
const name = path.join(cwd, args._[0]); | ||
await require('make-dir')(name); | ||
await downloadAndExtract(name, example, spinner); | ||
const dirname = path.join(cwd, args._[0]); | ||
await require('make-dir')(dirname); | ||
await downloadAndExtract(branch, example, dirname, spinner); | ||
} catch (error) { | ||
@@ -72,3 +77,3 @@ spinner.fail(error); | ||
async function validateExistence(example) { | ||
async function validateExistence(branch, example) { | ||
const { Octokit } = require('@octokit/rest'); | ||
@@ -78,2 +83,3 @@ await new Octokit().repos.getContent({ | ||
repo: 'nextron', | ||
ref: branch, | ||
path: `examples/${example}/package.json`, | ||
@@ -83,4 +89,5 @@ }); | ||
async function downloadAndExtract(name, example, spinner) { | ||
const mainUrl = 'https://codeload.github.com/saltyshiomix/nextron/tar.gz/main'; | ||
async function downloadAndExtract(branch, example, dirname, spinner) { | ||
const hyphenatedBranchName = branch.replace(/\//g, '-'); | ||
const mainUrl = `https://codeload.github.com/saltyshiomix/nextron/tar.gz/${branch}`; | ||
const got = require('got'); | ||
@@ -92,3 +99,3 @@ const { t, x } = require('tar'); | ||
.stream(mainUrl) | ||
.pipe(t({ cwd: name, strip: 3, filter: (path) => { | ||
.pipe(t({ cwd: dirname, strip: 3, filter: (path) => { | ||
if (path.endsWith(`${example}/tsconfig.json`)) { | ||
@@ -105,5 +112,5 @@ ext = 'ts'; | ||
.stream(mainUrl) | ||
.pipe(x({ cwd: name, strip: 3 }, ['nextron-main/examples/_template/gitignore.txt'])) | ||
.pipe(x({ cwd: dirname, strip: 3 }, [`nextron-${hyphenatedBranchName}/examples/_template/gitignore.txt`])) | ||
.on('finish', () => { | ||
fs.renameSync(path.join(name, 'gitignore.txt'), path.join(name, '.gitignore')); | ||
fs.renameSync(path.join(dirname, 'gitignore.txt'), path.join(dirname, '.gitignore')); | ||
resolve(); | ||
@@ -115,3 +122,3 @@ }); | ||
.stream(mainUrl) | ||
.pipe(x({ cwd: name, strip: 4 }, [`nextron-main/examples/_template/${ext}`])) | ||
.pipe(x({ cwd: dirname, strip: 4 }, [`nextron-${hyphenatedBranchName}/examples/_template/${ext}`])) | ||
.on('finish', () => resolve()); | ||
@@ -124,3 +131,3 @@ }), | ||
.stream(mainUrl) | ||
.pipe(x({ cwd: name, strip: 3 }, [`nextron-main/examples/${example}`])) | ||
.pipe(x({ cwd: dirname, strip: 3 }, [`nextron-${hyphenatedBranchName}/examples/${example}`])) | ||
.on('finish', () => resolve()); | ||
@@ -130,3 +137,3 @@ }); | ||
const cmd = (await pm() === 'yarn') ? 'yarn && yarn dev' : 'npm install && npm run dev'; | ||
spinner.clear(`Run \`${cmd}\` inside of "${name}" to start the app`); | ||
spinner.clear(`Run \`${cmd}\` inside of "${dirname}" to start the app`); | ||
} catch (error) { | ||
@@ -133,0 +140,0 @@ spinner.fail('Unknown error occurred.'); |
{ | ||
"name": "create-nextron-app", | ||
"version": "3.12.0", | ||
"description": "Create nextron (NEXT.js + Electron) apps in one command", | ||
"version": "4.0.0", | ||
"description": "Create nextron (Next.js + Electron) apps in one command", | ||
"repository": "git@github.com:saltyshiomix/create-nextron-app.git", | ||
@@ -6,0 +6,0 @@ "author": "Shiono Yoshihide <shiono.yoshihide@gmail.com>", |
@@ -15,3 +15,3 @@ <p align="center"><img src="https://i.imgur.com/DNOsAH0.png"></p> | ||
Create nextron (NEXT.js + Electron) apps in one command ⚡ | ||
Create nextron (Next.js + Electron) apps in one command ⚡ | ||
@@ -28,2 +28,5 @@ ## Usage | ||
$ npx create-nextron-app my-app --example with-typescript-material-ui | ||
# specific release branch of nextron | ||
$ npx create-nextron-app my-app --example with-typescript-emotion --branch release/v5 | ||
``` | ||
@@ -39,2 +42,5 @@ | ||
$ yarn create nextron-app my-app --example with-typescript-material-ui | ||
# specific release branch of nextron | ||
$ yarn create nextron-app my-app --example with-typescript-emotion --branch release/v5 | ||
``` | ||
@@ -41,0 +47,0 @@ |
9058
174
52