New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mypaas/mp-cli

Package Overview
Dependencies
Maintainers
5
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mypaas/mp-cli - npm Package Compare versions

Comparing version 1.0.4 to 1.0.7

template/component/editors/index.js

103

lib/create.js

@@ -1,81 +0,58 @@

const ora = require('ora')
const path = require('path')
const fs = require('fs-extra')
const fes = require('fs-extra')
const chalk = require('chalk')
const validateName = require('../utils/validateName')
const getExactSource = require('../utils/getExactSource')
const releaseSource = require('../utils/releaseSource')
const { componentUrl, cachePath, packageUrl } = require('../utils/const')
const inquirer = require('inquirer')
const { validateName } = require('../utils/helper')
const downloadComponent = require('../utils/download-component')
const { overwriteOption, selectPathOption } = require('../utils/inquirer-options')
let spinner = {}
module.exports = async (componentName, options) => {
module.exports = async (componentName) => {
try {
const { componentPackage } = options
const packages = fs.readdirSync(path.join(process.cwd(), 'packages'))
if (componentPackage) {
const dir = path.resolve(process.cwd(), 'packages', componentName)
if (fs.existsSync(dir)) {
console.log()
console.log(chalk.red(`component ${chalk.cyan(componentName)} aleady exist.`))
console.log()
process.exit(1)
}
let packagePath
let realPackagePath
try {
const { app: { packages } } = require(path.join(process.cwd(), 'app.config.js'))
packagePath = Array.isArray(packages) ? packages.filter(item => !!item) : []
} catch (e) {
packagePath = []
}
const packagePathLength = packagePath.length
if (packagePathLength === 0) {
console.log(chalk.red('error: 请配置app.config.js里组件包路径packages字段'))
process.exit(1)
} else if (packagePathLength === 1) {
realPackagePath = packagePath[0]
} else {
if (!packages.length) {
console.log()
console.log(chalk.red(`No component package exist.`))
console.log(`You can run ${chalk.cyan('mp-cli create <packageName> -p')} to init.`)
console.log()
process.exit(1)
}
const pathList = packagePath.map(item => ({ name: item, value: item }))
const { selectPath } = await inquirer.prompt([selectPathOption(pathList)])
realPackagePath = selectPath
}
// 验证组件名称
validateName(componentName, 'component')
//下载组件模版
spinner = ora(`creating ${componentPackage ? 'package' : 'component'} ${componentName}`)
spinner.start()
await getExactSource(componentPackage ? packageUrl : componentUrl, cachePath)
await releaseSource('source')
const sourcePath = path.resolve(cachePath, 'source')
if (componentPackage) {
const targetPath = path.resolve(process.cwd(), 'packages', componentName)
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath)
} else {
fs.emptyDirSync(targetPath)
const targetPackage = path.resolve(process.cwd(), realPackagePath)
const editorDir = path.join(targetPackage, 'editors', componentName)
const runtimeDir = path.join(targetPackage, 'packages', componentName)
const isExist = fes.existsSync(editorDir) || fes.existsSync(runtimeDir)
if (isExist) {
const { action } = await inquirer.prompt([overwriteOption(componentName)])
if (!action) {
process.exit(1)
}
fs.copySync(sourcePath, targetPath)
const packageInfo = path.join(targetPath, 'package.json')
const meta = fs.readJSONSync(packageInfo)
meta.name = componentName
fs.writeJSONSync(packageInfo, meta, { spaces: 4 })
fs.removeSync(sourcePath)
} else {
const targetPackage = path.resolve(process.cwd(), 'packages', packages[0])
const editorDir = path.join(targetPackage, 'editors', componentName)
const runtimeDir = path.join(targetPackage, 'packages', componentName)
fs.ensureDirSync(editorDir)
fs.ensureDirSync(runtimeDir)
fs.copySync(path.join(sourcePath, 'editor'), editorDir)
fs.copySync(path.join(sourcePath, 'runtime'), runtimeDir)
const metaPath = path.join(targetPackage, 'packages', componentName, 'meta.json')
const meta = fs.readJSONSync(metaPath)
meta.name = componentName
fs.writeJSONSync(metaPath, meta, { spaces: 4 })
fs.removeSync(sourcePath)
if (action === 'overwrite') {
fes.removeSync(editorDir)
fes.removeSync(runtimeDir)
}
}
spinner.stop()
await downloadComponent(targetPackage, componentName)
console.log()
console.log(`Create component ${chalk.cyan(componentName)} success.`)
if (componentPackage) {
console.log(`You can check in dir ${chalk.cyan('packages')}.`)
}
console.log(`组件包${chalk.cyan(realPackagePath)} 创建组件 ${chalk.cyan(componentName)} 成功.`)
console.log()
} catch (error) {
console.log(error)
spinner.stop && spinner.stop()
process.exit(1)
}
}
const path = require('path')
const chalk = require('chalk')
const fs = require('fs-extra')
const inquirer = require('inquirer')
const { execSync } = require('child_process')
const switchVersion = require('./switch')
const { cachePath, privateRegistry } = require('../utils/const')
const validateName = require('../utils/validateName')
const downloadTemplate = require('../utils/downloadTemplate')
const chalk = require('chalk')
module.exports = async (projectName, options) => {
try {
const cwd = process.cwd()
const { validateName, getResourceByEngineVersion } = require('../utils/helper')
const downloadTemplate = require('../utils/download-template')
const { privateRegistry } = require('../utils/const')
const downloadComponent = require('../utils/download-component')
const allResourceVersion = require('../utils/resource-version')
const { overwriteOption, packageManagerOption, projectOption, projectNameOption, engineVersionOption } = require('../utils/inquirer-options')
const cwd = process.cwd()
const initResoursesVersion = async (newProject, engineVersion, projectName) => {
const emulatorVersion = getResourceByEngineVersion(allResourceVersion['emulator'], engineVersion)
const pageLayoutVersion = getResourceByEngineVersion(allResourceVersion['page-layout'], engineVersion)
const sdkVersion = getResourceByEngineVersion(allResourceVersion['sdk'], engineVersion)
const designSdkVersion = getResourceByEngineVersion(allResourceVersion['design-sdk'], engineVersion)
const packageJsonPath = newProject ? path.join(cwd, `${projectName}/package.json`) : path.join(cwd, 'package.json')
const emulatorPackageName = '@mypaas/mp-emulator'
const pageLayoutPackageName = '@mypaas/page-layout'
const sdkPackageName = '@mypaas/mp-sdk'
const designSdkPackageName = '@mypaas/mp-design-sdk'
const enginePackageName = '@mypaas/mp-engine'
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
const depName = newProject ? 'dependencies' : 'devDependencies'
packageJson[depName][emulatorPackageName] = emulatorVersion
packageJson[depName][pageLayoutPackageName] = pageLayoutVersion
packageJson[depName][sdkPackageName] = sdkVersion
packageJson[depName][designSdkPackageName] = designSdkVersion
packageJson[depName][enginePackageName] = engineVersion
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4))
}
module.exports = async () => {
const { newProject } = await inquirer.prompt([projectOption])
if (newProject) {
const { projectName } = await inquirer.prompt([projectNameOption])
const defaultTargetPackage = ['./packages/package-name']
const inCurrent = projectName === '.'
const name = inCurrent ? path.relative('../', cwd) : projectName
const targetDir = path.resolve(cwd, projectName || '.')
const isExist = fs.existsSync(targetDir)
// 创建缓存目录
if (!fs.existsSync(cachePath)) {
fs.mkdirSync(cachePath)
}
// 校验工程名称合法性
validateName(name, 'project')
// 前置工作
console.log(`npm config set registry ${privateRegistry}`)
execSync(`npm config set registry ${privateRegistry}`)
if (fs.existsSync(targetDir)) {
if (options.force) {
await fs.remove(targetDir)
} else {
if (inCurrent) {
const { ok } = await inquirer.prompt([
{
name: 'ok',
type: 'confirm',
message: `Generate project in current directory?`
}
])
if (!ok) {
return
}
} else {
const { action } = await inquirer.prompt([
{
name: 'action',
type: 'list',
message: `Target directory ${chalk.cyan(targetDir)} already exists. Pick an action:`,
choices: [
{ name: 'Overwrite', value: 'overwrite' },
{ name: 'Merge', value: 'merge' },
{ name: 'Cancel', value: false }
]
}
])
if (!action) {
return
} else if (action === 'overwrite') {
console.log(`\nRemoving ${chalk.cyan(targetDir)}...`)
await fs.remove(targetDir)
}
}
if (isExist) {
const { action } = await inquirer.prompt([overwriteOption(targetDir)])
if (!action) {
process.exit(1)
}
action === 'overwrite' && fs.remove(targetDir)
}
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir)
}
await downloadTemplate(targetDir)
// await switchVersion(null, null, targetDir, true)
// 引擎版本圈定并写入 package.json
const { engineVersion } = await inquirer.prompt([engineVersionOption])
// 安装依赖
const { packageManager } = await inquirer.prompt([
{
name: 'packageManager',
type: 'list',
message: `Pick the package manager to use when installing dependencies:`,
choices: [
{
name: 'Use Yarn (recommond)',
value: 'yarn',
short: 'Yarn'
},
{
name: 'Use NPM',
value: 'npm',
short: 'NPM'
},
{ name: 'Cancel', value: false }
]
}
])
// 下载依赖资源(模板等)
const { packageManager } = await inquirer.prompt([packageManagerOption])
await downloadTemplate(targetDir, defaultTargetPackage)
const targetPackage = path.join(targetDir, defaultTargetPackage[0])
await downloadComponent(targetPackage, 'demo')
console.log(`npm config set @mypaas:registry ${privateRegistry}`)
execSync(`npm config set @mypaas:registry ${privateRegistry}`)
initResoursesVersion(newProject, engineVersion, name)
if (!packageManager) {
console.log()
console.log('Success init Project.')
console.log()
console.log(`Later you can:`)
console.log(chalk.cyan(`cd ${name}`))
console.log(chalk.cyan('yarn (recommond to use)'))
console.log(chalk.cyan('yarn (recommend to use)'))
console.log()
} else {
execSync(`${packageManager}`, { cwd: path.resolve(process.cwd(), name), stdio: [0, 1, 2] })
// 执行 install
console.log(chalk.cyan('执行安装项目依赖,需要一会...'))
try {
execSync(`${packageManager}`, { cwd: path.resolve(process.cwd(), name), stdio: [0, 1, 2] })
} catch (error) {
}
}
} catch (error) {
console.log(error.message)
process.exit(1)
} else {
// 引擎版本圈定并写入 package.json
const { engineVersion } = await inquirer.prompt([engineVersionOption])
const defaultTargetPackage = []
const targetDir = path.resolve(cwd, '.')
const { packageManager } = await inquirer.prompt([packageManagerOption])
await downloadTemplate(targetDir, defaultTargetPackage, newProject)
console.log(`npm config set @mypaas:registry ${privateRegistry}`)
execSync(`npm config set @mypaas:registry ${privateRegistry}`)
initResoursesVersion(newProject, engineVersion)
if (!packageManager) {
console.log('Success init Project.')
console.log(`Later you can:`)
console.log(chalk.cyan('yarn (recommend to use)'))
console.log()
} else {
console.log(chalk.cyan('执行安装项目依赖,需要一会...'))
try {
execSync(`${packageManager}`, { stdio: [0, 1, 2] })
} catch (error) {
}
}
}
}
{
"name": "@mypaas/mp-cli",
"version": "1.0.4",
"description": "cli for mp developers",
"version": "1.0.7",
"description": "devtools",
"main": "index.js",
"directories": {
"lib": "lib"
},
"dependencies": {
"chalk": "^4.1.0",
"child_process": "^1.0.2",
"commander": "^7.1.0",
"cross-env": "^7.0.3",
"fs-extra": "^9.1.0",
"inquirer": "^8.0.0",
"mem-fs": "^1.2.0",
"mem-fs-editor": "^8.0.0",
"node-fetch": "^2.6.1",
"ora": "^5.4.0",
"semver": "^7.3.4",
"validate-npm-package-name": "^3.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitlab.mypaas.com.cn/paas-miniprogram/frontend/devtools.git"
},
"bin": {
"mp-cli": "bin/mp-cli"
},
"repository": {
"type": "git",
"url": "git@git.mysoft.com.cn:mic-paas/mp-cli.git"
},
"keywords": [
"mp-cli"
],
"author": "caok02",
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^4.0.0",
"commander": "^5.1.0",
"envinfo": "^7.5.1",
"fs-extra": "^9.0.0",
"inquirer": "^7.1.0",
"node-fetch": "^2.6.0",
"ora": "^4.0.4",
"semver": "^7.3.2",
"validate-npm-package-name": "^3.0.0"
},
"devDependencies": {
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"prettier": "^2.0.5"
},
"engines": {

@@ -39,0 +37,0 @@ "node": ">=8.0.0"

@@ -1,15 +0,19 @@

# MP Devtools
# Devtools
# 开发工具
mp-cli
init——初始化项目
开发工具
create——创建组件包
## 安装
```shell
# 使用 npm 全局安装 CLI
$ npm install -g @mypaas/mp-cli
# OR 使用 yarn 全局安装 CLI
$ yarn global add @mypaas/mp-cli
```
change——更改依赖源
## 命令
- mp-cli init ——初始化项目
- mp-cli create ——创建组件包
- mp-cli start ——启动项目
info——查看当前环境
mp-cli --help 查看命名
clean——清除一些文件夹(默认清除node_modules)
mp-cli --help 查看命名
const path = require('path')
exports.engineUrl = version => `https://paas-dist.oss-cn-hangzhou.aliyuncs.com/prod/engine-cache/mobile/${version}/source.tar.gz`
exports.templateUrl = 'https://mp-resource-internal.oss-cn-hangzhou.aliyuncs.com/local/cli-template/project-template.tar.gz'
exports.templateUrl = 'https://mp-resource-internal.oss-cn-hangzhou.aliyuncs.com/local/cli-template/p-project.tar.gz'
exports.packageUrl = 'https://mp-resource-internal.oss-cn-hangzhou.aliyuncs.com/local/cli-template/package-template.tar.gz'
exports.componentUrl = 'https://mp-resource-internal.oss-cn-hangzhou.aliyuncs.com/local/cli-template/component-template.tar.gz'
exports.componentUrl = 'https://mp-resource-internal.oss-cn-hangzhou.aliyuncs.com/local/cli-template/p-component.tar.gz'
let homeDir = process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME']
if (!homeDir) {
homeDir = process.env.HOMEPATH
homeDir = process.env.HOMEPATH
}

@@ -12,0 +11,0 @@ exports.cachePath = path.resolve(`${homeDir}`, '.paascache')

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc