Skip to content

Commit

Permalink
fix(create): fetching template info without curl
Browse files Browse the repository at this point in the history
  • Loading branch information
saadjutt01 committed Dec 15, 2020
1 parent f44325d commit 289a862
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,24 @@ export async function createMinimalApp(folderPath) {
}

export async function createTemplateApp(folderPath, template) {
const {
stdout
} = shelljs.exec(
`curl https://api.github.com/repos/sasjs/template_${template}`,
{ silent: true }
const { stdout, stderr, code } = shelljs.exec(
`git ls-remote git@github.com:sasjs/template_${template}`,
{
silent: true
}
)
const response = JSON.parse(stdout)

if (response.message && response.message === 'Not Found')
throw 'Template provided is not found'
if (stderr.startsWith('ERROR: Repository not found.')) {
throw `Template "${template}" is not sasjs template`
}

if (code) {
throw `\n${stderr}`
}

if (response.full_name !== `sasjs/template_${template}`)
throw 'Template provided is not sasjs template'
if (!stdout) {
throw `Unable to fetch template "${template}"`
}

return new Promise(async (resolve, _) => {
createApp(folderPath, `https://github.com/sasjs/template_${template}.git`)
Expand Down
2 changes: 1 addition & 1 deletion test/commands/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('sasjs create', () => {
createFileStructure(
`create ${parentFolderNameTimeStamped} --template xyz`
)
).resolves.toEqual('Template provided is not found')
).resolves.toEqual('Template "xyz" is not sasjs template')
},
2 * 60 * 1000
)
Expand Down

0 comments on commit 289a862

Please sign in to comment.