adapt-cli 3.0.0 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bowerrc +2 -2
- package/.eslintignore +1 -1
- package/.eslintrc.json +14 -14
- package/.github/CONTRIBUTING.md +8 -0
- package/.github/ISSUE_TEMPLATE.md +17 -0
- package/.github/pull_request_template.md +25 -0
- package/.github/workflows/addtomainproject.yml +19 -0
- package/.github/workflows/releases.yml +25 -0
- package/.travis.yml +46 -46
- package/README.md +266 -266
- package/bin/adapt.js +3 -3
- package/json/help-create/component.json +9 -9
- package/json/help-create/course.json +9 -9
- package/json/help-create/question.json +9 -9
- package/json/help-create.json +12 -12
- package/json/help-devinstall.json +9 -9
- package/json/help-install.json +10 -10
- package/json/help-ls.json +7 -7
- package/json/help-register.json +7 -7
- package/json/help-rename.json +7 -7
- package/json/help-search.json +8 -8
- package/json/help-uninstall.json +7 -7
- package/json/help-unregister.json +8 -8
- package/json/help-update.json +12 -12
- package/json/help-version.json +7 -7
- package/json/help.json +19 -19
- package/lib/api.js +273 -260
- package/lib/cli.js +70 -69
- package/lib/commands/authenticate.js +18 -18
- package/lib/commands/create/component.js +64 -64
- package/lib/commands/create/course.js +26 -26
- package/lib/commands/create/question.js +18 -18
- package/lib/commands/create.js +94 -85
- package/lib/commands/devinstall.js +35 -35
- package/lib/commands/help.js +31 -31
- package/lib/commands/install.js +16 -16
- package/lib/commands/ls.js +35 -9
- package/lib/commands/register.js +11 -11
- package/lib/commands/rename.js +14 -14
- package/lib/commands/search.js +11 -11
- package/lib/commands/uninstall.js +9 -9
- package/lib/commands/unregister.js +12 -12
- package/lib/commands/update.js +12 -12
- package/lib/commands/version.js +13 -13
- package/lib/econnreset.js +8 -0
- package/lib/integration/AdaptFramework/build.js +42 -39
- package/lib/integration/AdaptFramework/clone.js +27 -27
- package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -9
- package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -9
- package/lib/integration/AdaptFramework/download.js +21 -21
- package/lib/integration/AdaptFramework/erase.js +34 -34
- package/lib/integration/AdaptFramework/getLatestVersion.js +74 -79
- package/lib/integration/AdaptFramework/npmInstall.js +21 -21
- package/lib/integration/AdaptFramework.js +19 -19
- package/lib/integration/Plugin.js +404 -403
- package/lib/integration/PluginManagement/autenticate.js +47 -56
- package/lib/integration/PluginManagement/install.js +224 -222
- package/lib/integration/PluginManagement/print.js +52 -52
- package/lib/integration/PluginManagement/register.js +130 -130
- package/lib/integration/PluginManagement/rename.js +95 -101
- package/lib/integration/PluginManagement/schemas.js +8 -8
- package/lib/integration/PluginManagement/search.js +37 -46
- package/lib/integration/PluginManagement/uninstall.js +141 -141
- package/lib/integration/PluginManagement/unregister.js +91 -101
- package/lib/integration/PluginManagement/update.js +224 -224
- package/lib/integration/PluginManagement.js +21 -21
- package/lib/integration/Project.js +146 -146
- package/lib/integration/Target.js +299 -296
- package/lib/integration/getBowerRegistryConfig.js +34 -34
- package/lib/logger.js +28 -28
- package/lib/util/JSONReadValidate.js +34 -34
- package/lib/util/constants.js +38 -38
- package/lib/util/createPromptTask.js +7 -7
- package/lib/util/download.js +45 -45
- package/lib/util/errors.js +58 -58
- package/lib/util/extract.js +24 -24
- package/lib/util/getDirNameFromImportMeta.js +6 -6
- package/lib/util/promises.js +36 -36
- package/package.json +74 -40
package/lib/logger.js
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import readline from 'readline'
|
2
|
-
import chalk from 'chalk'
|
3
|
-
|
4
|
-
export default {
|
5
|
-
isLoggingProgress: false,
|
6
|
-
logProgress (...args) {
|
7
|
-
this.isLoggingProgress = true
|
8
|
-
readline.cursorTo(process.stdout, 0)
|
9
|
-
this.write(args.join(' '))
|
10
|
-
},
|
11
|
-
warn (...args) {
|
12
|
-
chalk.yellow(...args)
|
13
|
-
},
|
14
|
-
error (...args) {
|
15
|
-
chalk.red(...args)
|
16
|
-
},
|
17
|
-
log (...args) {
|
18
|
-
if (this.isLoggingProgress) {
|
19
|
-
this.isLoggingProgress = false
|
20
|
-
readline.cursorTo(process.stdout, 0)
|
21
|
-
this.write(args.join(' '))
|
22
|
-
this.write('\n')
|
23
|
-
return
|
24
|
-
}
|
25
|
-
console.log.apply(console, args)
|
26
|
-
},
|
27
|
-
write: process.stdout.write.bind(process.stdout)
|
28
|
-
}
|
1
|
+
import readline from 'readline'
|
2
|
+
import chalk from 'chalk'
|
3
|
+
|
4
|
+
export default {
|
5
|
+
isLoggingProgress: false,
|
6
|
+
logProgress (...args) {
|
7
|
+
this.isLoggingProgress = true
|
8
|
+
readline.cursorTo(process.stdout, 0)
|
9
|
+
this.write(args.join(' '))
|
10
|
+
},
|
11
|
+
warn (...args) {
|
12
|
+
chalk.yellow(...args)
|
13
|
+
},
|
14
|
+
error (...args) {
|
15
|
+
chalk.red(...args)
|
16
|
+
},
|
17
|
+
log (...args) {
|
18
|
+
if (this.isLoggingProgress) {
|
19
|
+
this.isLoggingProgress = false
|
20
|
+
readline.cursorTo(process.stdout, 0)
|
21
|
+
this.write(args.join(' '))
|
22
|
+
this.write('\n')
|
23
|
+
return
|
24
|
+
}
|
25
|
+
console.log.apply(console, args)
|
26
|
+
},
|
27
|
+
write: process.stdout.write.bind(process.stdout)
|
28
|
+
}
|
@@ -1,34 +1,34 @@
|
|
1
|
-
import fs from 'fs-extra'
|
2
|
-
import JSONLint from 'json-lint'
|
3
|
-
|
4
|
-
/**
|
5
|
-
* @param {string} filepath
|
6
|
-
* @param {function} [done]
|
7
|
-
* @returns {Promise}
|
8
|
-
*/
|
9
|
-
export async function readValidateJSON (filepath, done) {
|
10
|
-
try {
|
11
|
-
const data = await fs.readFile(filepath, 'utf8')
|
12
|
-
validateJSON(data, filepath)
|
13
|
-
done?.(null, JSON.parse(data))
|
14
|
-
return JSON.parse(data)
|
15
|
-
} catch (err) {
|
16
|
-
done?.(err.message)
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
export function readValidateJSONSync (filepath) {
|
21
|
-
const data = fs.readFileSync(filepath, 'utf-8')
|
22
|
-
validateJSON(data, filepath)
|
23
|
-
return JSON.parse(data)
|
24
|
-
}
|
25
|
-
|
26
|
-
function validateJSON (jsonData, filepath) {
|
27
|
-
const lint = JSONLint(jsonData)
|
28
|
-
if (!lint.error) return
|
29
|
-
let errorMessage = 'JSON parsing error: ' + lint.error + ', line: ' + lint.line + ', character: ' + lint.character
|
30
|
-
if (filepath) {
|
31
|
-
errorMessage += ', file: \'' + filepath + '\''
|
32
|
-
}
|
33
|
-
throw new Error(errorMessage)
|
34
|
-
}
|
1
|
+
import fs from 'fs-extra'
|
2
|
+
import JSONLint from 'json-lint'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @param {string} filepath
|
6
|
+
* @param {function} [done]
|
7
|
+
* @returns {Promise}
|
8
|
+
*/
|
9
|
+
export async function readValidateJSON (filepath, done) {
|
10
|
+
try {
|
11
|
+
const data = await fs.readFile(filepath, 'utf8')
|
12
|
+
validateJSON(data, filepath)
|
13
|
+
done?.(null, JSON.parse(data))
|
14
|
+
return JSON.parse(data)
|
15
|
+
} catch (err) {
|
16
|
+
done?.(err.message)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
export function readValidateJSONSync (filepath) {
|
21
|
+
const data = fs.readFileSync(filepath, 'utf-8')
|
22
|
+
validateJSON(data, filepath)
|
23
|
+
return JSON.parse(data)
|
24
|
+
}
|
25
|
+
|
26
|
+
function validateJSON (jsonData, filepath) {
|
27
|
+
const lint = JSONLint(jsonData)
|
28
|
+
if (!lint.error) return
|
29
|
+
let errorMessage = 'JSON parsing error: ' + lint.error + ', line: ' + lint.line + ', character: ' + lint.character
|
30
|
+
if (filepath) {
|
31
|
+
errorMessage += ', file: \'' + filepath + '\''
|
32
|
+
}
|
33
|
+
throw new Error(errorMessage)
|
34
|
+
}
|
package/lib/util/constants.js
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
import fs from 'fs-extra'
|
2
|
-
|
3
|
-
export const ADAPT_ALLOW_PRERELEASE = process.env.ADAPT_ALLOW_PRERELEASE !== 'false'
|
4
|
-
|
5
|
-
export const ADAPT_FRAMEWORK = process.env.ADAPT_FRAMEWORK || 'https://github.com/adaptlearning/adapt_framework'
|
6
|
-
|
7
|
-
export const ADAPT_COMPONENT = process.env.ADAPT_COMPONENT || 'https://github.com/adaptlearning/adapt-component'
|
8
|
-
|
9
|
-
export const ADAPT_QUESTION = process.env.ADAPT_QUESTION || 'https://github.com/adaptlearning/adapt-questionComponent'
|
10
|
-
|
11
|
-
export const ADAPT_DEFAULT_USER_AGENT = process.env.ADAPT_DEFAULT_USER_AGENT || 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'
|
12
|
-
|
13
|
-
export const HOME_DIRECTORY = [
|
14
|
-
process.env.HOME,
|
15
|
-
(process.env.HOMEDRIVE + process.env.HOMEPATH),
|
16
|
-
process.env.USERPROFILE,
|
17
|
-
'/tmp',
|
18
|
-
'/temp'
|
19
|
-
].filter(fs.existsSync)[0]
|
20
|
-
|
21
|
-
/** @type {string} */
|
22
|
-
export const PLUGIN_TYPES = [
|
23
|
-
'component',
|
24
|
-
'extension',
|
25
|
-
'menu',
|
26
|
-
'theme'
|
27
|
-
]
|
28
|
-
|
29
|
-
/** @type {Object} */
|
30
|
-
export const PLUGIN_TYPE_FOLDERS = {
|
31
|
-
component: 'components',
|
32
|
-
extension: 'extensions',
|
33
|
-
menu: 'menu',
|
34
|
-
theme: 'theme'
|
35
|
-
}
|
36
|
-
|
37
|
-
/** @type {string} */
|
38
|
-
export const PLUGIN_DEFAULT_TYPE = PLUGIN_TYPES[0]
|
1
|
+
import fs from 'fs-extra'
|
2
|
+
|
3
|
+
export const ADAPT_ALLOW_PRERELEASE = process.env.ADAPT_ALLOW_PRERELEASE !== 'false'
|
4
|
+
|
5
|
+
export const ADAPT_FRAMEWORK = process.env.ADAPT_FRAMEWORK || 'https://github.com/adaptlearning/adapt_framework'
|
6
|
+
|
7
|
+
export const ADAPT_COMPONENT = process.env.ADAPT_COMPONENT || 'https://github.com/adaptlearning/adapt-component'
|
8
|
+
|
9
|
+
export const ADAPT_QUESTION = process.env.ADAPT_QUESTION || 'https://github.com/adaptlearning/adapt-questionComponent'
|
10
|
+
|
11
|
+
export const ADAPT_DEFAULT_USER_AGENT = process.env.ADAPT_DEFAULT_USER_AGENT || 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'
|
12
|
+
|
13
|
+
export const HOME_DIRECTORY = [
|
14
|
+
process.env.HOME,
|
15
|
+
(process.env.HOMEDRIVE + process.env.HOMEPATH),
|
16
|
+
process.env.USERPROFILE,
|
17
|
+
'/tmp',
|
18
|
+
'/temp'
|
19
|
+
].filter(fs.existsSync)[0]
|
20
|
+
|
21
|
+
/** @type {string} */
|
22
|
+
export const PLUGIN_TYPES = [
|
23
|
+
'component',
|
24
|
+
'extension',
|
25
|
+
'menu',
|
26
|
+
'theme'
|
27
|
+
]
|
28
|
+
|
29
|
+
/** @type {Object} */
|
30
|
+
export const PLUGIN_TYPE_FOLDERS = {
|
31
|
+
component: 'components',
|
32
|
+
extension: 'extensions',
|
33
|
+
menu: 'menu',
|
34
|
+
theme: 'theme'
|
35
|
+
}
|
36
|
+
|
37
|
+
/** @type {string} */
|
38
|
+
export const PLUGIN_DEFAULT_TYPE = PLUGIN_TYPES[0]
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import inquirer from 'inquirer'
|
2
|
-
|
3
|
-
export async function createPromptTask (question) {
|
4
|
-
question = Object.assign({}, { name: 'question' }, question)
|
5
|
-
const confirmation = await inquirer.prompt([question])
|
6
|
-
return confirmation.question
|
7
|
-
}
|
1
|
+
import inquirer from 'inquirer'
|
2
|
+
|
3
|
+
export async function createPromptTask (question) {
|
4
|
+
question = Object.assign({}, { name: 'question' }, question)
|
5
|
+
const confirmation = await inquirer.prompt([question])
|
6
|
+
return confirmation.question
|
7
|
+
}
|
package/lib/util/download.js
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
import chalk from 'chalk'
|
2
|
-
import uuid from 'uuid'
|
3
|
-
import fs from 'fs-extra'
|
4
|
-
import path from 'path'
|
5
|
-
import urljoin from 'url-join'
|
6
|
-
import fetch from 'download'
|
7
|
-
import { HOME_DIRECTORY } from './constants.js'
|
8
|
-
import gh from 'parse-github-url'
|
9
|
-
|
10
|
-
export default async function download ({
|
11
|
-
repository,
|
12
|
-
branch,
|
13
|
-
tmp,
|
14
|
-
cwd,
|
15
|
-
logger
|
16
|
-
} = {}) {
|
17
|
-
if (!branch && !repository) throw new Error('Repository details are required.')
|
18
|
-
const repositoryName = gh(repository).name
|
19
|
-
logger?.write(chalk.cyan(`downloading ${repositoryName} to ${cwd}\t`))
|
20
|
-
tmp = (tmp || path.join(HOME_DIRECTORY, '.adapt', 'tmp', uuid
|
21
|
-
const downloadFileName = await new Promise((resolve, reject) => {
|
22
|
-
let downloadFileName = ''
|
23
|
-
const url = urljoin(repository, 'archive', branch + '.zip')
|
24
|
-
fetch(url, tmp, {
|
25
|
-
extract: true
|
26
|
-
})
|
27
|
-
.on('response', response => {
|
28
|
-
const disposition = response.headers['content-disposition']
|
29
|
-
if (disposition?.indexOf('attachment') === -1) return
|
30
|
-
const regex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
|
31
|
-
const matches = regex.exec(disposition)
|
32
|
-
if (!matches?.[1]) return
|
33
|
-
downloadFileName = matches[1].replace(/['"]/g, '')
|
34
|
-
})
|
35
|
-
.on('error', reject)
|
36
|
-
.then(() => resolve(downloadFileName))
|
37
|
-
})
|
38
|
-
const sourceFileName = downloadFileName
|
39
|
-
? path.parse(downloadFileName).name
|
40
|
-
: `${repositoryName}-${branch}`
|
41
|
-
const sourcePath = path.join(tmp, sourceFileName)
|
42
|
-
await fs.copy(sourcePath, cwd)
|
43
|
-
await fs.rm(tmp, { recursive: true })
|
44
|
-
logger?.log(' ', 'done!')
|
45
|
-
}
|
1
|
+
import chalk from 'chalk'
|
2
|
+
import { v4 as uuid } from 'uuid'
|
3
|
+
import fs from 'fs-extra'
|
4
|
+
import path from 'path'
|
5
|
+
import urljoin from 'url-join'
|
6
|
+
import fetch from 'download'
|
7
|
+
import { HOME_DIRECTORY } from './constants.js'
|
8
|
+
import gh from 'parse-github-url'
|
9
|
+
|
10
|
+
export default async function download ({
|
11
|
+
repository,
|
12
|
+
branch,
|
13
|
+
tmp,
|
14
|
+
cwd,
|
15
|
+
logger
|
16
|
+
} = {}) {
|
17
|
+
if (!branch && !repository) throw new Error('Repository details are required.')
|
18
|
+
const repositoryName = gh(repository).name
|
19
|
+
logger?.write(chalk.cyan(`downloading ${repositoryName} to ${cwd}\t`))
|
20
|
+
tmp = (tmp || path.join(HOME_DIRECTORY, '.adapt', 'tmp', uuid()))
|
21
|
+
const downloadFileName = await new Promise((resolve, reject) => {
|
22
|
+
let downloadFileName = ''
|
23
|
+
const url = urljoin(repository, 'archive', branch + '.zip')
|
24
|
+
fetch(url, tmp, {
|
25
|
+
extract: true
|
26
|
+
})
|
27
|
+
.on('response', response => {
|
28
|
+
const disposition = response.headers['content-disposition']
|
29
|
+
if (disposition?.indexOf('attachment') === -1) return
|
30
|
+
const regex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
|
31
|
+
const matches = regex.exec(disposition)
|
32
|
+
if (!matches?.[1]) return
|
33
|
+
downloadFileName = matches[1].replace(/['"]/g, '')
|
34
|
+
})
|
35
|
+
.on('error', reject)
|
36
|
+
.then(() => resolve(downloadFileName))
|
37
|
+
})
|
38
|
+
const sourceFileName = downloadFileName
|
39
|
+
? path.parse(downloadFileName).name
|
40
|
+
: `${repositoryName}-${branch}`
|
41
|
+
const sourcePath = path.join(tmp, sourceFileName)
|
42
|
+
await fs.copy(sourcePath, cwd)
|
43
|
+
await fs.rm(tmp, { recursive: true })
|
44
|
+
logger?.log(' ', 'done!')
|
45
|
+
}
|
package/lib/util/errors.js
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
export default {
|
2
|
-
ERROR_COURSE_DIR: {
|
3
|
-
code: 0,
|
4
|
-
message: 'Commands must be run in an Adapt project directory'
|
5
|
-
},
|
6
|
-
ERROR_INCOMPATIBLE_VALID_REQUEST: {
|
7
|
-
code: 1,
|
8
|
-
message: 'No compatible version exists (requested version is valid)'
|
9
|
-
},
|
10
|
-
ERROR_INCOMPATIBLE_BAD_REQUEST: {
|
11
|
-
code: 2,
|
12
|
-
message: 'No compatible version exists (requested version is invalid)'
|
13
|
-
},
|
14
|
-
ERROR_INCOMPATIBLE: {
|
15
|
-
code: 3,
|
16
|
-
message: 'No compatible version exists'
|
17
|
-
},
|
18
|
-
ERROR_COMPATIBLE_INC_REQUEST: {
|
19
|
-
code: 4,
|
20
|
-
message: 'Incompatible version requested (compatible version exists)'
|
21
|
-
},
|
22
|
-
ERROR_COMPATIBLE_BAD_REQUEST: {
|
23
|
-
code: 5,
|
24
|
-
message: 'Requested version is invalid'
|
25
|
-
},
|
26
|
-
ERROR_UNINSTALL: {
|
27
|
-
code: 6,
|
28
|
-
message: 'The plugin could not be uninstalled'
|
29
|
-
},
|
30
|
-
ERROR_NOT_FOUND: {
|
31
|
-
code: 7,
|
32
|
-
message: 'The plugin could not be found'
|
33
|
-
},
|
34
|
-
ERROR_NOTHING_TO_UPDATE: {
|
35
|
-
code: 8,
|
36
|
-
message: 'Could not resolve any plugins to update'
|
37
|
-
},
|
38
|
-
ERROR_UPDATE_INCOMPATIBLE: {
|
39
|
-
code: 9,
|
40
|
-
message: 'Incompatible update requested'
|
41
|
-
},
|
42
|
-
ERROR_INSTALL_ERROR: {
|
43
|
-
code: 10,
|
44
|
-
message: 'Unknown installation error'
|
45
|
-
},
|
46
|
-
ERROR_UPDATE_ERROR: {
|
47
|
-
code: 11,
|
48
|
-
message: 'Unknown update error'
|
49
|
-
},
|
50
|
-
ERROR_NO_RELEASES: {
|
51
|
-
code: 12,
|
52
|
-
message: 'No published releases'
|
53
|
-
},
|
54
|
-
ERROR_NO_UPDATE: {
|
55
|
-
code: 13,
|
56
|
-
message: 'No update available'
|
57
|
-
}
|
58
|
-
}
|
1
|
+
export default {
|
2
|
+
ERROR_COURSE_DIR: {
|
3
|
+
code: 0,
|
4
|
+
message: 'Commands must be run in an Adapt project directory'
|
5
|
+
},
|
6
|
+
ERROR_INCOMPATIBLE_VALID_REQUEST: {
|
7
|
+
code: 1,
|
8
|
+
message: 'No compatible version exists (requested version is valid)'
|
9
|
+
},
|
10
|
+
ERROR_INCOMPATIBLE_BAD_REQUEST: {
|
11
|
+
code: 2,
|
12
|
+
message: 'No compatible version exists (requested version is invalid)'
|
13
|
+
},
|
14
|
+
ERROR_INCOMPATIBLE: {
|
15
|
+
code: 3,
|
16
|
+
message: 'No compatible version exists'
|
17
|
+
},
|
18
|
+
ERROR_COMPATIBLE_INC_REQUEST: {
|
19
|
+
code: 4,
|
20
|
+
message: 'Incompatible version requested (compatible version exists)'
|
21
|
+
},
|
22
|
+
ERROR_COMPATIBLE_BAD_REQUEST: {
|
23
|
+
code: 5,
|
24
|
+
message: 'Requested version is invalid'
|
25
|
+
},
|
26
|
+
ERROR_UNINSTALL: {
|
27
|
+
code: 6,
|
28
|
+
message: 'The plugin could not be uninstalled'
|
29
|
+
},
|
30
|
+
ERROR_NOT_FOUND: {
|
31
|
+
code: 7,
|
32
|
+
message: 'The plugin could not be found'
|
33
|
+
},
|
34
|
+
ERROR_NOTHING_TO_UPDATE: {
|
35
|
+
code: 8,
|
36
|
+
message: 'Could not resolve any plugins to update'
|
37
|
+
},
|
38
|
+
ERROR_UPDATE_INCOMPATIBLE: {
|
39
|
+
code: 9,
|
40
|
+
message: 'Incompatible update requested'
|
41
|
+
},
|
42
|
+
ERROR_INSTALL_ERROR: {
|
43
|
+
code: 10,
|
44
|
+
message: 'Unknown installation error'
|
45
|
+
},
|
46
|
+
ERROR_UPDATE_ERROR: {
|
47
|
+
code: 11,
|
48
|
+
message: 'Unknown update error'
|
49
|
+
},
|
50
|
+
ERROR_NO_RELEASES: {
|
51
|
+
code: 12,
|
52
|
+
message: 'No published releases'
|
53
|
+
},
|
54
|
+
ERROR_NO_UPDATE: {
|
55
|
+
code: 13,
|
56
|
+
message: 'No update available'
|
57
|
+
}
|
58
|
+
}
|
package/lib/util/extract.js
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
import uuid from 'uuid'
|
2
|
-
import path from 'path'
|
3
|
-
import decompress from 'decompress'
|
4
|
-
import { HOME_DIRECTORY } from './constants.js'
|
5
|
-
|
6
|
-
export default async function extract ({
|
7
|
-
sourcePath,
|
8
|
-
cwd
|
9
|
-
} = {}) {
|
10
|
-
const rootPath = path.join(HOME_DIRECTORY, '.adapt', 'tmp', uuid
|
11
|
-
const files = await decompress(path.join(cwd, sourcePath), rootPath, {
|
12
|
-
filter: file => !file.path.endsWith('/')
|
13
|
-
})
|
14
|
-
const rootDirectories = Object.keys(files.reduce((memo, file) => { memo[file.path.split(/\\|\//g)[0]] = true; return memo }, {}))
|
15
|
-
let copyPath = rootPath
|
16
|
-
if (rootDirectories.length === 1) {
|
17
|
-
const rootDirectory = files[0].path.split(/\\|\//g)[0]
|
18
|
-
copyPath = path.join(rootPath, rootDirectory)
|
19
|
-
}
|
20
|
-
return {
|
21
|
-
rootPath,
|
22
|
-
copyPath
|
23
|
-
}
|
24
|
-
}
|
1
|
+
import { v4 as uuid } from 'uuid'
|
2
|
+
import path from 'path'
|
3
|
+
import decompress from 'decompress'
|
4
|
+
import { HOME_DIRECTORY } from './constants.js'
|
5
|
+
|
6
|
+
export default async function extract ({
|
7
|
+
sourcePath,
|
8
|
+
cwd
|
9
|
+
} = {}) {
|
10
|
+
const rootPath = path.join(HOME_DIRECTORY, '.adapt', 'tmp', uuid()).replace(/\\/g, '/')
|
11
|
+
const files = await decompress(path.join(cwd, sourcePath), rootPath, {
|
12
|
+
filter: file => !file.path.endsWith('/')
|
13
|
+
})
|
14
|
+
const rootDirectories = Object.keys(files.reduce((memo, file) => { memo[file.path.split(/\\|\//g)[0]] = true; return memo }, {}))
|
15
|
+
let copyPath = rootPath
|
16
|
+
if (rootDirectories.length === 1) {
|
17
|
+
const rootDirectory = files[0].path.split(/\\|\//g)[0]
|
18
|
+
copyPath = path.join(rootPath, rootDirectory)
|
19
|
+
}
|
20
|
+
return {
|
21
|
+
rootPath,
|
22
|
+
copyPath
|
23
|
+
}
|
24
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
export default function getDirNameFromImportMeta (importMeta) {
|
2
|
-
const __dirname = (process.platform === 'win32')
|
3
|
-
? new URL('.', importMeta.url).pathname.slice(1)
|
4
|
-
: new URL('.', import.meta.url).pathname
|
5
|
-
return __dirname
|
6
|
-
}
|
1
|
+
export default function getDirNameFromImportMeta (importMeta) {
|
2
|
+
const __dirname = (process.platform === 'win32')
|
3
|
+
? new URL('.', importMeta.url).pathname.slice(1)
|
4
|
+
: new URL('.', import.meta.url).pathname
|
5
|
+
return __dirname
|
6
|
+
}
|
package/lib/util/promises.js
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
import { eachOfLimit, eachOfSeries } from 'async'
|
2
|
-
/**
|
3
|
-
* Execute all promises in parallel, call progress at each promise to allow
|
4
|
-
* progress reporting
|
5
|
-
* @param {Array} array
|
6
|
-
* @param {function} iterator
|
7
|
-
* @param {function} progress
|
8
|
-
* @returns
|
9
|
-
*/
|
10
|
-
export async function eachOfLimitProgress (array, iterator, progress) {
|
11
|
-
let currentIndex = 0
|
12
|
-
progress(0)
|
13
|
-
await eachOfLimit(array, 8, async item => {
|
14
|
-
currentIndex++
|
15
|
-
progress(parseInt((currentIndex * 100) / array.length))
|
16
|
-
return iterator(item)
|
17
|
-
})
|
18
|
-
}
|
19
|
-
|
20
|
-
/**
|
21
|
-
* Execute iterator against each item in the array waiting for the iterator returned
|
22
|
-
* to finish before continuing, calling progress as each stage
|
23
|
-
* @param {Array} array
|
24
|
-
* @param {function} iterator
|
25
|
-
* @param {function} progress
|
26
|
-
* @returns
|
27
|
-
*/
|
28
|
-
export async function eachOfSeriesProgress (array, iterator, progress) {
|
29
|
-
let currentIndex = 0
|
30
|
-
progress(0)
|
31
|
-
await eachOfSeries(array, async item => {
|
32
|
-
currentIndex++
|
33
|
-
progress(parseInt((currentIndex * 100) / array.length))
|
34
|
-
return iterator(item)
|
35
|
-
})
|
36
|
-
}
|
1
|
+
import { eachOfLimit, eachOfSeries } from 'async'
|
2
|
+
/**
|
3
|
+
* Execute all promises in parallel, call progress at each promise to allow
|
4
|
+
* progress reporting
|
5
|
+
* @param {Array} array
|
6
|
+
* @param {function} iterator
|
7
|
+
* @param {function} progress
|
8
|
+
* @returns
|
9
|
+
*/
|
10
|
+
export async function eachOfLimitProgress (array, iterator, progress) {
|
11
|
+
let currentIndex = 0
|
12
|
+
progress(0)
|
13
|
+
await eachOfLimit(array, 8, async item => {
|
14
|
+
currentIndex++
|
15
|
+
progress(parseInt((currentIndex * 100) / array.length))
|
16
|
+
return iterator(item)
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Execute iterator against each item in the array waiting for the iterator returned
|
22
|
+
* to finish before continuing, calling progress as each stage
|
23
|
+
* @param {Array} array
|
24
|
+
* @param {function} iterator
|
25
|
+
* @param {function} progress
|
26
|
+
* @returns
|
27
|
+
*/
|
28
|
+
export async function eachOfSeriesProgress (array, iterator, progress) {
|
29
|
+
let currentIndex = 0
|
30
|
+
progress(0)
|
31
|
+
await eachOfSeries(array, async item => {
|
32
|
+
currentIndex++
|
33
|
+
progress(parseInt((currentIndex * 100) / array.length))
|
34
|
+
return iterator(item)
|
35
|
+
})
|
36
|
+
}
|