API 浏览器
应用扩展卸载 API

本页引用 src/uninstall.js 文件,该文件在应用扩展卸载时执行。并非所有应用扩展都需要卸载 - 这是一个可选步骤。

¥This page refers to src/uninstall.js file which is executed when the App Extension is uninstalled. Not all App Extensions will need an uninstall – this is an optional step.

文件基本结构示例:

¥Example of basic structure of the file:

// can be async
export default function (api) {
  // props and methods for "api" Object
  // are described below
}

api.engine(api.engine)

包含正在使用的 Quasar CLI 引擎(以字符串形式)。示例:@quasar/app-vite@quasar/app-webpack

¥Contains the Quasar CLI engine (as String) being used. Examples: @quasar/app-vite or @quasar/app-webpack.

api.hasVite(api.hasVite)

布尔值 - 是否在 @quasar/app-vite 上运行。

¥Boolean - is running on @quasar/app-vite or not.

api.hasWebpack(api.hasWebpack)

布尔值 - 是否在 @quasar/app-webpack 上运行。

¥Boolean - is running on @quasar/app-webpack or not.

api.extId(api.extId)

包含此应用扩展的 ext-id(字符串)。

¥Contains the ext-id (String) of this App Extension.

api.prompts(api.prompts)

是一个对象,其中包含此应用扩展安装时提示的答案。更多提示信息,请查看 提示 API

¥Is an Object which has the answers to the prompts when this App Extension gets installed. For more info on prompts, check out Prompts API.

api.resolve(api.resolve)

解析此应用扩展程序正在运行的应用内的路径。无需导入 path 并自行解析路径。

¥Resolves paths within the app on which this App Extension is running. Eliminates the need to import path and resolve the paths yourself.

// resolves to root of app
api.resolve.app('src/my-file.js')

// resolves to root/src of app
api.resolve.src('my-file.js')

// resolves to root/public of app
// (@quasar/app-webpack v3.4+ or @quasar/app-vite v1+)
api.resolve.public('my-image.png')

// resolves to root/src-pwa of app
api.resolve.pwa('some-file.js')

// resolves to root/src-ssr of app
api.resolve.ssr('some-file.js')

// resolves to root/src-cordova of app
api.resolve.cordova('config.xml')

// resolves to root/src-electron of app
api.resolve.electron('some-file.js')

// resolves to root/src-bex of app
api.resolve.bex('some-file.js')

api.appDir(api.appDir)

包含运行此应用扩展程序的应用根目录的完整路径(字符串)。

¥Contains the full path (String) to the root of the app on which this App Extension is running.

api.hasTypescript
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
(api.hasTypescript
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
)

/**

 * @return {Promise<boolean>} host project has Typescript active or not
 */
await api.hasTypescript()

api.hasLint
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
(api.hasLint
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
)

/**

 * @return {Promise<boolean>} host project has ESLint or not
 */
await api.hasLint()

api.getStorePackageName
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
(api.getStorePackageName
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
)

/**

 * @return {Promise<string|undefined>} 'pinia' | 'vuex' | undefined
 */
await api.getStorePackageName()

api.getNodePackagerName
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
(api.getNodePackagerName
@quasar/app-vite 1.6+
@quasar/app-webpack 3.11+
)

/**

 * @return {Promise<'npm' | 'yarn' | 'pnpm' | 'bun'>}
 */
await api.getNodePackagerName()

api.hasPackage(api.hasPackage)

通过语义版本条件确定主机应用中是否安装了某些软件包。

¥Determine if some package is installed in the host app through a semver condition.

语义版本条件示例:'1.x || >=2.5.0 || 5.0.0 - 7.2.3'

¥Example of semver condition: '1.x || >=2.5.0 || 5.0.0 - 7.2.3'.

/**

 * @param {string} packageName

 * @param {string} (optional) semverCondition

 * @return {boolean} package is installed and meets optional semver condition
 */
if (api.hasPackage('vuelidate')) {
  // hey, this app has it (any version of it)
}
if (api.hasPackage('quasar', '^2.0.0')) {
  // hey, this app has Quasar UI v2 installed
}

api.hasExtension(api.hasExtension)

检查是否安装了其他应用扩展。

¥Check if another app extension is installed.

/**

 * Check if another app extension is installed

 *  * @param {string} extId

 * @return {boolean} has the extension installed.
 */
if (api.hasExtension(extId)) {
  // hey, we have it
}

api.getPackageVersion(api.getPackageVersion)

获取宿主应用包的版本。

¥Get the version of a host app package.

/**

 * @param {string} packageName

 * @return {string|undefined} version of app's package
 */
console.log( api.getPackageVersion(packageName) )
// output examples:
//   1.1.3
//   undefined (when package not found)

api.removePath(api.removePath)

从应用项目文件夹中移除文件或文件夹(应用扩展程序已安装且不再需要该文件或文件夹)。

¥Removes a file or folder from the app project folder (which the App Extension has installed and is no longer needed).

注意并注意不要删除会破坏开发者应用的文件。

¥Be mindful about it and do not delete the files that would break developer’s app.

文件或文件夹的路径需要相对于项目的根文件夹。

¥The path to file or folder needs to be relative to project’s root folder.

/**

  * @param {string} __path
  */
api.removePath('my-folder')

以上示例从应用的根目录中删除 “my-folder”。

¥The above example deletes “my-folder” from the root of the app.

api.getPersistentConf(api.getPersistentConf)

获取此扩展程序的内部持久化配置。如果没有对象,则返回空对象。

¥Get the internal persistent config of this extension. Returns empty object if it has none.

/**

 * @return {object} cfg
 */
api.getPersistentConf()

api.onExitLog(api.onExitLog)

在 App CLI 完成应用扩展卸载并即将退出后,添加一条打印消息。可以多次调用以注册多个退出日志。

¥Adds a message to be printed after App CLI finishes up uninstalling the App Extension and is about to exit. Can be called multiple times to register multiple exit logs.

/**

 * @param {string} msg
 */
api.onExitLog('Thanks for having used my extension')