Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 0d3dbe8

Browse files
committed
[core] don't write store.json while the module isn't suitable for the core
1 parent 3d6d1d2 commit 0d3dbe8

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

lib/cli.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ let coreConfigurations = {
7373
next_version: '',
7474
local: '',
7575
last_update_time: '',
76-
updateTimes: 7
76+
update_time: 7
7777
}
7878

7979
// check the node version
@@ -274,7 +274,8 @@ const prepare = async (command, config) => {
274274
is_next: true,
275275
next_version: '',
276276
local: path.join(config.coreRoot, 'node_modules', coreName),
277-
last_update_time: (new Date()).getTime()
277+
last_update_time: (new Date()).getTime(),
278+
update_time: 7
278279
}
279280
}
280281
try {

packages/@weex/core/src/cli/cli.ts

+50-16
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@ export interface CoreOptions {
8787

8888
export default class Cli {
8989
private cli: any
90+
private updateTime: number
9091
private rawArgv: string[] | string
9192
private argv: IParameters
9293
private plugins: PluginItem[] = []
9394
private cliConfiguration: CliConfiguration
9495
constructor(data: CliConfiguration, options: CoreOptions = {}) {
9596
debug('Init Cli instance on <%s>', __filename)
96-
9797
this.rawArgv = data.argv
9898

99+
this.updateTime = data.configs.update_time || 7
100+
99101
this.argv = parseParams(data.argv)
100102

101103
this.cliConfiguration = data
@@ -167,8 +169,13 @@ export default class Cli {
167169
})
168170
for (let i = 0; i < packages.length; i++) {
169171
const commandBasePath = path.join(packages[i].root, 'commands')
172+
const extensionBasePath = path.join(packages[i].root, 'extensions')
170173
const commandFiles: string[] = fs.list(commandBasePath) || []
171174
commands = []
175+
// continue next package while the package has not commands and extensions folder
176+
if (!fs.existsAsync(commandBasePath) && !fs.existsAsync(extensionBasePath)) {
177+
continue
178+
}
172179
commandFiles.forEach(file => {
173180
let content: Command = {}
174181
try {
@@ -217,18 +224,34 @@ export default class Cli {
217224
} else {
218225
// check if there has some module need to be upgraded
219226
// check last_update_time
220-
const info: any = await updateNpmPackageInfo(this.cliConfiguration.modules, this.cliConfiguration.registry)
227+
const info: any = await updateNpmPackageInfo(this.cliConfiguration.modules, this.cliConfiguration.registry, this.updateTime)
221228
if (info) {
222229
let upgradeList = {}
223230
for (let mod in info.mods) {
224231
if (!info.mods[mod].is_next) {
225232
upgradeList[mod] = info.mods[mod]
226233
}
227234
}
228-
let lists = Object.keys(upgradeList)
235+
const generateChangelog = (changelog: any[] | string): string => {
236+
if (!changelog) {
237+
return ''
238+
}
239+
if (typeof changelog === 'string') {
240+
changelog = [changelog]
241+
}
242+
changelog = changelog.map(log => `\n • ${log}`)
243+
return `\n changelog:${changelog.join('')}`
244+
}
245+
246+
let lists = Object.keys(upgradeList).map(key => {
247+
return {
248+
name: `${key} ${logger.colors.grey(`${upgradeList[key].version} -> ${upgradeList[key].next_version}${generateChangelog(upgradeList[key].changelog)}`)}`,
249+
value: key
250+
}
251+
})
229252
let yes = 'Yes, update all'
230253
let no = 'No, next time'
231-
let choices = [yes, no, new inquirer.Separator('Or choose update package')].concat(Object.keys(upgradeList))
254+
let choices = [yes, no, new inquirer.Separator('Or choose update package')].concat(lists)
232255
if (lists.length > 0) {
233256
let res = await inquirer.prompt({
234257
name: 'choose',
@@ -418,24 +441,35 @@ export async function updateNpmPackageInfo(modules: ModData, registry: string, t
418441
return false
419442
}
420443
logger.info(`Time: ${formateTime(date)}, verify if there is an update`)
421-
const spinner = logger.spin('Checking ... please wait')
422444
for (let mod in modData.mods) {
423-
spinner.text = `Checking ${mod} ...`
424-
let res = await getNpmPackageLatestVersion(mod, registry)
445+
let spinner = logger.spin(`Checking ${mod} ... ${logger.colors.grey('this may take a few seconds')}`)
446+
spinner.text = ``
447+
let res = await getLatestNpmPackageInfo(mod, registry)
425448
if (!res.error) {
426-
spinner.succeed(`Finished checking [${mod}]`)
449+
spinner.stopAndPersist({
450+
symbol: `${logger.colors.green(`[${logger.checkmark}]`)}`,
451+
text: `sync module [${mod}]`
452+
})
427453
if (semver.gt(res.latest, modData.mods[mod].version)) {
428454
modData.mods[mod].is_next = false
429455
modData.mods[mod].next_version = res.latest
456+
modData.mods[mod].changelog = res.package.changelog || ''
430457
} else {
431458
modData.mods[mod].is_next = true
432459
modData.mods[mod].next_version = res.latest
460+
modData.mods[mod].changelog = res.package.changelog || ''
433461
}
434462
} else {
435463
if (res.error === ErrorType.PACKAGE_NOT_FOUND) {
436-
spinner.fail(`Package [${mod}] not found on registry ${registry}`)
464+
spinner.stopAndPersist({
465+
symbol: `${logger.colors.red(`[${logger.xmark}]`)}`,
466+
text: `Package [${mod}] not found on registry ${registry}`
467+
})
437468
} else {
438-
spinner.fail(`Unkonw error with checking [${mod}], ${res.error}`)
469+
spinner.stopAndPersist({
470+
symbol: `${logger.colors.red(`[${logger.xmark}]`)}`,
471+
text: `Unkonw error with checking [${mod}], ${res.error}`
472+
})
439473
}
440474
}
441475
}
@@ -450,20 +484,21 @@ export async function updateNpmPackageInfo(modules: ModData, registry: string, t
450484
* @param registry npm registry
451485
* @returns {error?:string, latest?:string}
452486
*/
453-
export async function getNpmPackageLatestVersion(name: string, registry: string) {
487+
export async function getLatestNpmPackageInfo(name: string, registry: string) {
454488
const npmApi = http.create({
455489
baseURL: `${registry}`,
456490
})
457-
const res: any = await npmApi.get(`${name}`)
491+
const res: any = await npmApi.get(`${name}/latest`)
458492
let error
459493
if (res.data.error) {
460494
if (/not_found/.test(res.data.error)) {
461495
error = ErrorType.PACKAGE_NOT_FOUND
462496
}
463-
} else if (res.data['dist-tags']['latest']) {
464-
const latest = res.data['dist-tags']['latest']
497+
} else if (res.data['version']) {
498+
const latest = res.data['version']
465499
return {
466500
latest: latest,
501+
package: res.data
467502
}
468503
} else {
469504
error = `can't found ${name} latest version`
@@ -481,6 +516,7 @@ export async function getNpmPackageLatestVersion(name: string, registry: string)
481516
* @param options data from error stack
482517
*/
483518
export async function analyzer(type: string, stack: any, options?: any) {
519+
logger.log('\n')
484520
if (type === 'repair') {
485521
if (ErrorType.PACKAGE_NOT_FOUND === stack) {
486522
const innerMods = ['@weex-cli/debug', '@weex-cli/generator', '@weex-cli/build', '@weex-cli/preview', '@weex-cli/run', '@weex-cli/doctor', '@weex-cli/lint', '@weex-cli/device']
@@ -538,8 +574,6 @@ export async function analyzer(type: string, stack: any, options?: any) {
538574
logger.log(logger.colors.grey(`\nLooking for related issues on:`))
539575
logger.log('https://github.com/weexteam/weex-toolkit/issues?q=is%3Aclosed')
540576
}
541-
console.log('\n\n\n\n\n')
542-
console.log(type, stack, options)
543577
}
544578

545579
export function formateTime(date: Date) {

packages/@weex/core/src/cli/commands/install.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export default {
88
alias: ['update', 'i'],
99
description: 'Install weex plugin for Weex Cli',
1010
hidden: false,
11-
run: async toolbox => {
12-
const { parameters, fs, logger } = toolbox
11+
run: async ({
12+
parameters,
13+
fs,
14+
logger
15+
}) => {
1316
const globalConfiguration: CliConfiguration = parameters.options.__config
1417
const packagename = parameters.first
1518
const moduleConfigFilePath = path.join(globalConfiguration.moduleRoot, globalConfiguration.moduleConfigFileName)
@@ -53,7 +56,14 @@ export default {
5356
let type = ModType.EXTENSION
5457
for (let i = 0; i < packages.length; i++) {
5558
const commandBasePath = path.join(packages[i].root, 'commands')
59+
const extensionBasePath = path.join(packages[i].root, 'extensions')
5660
const commandFiles: string[] = fs.list(commandBasePath) || []
61+
// continue next package while the package has not commands and extensions folder
62+
if (!fs.exists(commandBasePath) && !fs.exists(extensionBasePath)) {
63+
logger.log(`The module ${logger.colors.yellow(packages[i].package.name)} was not suitable for the weex core`)
64+
logger.log('Please check the spelling')
65+
return
66+
}
5767
commandFiles.forEach(file => {
5868
let content
5969
try {
@@ -73,6 +83,7 @@ export default {
7383
if (commands.length > 0) {
7484
globalConfiguration.modules.mods[packages[i].package.name] = {
7585
type: type,
86+
description: packages[i].package.description,
7687
version: packages[i].package.version,
7788
dependencies: packages[i].package.pluginDependencies,
7889
next_version: '',
@@ -84,6 +95,7 @@ export default {
8495
} else {
8596
globalConfiguration.modules.mods[packages[i].package.name] = {
8697
type: type,
98+
description: packages[i].package.description,
8799
version: packages[i].package.version,
88100
dependencies: packages[i].package.pluginDependencies,
89101
next_version: '',

0 commit comments

Comments
 (0)