-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Npx script for creating a new Onlook project (#292)
- Loading branch information
Showing
6 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const NEXT_TEMPLATE_REPO = 'onlook-dev/starter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { exec } from 'child_process'; | ||
import degit from 'degit'; | ||
import * as fs from 'fs'; | ||
import ora from 'ora'; | ||
import * as path from 'path'; | ||
import { promisify } from 'util'; | ||
import { NEXT_TEMPLATE_REPO } from './constant'; | ||
|
||
const execAsync = promisify(exec); | ||
|
||
export async function create(projectName: string) { | ||
const targetPath = path.join(process.cwd(), projectName); | ||
|
||
console.log(`Creating a new Onlook project: ${projectName}`); | ||
|
||
// Check if the directory already exists | ||
if (fs.existsSync(targetPath)) { | ||
console.error(`Error: Directory ${projectName} already exists.`); | ||
process.exit(1); | ||
} | ||
|
||
const spinner = ora('Initializing project').start(); | ||
|
||
try { | ||
// Clone the template using degit | ||
spinner.text = 'Cloning template'; | ||
const emitter = degit(NEXT_TEMPLATE_REPO, { | ||
cache: false, | ||
force: true, | ||
verbose: true, | ||
}); | ||
|
||
await emitter.clone(targetPath); | ||
|
||
// Change to the project directory | ||
process.chdir(targetPath); | ||
|
||
// Install dependencies | ||
spinner.text = 'Installing dependencies'; | ||
await execAsync('npm install'); | ||
|
||
spinner.succeed('Project created successfully'); | ||
|
||
console.log('\nTo get started:'); | ||
console.log(` cd ${projectName}`); | ||
console.log(' npm run dev'); | ||
} catch (error) { | ||
spinner.fail('Project creation failed'); | ||
console.error('An error occurred:', error); | ||
process.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters