Skip to content

Refactor where starter project version is determined #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions create-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import tar from 'tar'

const require = createRequire(import.meta.url)

export async function createProject ({ dest, path, name }) {
export async function createProject ({ dest, path, name, starterProjectVersion = 9999 }) {
let looseName = /^[a-z][a-zA-Z0-9-_]+$/
let appName = 'my-enhance-app'
if (name) {
Expand All @@ -36,7 +36,7 @@ export async function createProject ({ dest, path, name }) {

try {
// Get tarball url
const latestUrl = await computeTarballUrl()
const latestUrl = await computeTarballUrl(starterProjectVersion)

// Download the starter project
await downloadStarterProject(latestUrl, starterProjectArchive)
Expand Down Expand Up @@ -103,13 +103,10 @@ async function downloadStarterProject(url, dest) {
})
}

async function computeTarballUrl() {
async function computeTarballUrl(starterProjectVersion) {
// Get url to latest starter project
const { body } = await tiny.get({url: 'https://registry.npmjs.org/@enhance/starter-project'})

// Need to pin major version set in package.json
const { starterProjectVersion } = require('./package.json')

// get keys from body.version
const latestVer = body['dist-tags'].latest
const version = Object.keys(body.versions).reduce(
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import { resolve } from 'path'
import { failure, success } from './console.js'
import { createProject } from './create-project.js'

import { createRequire } from 'module'

const args = process.argv.slice(2, process.argv.length)
const path = args[0]
const require = createRequire(import.meta.url)

// Need to pin major version set in package.json
const { starterProjectVersion } = require('./package.json')

if (!path) {
throw Error('Missing path. Pass a pathname to create a new project.')
Expand All @@ -16,7 +22,7 @@ if (!path) {
const dest = resolve(process.cwd(), path)

try {
await createProject({ path, dest })
await createProject({ path, dest, starterProjectVersion })
success({ path, dest })
}
catch (e) {
Expand Down