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

component-cli

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

component-cli - npm Package Compare versions

Comparing version 0.0.1 to 0.1.1

build/common/co-config.js

9

bin/index.js
#!/usr/bin/env node
console.log('', __dirname)
console.log('Hello, world!')
console.log('', process.execPath)
console.log('', process.cwd())
// console.log('', __dirname)
// console.log('Hello, world!')
// console.log('', process.execPath)
require('../index')

@@ -6,22 +6,21 @@ require('colors')

const rimraf = require('rimraf')
const utils = require('./common/utils')
const path = require('path')
const fs = require('fs-extra')
const promptHist = require('./common/prompt-component-history')
const prompt = require('prompt-sync')()
const makeNpmJson = require('./common/npm-packagejson')
const coconfig = require('./common/co-config')
const buildDemo = require('./demo.js')
const componentName =
(
prompt(`component name(${promptHist.setting.name || '...'}):`) || ''
).trim() || promptHist.setting.name
const isSingle = coconfig.setting.single
if (!componentName) {
console.log('请输入组件名'.red)
return
}
const name = utils.inputName()
if (!name) return
const srcPath = path.join(__dirname, '../src', componentName)
const distPath = path.join(__dirname, '../dist', componentName)
const demoPath = path.join(__dirname, '../demo', componentName)
const projPaths = require('./common/project-paths')(name)
const srcPath = projPaths.src
const distPath = projPaths.dist
const demoPath = projPaths.demoDist
if (!fs.existsSync(srcPath)) {

@@ -32,23 +31,24 @@ console.log(`找不到路径 ${srcPath}`.red)

if (!fs.existsSync(path.join(srcPath, 'component.json'))) {
if (!fs.existsSync(projPaths.jsonSrc)) {
console.log(`找不到组件配置文件 component.json`.red)
return
}
promptHist.save({
name: componentName
coconfig.save({
name
})
const componentConfig = require(path.join(srcPath, 'component.json'))
rimraf(demoPath, {}, () => {})
rimraf(distPath, {}, () => {})
console.log(`正在构建项目 ${componentName}`)
webpack(BuildConf(componentName), function(err, stats) {
webpack(BuildConf(name), function(err, stats) {
console.log(stats)
if (!err) {
console.log(`成功构建项目 ${componentName}!`.green)
console.log(`正在构建Demo ${componentName}`)
fs.copySync(path.join(srcPath, 'types'), path.join(distPath, 'types'))
webpack(demoConf(componentName), function(err, stats) {
console.log(`成功构建项目 ${name}!`.green)
fs.copySync(projPaths.typesSrc, projPaths.typesDist)
fs.copyFileSync(projPaths.readmeSrc, projPaths.readmeDist)
makeNpmJson(projPaths)
webpack(demoConf(name), function(err, stats) {
if (!err) {
console.log(`成功构建Demo ${componentName}!`.green)
buildDemo.bulidReadme(componentName)
console.log(`成功构建Demo ${name}!`.green)
buildDemo.bulidReadme(name, isSingle)
} else {

@@ -55,0 +55,0 @@ throw err

const path = require('path')
const fs = require('fs-extra')
const coconfig = require('./co-config')
const prompt = require('prompt-sync')()
module.exports = {
inputName() {
const isSingle = coconfig.setting.single
let componentName = coconfig.setting.name
if (!isSingle) {
componentName =
(
prompt(
`component name: (${coconfig.setting.name || '...'}) `
) || ''
).trim() || coconfig.setting.name
if (!componentName) {
console.log('请输入组件名'.red)
return
}
}
return componentName
},
fileReplace(filePath, obj) {

@@ -6,0 +27,0 @@ const readme = fs.readFileSync(filePath, 'utf8')

require('colors')
const path = require('path')
const fs = require('fs-extra')
const shell = require('shelljs')
const prompt = require('prompt-sync')()
const argv = require('yargs').argv
const utils = require('./common/utils')
const prompt = require('prompt-sync')()
const promptHist = require('./common/prompt-component-history')
const coconfig = require('./common/co-config')
const basePath = process.cwd()
if (coconfig.setting.name && coconfig.setting.single) {
console.error('单组件项目不可重复创建组件'.red)
return
}
const isSingle = !(argv.m || argv.multiple)
const name = (prompt('component name:') || '').trim()

@@ -14,4 +23,6 @@ if (!name) {

const srcPath = path.resolve(__dirname, '../src', name)
const projPaths = require('./common/project-paths')(name, isSingle)
const srcPath = projPaths.src
if (fs.existsSync(srcPath)) {

@@ -22,12 +33,21 @@ console.error(`已存在同名组件 ${srcPath}, 请给组件一个新名字`.red)

const desc = (prompt('description:') || '').trim()
let scope = (
prompt(
`scope: ${
coconfig.setting.scope ? '(' + coconfig.setting.scope + ')' : ''
}`
) || ''
).trim()
if (!scope) {
scope = coconfig.setting.scope || ''
}
let desc = (prompt('description:') || '').trim()
if (!desc) {
console.error('请输入组件描述'.red)
return
desc = ''
}
let version = (prompt("version(like '1.1.1 or 1.1'):") || '').trim()
let version = (prompt('version: (0.1 or 0.1.0) ') || '').trim()
if (!version) {
console.error('请输入务必输入组件名、描述、版本号'.red)
return
version = '0.1'
}

@@ -38,2 +58,3 @@ if (!utils.version.valid(version)) {

}
version = utils.version.trim(version)

@@ -43,15 +64,54 @@

name,
scopeName: '@' + scope + '/' + name,
desc,
scope,
version
}
;(async () => {
await fs.copySync(path.resolve(__dirname, './template'), srcPath)
utils.fileReplace(path.resolve(srcPath, 'component.json'), info)
utils.fileReplace(path.resolve(srcPath, 'README.md'), info)
utils.fileReplace(path.resolve(srcPath, 'types/index.d.ts'), info)
await fs.copySync(
path.resolve(__dirname, 'template/demo'),
projPaths.demoSrc
)
await fs.copySync(path.resolve(__dirname, 'template/test'), projPaths.test)
await fs.copySync(
path.resolve(__dirname, 'template/types'),
projPaths.typesSrc
)
await fs.copySync(
path.resolve(__dirname, 'template/component.json'),
projPaths.jsonSrc
)
await fs.copySync(
path.resolve(__dirname, 'template/index.js'),
projPaths.indexJs
)
await fs.copySync(
path.resolve(__dirname, 'template/index.vue'),
projPaths.indexVue
)
await fs.copySync(
path.resolve(__dirname, 'template/README.md'),
projPaths.readmeSrc
)
await fs.copySync(
path.resolve(__dirname, 'template/types'),
projPaths.typesSrc
)
utils.fileReplace(projPaths.jsonSrc, info)
utils.fileReplace(projPaths.readmeSrc, info)
utils.fileReplace(path.resolve(projPaths.typesSrc, 'index.d.ts'), info)
if (coconfig.isNewProject) {
shell.cd(projPaths.root)
const { code, stderr, stdout } = shell.exec('npm install')
}
console.log('组件创建成功!'.green)
})()
promptHist.save({
coconfig.save({
name,
desc
scope,
single: isSingle
})

@@ -6,8 +6,12 @@ require('colors')

const fs = require('fs')
const basePath = process.cwd()
module.exports = {
bulidReadme(componentName) {
const srcPath = path.join(__dirname, '../src', componentName)
const distPath = path.join(__dirname, '../dist', componentName)
const demoPath = path.join(__dirname, '../demo', componentName)
bulidReadme(componentName, isSingle) {
const projPaths = require('./common/project-paths')(componentName)
const srcPath = projPaths.src
const distPath = projPaths.dist
const demoPath = projPaths.demoDist
const indexHtml = fs.readFileSync(

@@ -17,5 +21,3 @@ path.join(demoPath, 'index.html'),

) // 读取index.html内容
const readme = marked(
fs.readFileSync(path.join(srcPath, 'README.md'), 'utf8')
) // 将README.md转为html
const readme = marked(fs.readFileSync(projPaths.readmeSrc, 'utf8')) // 将README.md转为html
// fs.outputFileSync(path.join(demoPath, 'index.html'), indexHtml.replace('</html>', (readme + '</html>')))

@@ -28,8 +30,14 @@ fs.writeFile(

console.log('readme转换成功!'.green)
this.buildDemoList()
if (!isSingle) {
this.buildDemoList(componentName, isSingle)
}
}
)
},
buildDemoList() {
const demoPath = path.join(__dirname, '../demo')
buildDemoList(componentName, isSingle) {
const demoPath = path.join(
basePath,
'./demo',
isSingle ? '' : componentName
)
const demoArr = fs.readdirSync(demoPath)

@@ -36,0 +44,0 @@ const demoList = fs.readdirSync(demoPath).filter((file) => {

@@ -7,7 +7,8 @@ require('colors')

const prompt = require('prompt-sync')()
const promptHist = require('./common/prompt-component-history')
const coconfig = require('./common/co-config')
const makeNpmJson = require('./common/npm-packagejson')
console.log('------------------------------------------------------'.yellow)
console.log(`请确保您已经登录私有npm http://npm.tumax.we.com`)
console.log(
`登录:npm login --registry=http://npm.tumax.we.com --scope=@admin-commons`
`登录:npm login --registry=http://npm.tumax.we.com --scope=@your scope`
)

@@ -17,13 +18,10 @@ console.log(`注册:npm adduser --registry=http://npm.tumax.we.com`)

const name =
(
prompt(`component name(${promptHist.setting.name || '...'}):`) || ''
).trim() || promptHist.setting.name
if (!name) {
console.error('请输入组件名'.red)
return
}
const name = utils.inputName()
if (!name) return
const srcPath = path.resolve(__dirname, '../src', name)
const projPaths = require('./common/project-paths')(name)
const srcPath = projPaths.src
const distPath = projPaths.dist
if (!fs.existsSync(srcPath)) {

@@ -34,48 +32,6 @@ console.error(`组件 ${name} 不存在`.red)

const componentConfig = require(path.join(srcPath, 'component.json'))
const preVersion = componentConfig.version
makeNpmJson(projPaths, true)
let version = (prompt(`version(${preVersion}):`) || '').trim()
if (!version) {
console.error('请输入要发布的版本号'.red)
return
}
version = utils.version.trim(version)
if (
utils.version.lt(version, preVersion) ||
utils.version.eq(version, preVersion)
) {
console.error(`请输入大于 ${preVersion} 的版本号`.red)
return
}
componentConfig.version = version
const distPath = path.join(__dirname, '../dist', name)
if (!fs.existsSync(distPath)) {
console.error(`请先 'yarn build' 构建组件`.red)
return
}
const packageJson = { ...componentConfig }
delete packageJson.extract
delete packageJson.externals
delete packageJson.sourceMap
packageJson.main = name + '.min.js'
fs.outputJsonSync(path.resolve(distPath, 'package.json'), packageJson, {
encoding: 'utf8'
})
fs.copyFileSync(
path.resolve(srcPath, 'README.md'),
path.resolve(distPath, 'README.md')
)
/// shell
shell.cd(path.resolve(__dirname, '../dist/' + name))
shell.cd(projPaths.dist)

@@ -95,11 +51,3 @@ console.log((shell.cat('./package.json') || '').yellow)

console.log('发布成功!'.green)
const comJson = fs.readFileSync(
path.join(srcPath, 'component.json'),
'utf8'
)
fs.outputFileSync(
path.join(srcPath, 'component.json'),
comJson.replace(preVersion, version)
)
}
promptHist.save({ name })
coconfig.save({ name })
{
"version": "$version$",
"name": "@admin-commons/$name$",
"scope": "$scope$",
"name": "$name$",
"description": "$desc$",

@@ -15,4 +16,6 @@ "extract": true,

},
"dependencies": {},
"dependencies": {
"vue": "^2.5.15"
},
"peerDependencies": {}
}

@@ -1,2 +0,2 @@

# @admin-commons/$name$
# $scopeName$

@@ -3,0 +3,0 @@ ## v$version$

@@ -8,3 +8,3 @@ require('color')

const promptHist = require('./common/prompt-component-history')
const coconfig = require('./common/co-config')
const prompt = require('prompt-sync')()

@@ -14,4 +14,4 @@

(
prompt(`component name(${promptHist.setting.name || '...'}):`) || ''
).trim() || promptHist.setting.name
prompt(`component name: (${coconfig.setting.name || '...'}) `) || ''
).trim() || coconfig.setting.name

@@ -29,3 +29,3 @@ if (!componentName) {

}
promptHist.save({
coconfig.save({
name: componentName

@@ -32,0 +32,0 @@ })

var path = require('path')
var vueLoaderConfig = require('../common/vue-loader.conf')
const coconfig = require('../common/co-config')
const basePath = process.cwd()
module.exports = {
context: basePath,
resolve: {

@@ -9,6 +12,17 @@ extensions: ['.js', '.vue', '.json'],

vue$: 'vue/dist/vue.esm.js'
}
},
modules: [
path.join(basePath, 'node_modules'),
path.join(__dirname, '../../node_modules')
]
},
resolveLoader: {
modules: [
path.join(basePath, 'node_modules'),
path.join(__dirname, '../../node_modules')
]
},
module: {
rules: [{
rules: [
{
test: /\.(json)$/,

@@ -15,0 +29,0 @@ loader: 'json'

@@ -7,8 +7,8 @@ const utils = require('../common/webpack-utils')

const path = require('path')
module.exports = (componentName) => {
const srcPath = path.join(__dirname, '../../src', componentName)
const distPath = path.join(__dirname, '../../dist', componentName)
const projPaths = require('../common/project-paths')(componentName)
const srcPath = projPaths.src
const distPath = projPaths.dist
let componentConfig = require(path.join(srcPath, 'component.json'))
let componentConfig = projPaths.jsonSrc

@@ -35,2 +35,3 @@ componentConfig = Object.assign(

console.log(srcPath, '---', distPath)
return merge(baseWebpackConfig, {

@@ -49,4 +50,6 @@ mode: 'production',

publicPath: '',
filename: `${componentName}.min.js`,
library: componentName,
filename: `index.js`,
library: componentConfig.scope
? '@' + componentConfig.scope + '/' + componentName
: componentName,
libraryTarget: 'umd',

@@ -59,3 +62,3 @@ umdNamedDefine: true

new MiniCssExtractPlugin({
filename: `${componentName}.min.css`
filename: `index.css`
}),

@@ -62,0 +65,0 @@ new OptimizeCSSPlugin()

@@ -12,13 +12,9 @@ const rimraf = require('rimraf')

module.exports = (componentName) => {
const srcPath = path.join(__dirname, '../../src', componentName)
const distPath = path.join(__dirname, '../../dist', componentName)
const demoPath = path.join(__dirname, '../../demo', componentName)
const projPaths = require('../common/project-paths')(componentName)
const srcPath = projPaths.src
const distPath = projPaths.dist
const demoPath = projPaths.demoDist
let templatePath = path.join(__dirname, '../common/demo-tpl.html')
if (fs.existsSync(path.join(srcPath, 'demo.html'))) {
templatePath = path.join(srcPath, 'demo.html')
}
const entry = { index: path.join(srcPath, 'demo/index.js') },
const entry = { index: path.join(projPaths.demoSrc, 'index.js') },
plugins = [

@@ -36,4 +32,4 @@ new HtmlWebpackPlugin({

]
const css = path.join(distPath, `${componentName}.min.css`)
const css = path.join(distPath, `index.css`)
const js = path.join(distPath, `index.js`)
return merge(baseWebpackConf, {

@@ -43,6 +39,3 @@ entry,

alias: {
CurrentComponent: path.join(
distPath,
`${componentName}.min.js`
),
CurrentComponent: js,
'CurrentComponent-css': fs.existsSync(css)

@@ -49,0 +42,0 @@ ? css

const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const utils = require('../common/webpack-utils')
const wUtils = require('../common/webpack-utils')
const merge = require('webpack-merge')
const webpack = require('webpack')
const baseWebpackConf = require('./base')
const prompt = require('prompt-sync')()
const promptHist = require('../common/prompt-component-history')
const path = require('path')
const fs = require('fs')
const componentName =
(
prompt(`component name(${promptHist.setting.name || '...'}):`) || ''
).trim() || promptHist.setting.name
if (!componentName) {
console.error('请输入组件名'.red)
return
}
module.exports = function(componentName) {
const projPaths = require('../common/project-paths')(componentName)
const srcPath = projPaths.src
const demoPath = projPaths.demoDist
const srcPath = path.join(__dirname, '../../src', componentName)
const demoPath = path.join(__dirname, '../../demo', componentName)
let templatePath = path.join(__dirname, '../common/demo-tpl.html')
let templatePath = path.join(__dirname, '../common/demo-tpl.html')
if (!fs.existsSync(srcPath)) {
throw `找不到路径 ${srcPath}`
return merge(baseWebpackConf, {
entry: {
index: [
'webpack-dev-server/client?http://localhost:3333/',
path.join(projPaths.demoSrc, 'index.js')
]
},
resolve: {
alias: {
CurrentComponent: path.join(srcPath, 'index.js'),
'CurrentComponent-css': path.join(
__dirname,
'../common/placeholder.css'
)
}
},
module: {
rules: wUtils.styleLoaders({
sourceMap: true,
extract: true
})
},
output: {
path: demoPath,
filename: '[name].js'
},
devtool: '#source-map',
watch: true,
mode: 'development',
devServer: {
contentBase: demoPath,
host: 'localhost',
port: 3333,
open: true
},
plugins: [
new HtmlWebpackPlugin({
title: componentName,
cache: false,
filename: `index.html`,
inject: 'body',
template: templatePath
}),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new webpack.HotModuleReplacementPlugin()
]
})
}
if (!fs.existsSync(path.join(srcPath, 'component.json'))) {
throw `找不到组件配置文件 component.json`
}
if (fs.existsSync(path.join(srcPath, 'demo.html'))) {
templatePath = path.join(srcPath, 'demo.html')
}
const componentConfig = require(path.join(srcPath, 'component.json')),
entry = { index: path.join(srcPath, 'demo/index.js') },
plugins = [
new HtmlWebpackPlugin({
title: componentName,
cache: false,
filename: `index.html`,
inject: 'body',
template: templatePath
}),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new webpack.HotModuleReplacementPlugin()
]
console.log('开发模式构建项目:' + componentName)
promptHist.save({ name: componentName })
module.exports = merge(baseWebpackConf, {
entry,
resolve: {
alias: {
CurrentComponent: path.join(srcPath, 'index.js'),
'CurrentComponent-css': path.join(
__dirname,
'../common/placeholder.css'
)
}
},
module: {
rules: utils.styleLoaders({
sourceMap: true,
extract: true
})
},
output: {
path: demoPath,
filename: '[name].js'
},
devtool: '#source-map',
watch: true,
mode: 'development',
devServer: {
contentBase: demoPath,
host: 'localhost',
port: 3333,
open: true
},
plugins
})
{
"name": "component-cli",
"version": "0.0.1",
"version": "0.1.1",
"description": "A command-line tool for creating components",
"scripts": {
"dev": "webpack-dev-server --inline --hot --config build/webpack-conf/dev.js"
},
"bin": {

@@ -14,3 +17,59 @@ "co": "bin/index.js"

"author": "steven chen <522702986@qq.com>",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"autoprefixer": "^6.7.2",
"babel-core": "^6.26.3",
"babel-eslint": "^7.1.1",
"babel-loader": "^7.1.4",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-stage-2": "^6.22.0",
"babel-runtime": "^6.26.0",
"clean-webpack-plugin": "^0.1.19",
"colors": "^1.3.2",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.11",
"eslint": "^3.19.0",
"eslint-config-standard": "^6.2.1",
"eslint-friendly-formatter": "^2.0.7",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^2.0.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^1.1.11",
"fs-extra": "^7.0.0",
"glob": "^7.1.2",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.0.6",
"karma": "^3.1.1",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.2",
"less": "^3.0.1",
"less-loader": "^4.1.0",
"marked": "^0.5.1",
"mini-css-extract-plugin": "^0.4.3",
"node-sass": "^4.7.2",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"prompt-sync": "^4.1.6",
"prompt-sync-history": "^1.0.1",
"rimraf": "^2.6.2",
"sass-loader": "^6.0.7",
"shelljs": "^0.8.2",
"style-loader": "^0.20.3",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"uglifyjs-webpack-plugin": "^1.2.5",
"url-loader": "^1.0.1",
"vue-html-loader": "^1.2.4",
"vue-loader": "^14.2.3",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.15",
"webpack": "4.20.2",
"webpack-cli": "3.1.1",
"webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.0",
"yargs": "^11.0.0"
}
}

@@ -1,8 +0,18 @@

# To Develop ...
# component-cli
## A command-line tool for creating components
## 本地安装
`npm install . -g`
## 远程安装
`npm install component-cli -g`
## 命令
- `co build`
- `co dev`
- `co add`
- `co publish`
- `co c`
- `co b`
- `co d`
- `co p`
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