|
@@ -5,12 +5,13 @@ const decompress = require('decompress')
|
|
const path = require('path')
|
|
const path = require('path')
|
|
const fs = require('fs')
|
|
const fs = require('fs')
|
|
|
|
|
|
-interface FormatParams {
|
|
|
|
|
|
+export interface FormatParams {
|
|
type: string
|
|
type: string
|
|
group: string
|
|
group: string
|
|
name: string
|
|
name: string
|
|
checkout: string
|
|
checkout: string
|
|
path: string
|
|
path: string
|
|
|
|
+ strip: number
|
|
}
|
|
}
|
|
|
|
|
|
async function initLanguage (lang = 'cn') {
|
|
async function initLanguage (lang = 'cn') {
|
|
@@ -29,7 +30,7 @@ async function initLanguage (lang = 'cn') {
|
|
|
|
|
|
initLanguage()
|
|
initLanguage()
|
|
|
|
|
|
-export class DownloadRemoteProjectTemplate {
|
|
|
|
|
|
+export default class DownloadRemoteProjectTemplate {
|
|
private hooks: any
|
|
private hooks: any
|
|
private FileName: any
|
|
private FileName: any
|
|
|
|
|
|
@@ -48,7 +49,8 @@ export class DownloadRemoteProjectTemplate {
|
|
destinationFolder: string
|
|
destinationFolder: string
|
|
extract?: boolean
|
|
extract?: boolean
|
|
}) {
|
|
}) {
|
|
- const url = this.getLink(this.getFormatParams(repository, remoteFolder))
|
|
|
|
|
|
+ const params = this.getFormatParams(repository, remoteFolder)
|
|
|
|
+ const url = this.getLink(params)
|
|
const realDestinationFolder = path.resolve(__dirname, destinationFolder)
|
|
const realDestinationFolder = path.resolve(__dirname, destinationFolder)
|
|
this.checkCreateFolder(realDestinationFolder)
|
|
this.checkCreateFolder(realDestinationFolder)
|
|
if (!url) {
|
|
if (!url) {
|
|
@@ -60,7 +62,8 @@ export class DownloadRemoteProjectTemplate {
|
|
return this.download(url, realDestinationFolder, this.hooks.getOptions()).then(async () => {
|
|
return this.download(url, realDestinationFolder, this.hooks.getOptions()).then(async () => {
|
|
if (extract) {
|
|
if (extract) {
|
|
await decompress(path.resolve(realDestinationFolder, this.FileName), realDestinationFolder, {
|
|
await decompress(path.resolve(realDestinationFolder, this.FileName), realDestinationFolder, {
|
|
- filter: this.hooks.doFilterFiles
|
|
|
|
|
|
+ filter: this.hooks.doFilterFiles,
|
|
|
|
+ strip: params.strip
|
|
}).then(() => {
|
|
}).then(() => {
|
|
console.log(i18next.t('success_extract'))
|
|
console.log(i18next.t('success_extract'))
|
|
})
|
|
})
|
|
@@ -95,7 +98,8 @@ export class DownloadRemoteProjectTemplate {
|
|
group: matchArgs[8] || matchArgs[4],
|
|
group: matchArgs[8] || matchArgs[4],
|
|
name: matchArgs[9] || matchArgs[5],
|
|
name: matchArgs[9] || matchArgs[5],
|
|
checkout: matchArgs[6] || 'master',
|
|
checkout: matchArgs[6] || 'master',
|
|
- path: isRootFolder ? '' : remoteFolder
|
|
|
|
|
|
+ path: isRootFolder ? '' : remoteFolder,
|
|
|
|
+ strip: isRootFolder ? 1 : remoteFolder.split('/').length + 1
|
|
}
|
|
}
|
|
return result
|
|
return result
|
|
}
|
|
}
|