@ansstory/hias 1.0.0

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/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2025
4
+
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the “Software”), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # hias-cli
2
+ ```sh
3
+ npm i hias -g
4
+ hias -h
5
+ hias create xxx
6
+ hias adv Demo -d src/components
7
+ hias adr Demo -d src/components
8
+ hias adrt Demo -d src/components
9
+ hias adrd useDemoStore -d src/store/modules
10
+ hias adrdt useDemoStore -d src/store/modules
11
+ ```
package/lib/config.js ADDED
@@ -0,0 +1,14 @@
1
+ const foramworkUrl = {
2
+ 'vue-ts': 'https://gitee.com/AnsStory/as_cms_vue_ts_tmp.git',
3
+ 'uni-vite': 'https://gitee.com/AnsStory/uni_vite.git',
4
+ 'nuxt-web': 'https://gitee.com/AnsStory/nuxt_web_tmp.git',
5
+ 'vue-screen': 'https://gitee.com/AnsStory/vite_screen.git',
6
+ }
7
+ const framwork = Object.keys(foramworkUrl)
8
+
9
+ module.exports = {
10
+ // 可选择的框架
11
+ framwork,
12
+ // 框架对应的下载地址
13
+ foramworkUrl,
14
+ }
@@ -0,0 +1,58 @@
1
+ var inquirer = require('inquirer')
2
+ const { program } = require('commander')
3
+ var config = require('../config')
4
+ var downloadFun = require('./download')
5
+ const compileEjs = require('../utils/compile-ejs')
6
+ const writeFile = require('../utils/write-file')
7
+ const beginAction = async (project, args) => {
8
+ // 命令行的执行逻辑代码
9
+ // console.log(project);
10
+ // console.log(args);
11
+ const answer = await inquirer.prompt([
12
+ {
13
+ type: 'list',
14
+ name: 'framwork',
15
+ choices: config.framwork,
16
+ message: 'Please select the template.',
17
+ },
18
+ ])
19
+ // console.log(answer);
20
+ // 下载代码模板
21
+ downloadFun(config.foramworkUrl[answer.framwork], project)
22
+ }
23
+
24
+ async function addComponentAction(cpnName, temPath, fileType) {
25
+ const result = await compileEjs(temPath, {
26
+ name: cpnName,
27
+ lowername: cpnName.toLowerCase(),
28
+ })
29
+
30
+ const dest = program.opts().dest || 'src/components'
31
+ await writeFile(`${dest}/${cpnName}.${fileType}`, result)
32
+ console.log('Component creation was successful:', cpnName + '.vue')
33
+ }
34
+
35
+ async function addVueComponentAction(cpnName) {
36
+ await addComponentAction(cpnName, 'component.vue.ejs', 'vue')
37
+ }
38
+ async function addReactComponentAction(cpnName) {
39
+ await addComponentAction(cpnName, 'component.jsx.ejs', 'jsx')
40
+ }
41
+ async function addReactTsComponentAction(cpnName) {
42
+ await addComponentAction(cpnName, 'component.tsx.ejs', 'tsx')
43
+ }
44
+ async function addReduxStoreAction(cpnName) {
45
+ await addComponentAction(cpnName, 'reduxStore.jsx.ejs', 'jsx')
46
+ }
47
+ async function addReduxTsStoreAction(cpnName) {
48
+ await addComponentAction(cpnName, 'reduxTsStore.tsx.ejs', 'tsx')
49
+ }
50
+
51
+ module.exports = {
52
+ beginAction,
53
+ addVueComponentAction,
54
+ addReactComponentAction,
55
+ addReactTsComponentAction,
56
+ addReduxStoreAction,
57
+ addReduxTsStoreAction
58
+ }
@@ -0,0 +1,34 @@
1
+ const {
2
+ beginAction,
3
+ addVueComponentAction,
4
+ addReactComponentAction,
5
+ addReactTsComponentAction,
6
+ addReduxStoreAction,
7
+ addReduxTsStoreAction,
8
+ } = require('./action')
9
+
10
+ const beginCommander = function (program) {
11
+ program.command('create <project> [other...]').alias('crt').description('create project. For example: asn create airbnb').action(beginAction)
12
+ program
13
+ .command('adv <vuecpnname> [...others]')
14
+ .description('add vue component into a folder, For example: asn addv Demo -d src/components')
15
+ .action(addVueComponentAction)
16
+ program
17
+ .command('adr <reactcpnname> [...others]')
18
+ .description('add react jsx component into a folder, For example: asn addr Demo -d src/components')
19
+ .action(addReactComponentAction)
20
+ program
21
+ .command('adrt <reactcpnname> [...others]')
22
+ .description('add react tsx component into a folder, For example: asn addrt Demo -d src/components')
23
+ .action(addReactTsComponentAction)
24
+ program
25
+ .command('adrd <reactcpnname> [...others]')
26
+ .description('add redux jsx store into a folder, For example: asn addrt useDemoStore -d src/store/modules')
27
+ .action(addReduxStoreAction)
28
+ program
29
+ .command('adrdt <reactcpnname> [...others]')
30
+ .description('add redux tsx store into a folder, For example: asn addrt useDemoStore -d src/store/modules')
31
+ .action(addReduxTsStoreAction)
32
+ }
33
+
34
+ module.exports = beginCommander
@@ -0,0 +1,19 @@
1
+ const download = require('download-git-repo')
2
+ const ora = require('ora')
3
+ const chalk = require('chalk')
4
+ const downloadFun = function (url, project) {
5
+ const spinner = ora().start()
6
+ spinner.text = 'in progress...'
7
+ download('direct:' + url, project, { clone: true }, (err) => {
8
+ if (!err) {
9
+ spinner.succeed('succeed')
10
+ console.log(chalk.blue.bold('you run:'))
11
+ console.log(chalk.blue.bold('cd ' + project))
12
+ console.log(chalk.blue.bold('code .'))
13
+ } else {
14
+ spinner.fail(`error: ${err}`)
15
+ }
16
+ })
17
+ }
18
+
19
+ module.exports = downloadFun
@@ -0,0 +1,6 @@
1
+ const beginHelp = function (program) {
2
+ const version = require('../../package.json').version
3
+ program.version(version, '-v --version')
4
+ program.option('-d --dest <dest>', 'a destination folder, For example: -d src/components')
5
+ }
6
+ module.exports = beginHelp
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env node
2
+ const { program } = require('commander')
3
+ const beginHelp = require('./core/help')
4
+ const beginCommander = require('./core/commander')
5
+ beginHelp(program)
6
+ beginCommander(program)
7
+ program.parse(process.argv)
@@ -0,0 +1,11 @@
1
+ import React, { memo } from 'react'
2
+
3
+ const <%= name %> = memo(() => {
4
+ return (
5
+ <div>
6
+ <%= name %>
7
+ </div>
8
+ )
9
+ })
10
+
11
+ export default <%= name %>
@@ -0,0 +1,12 @@
1
+ import React, { memo } from "react"
2
+ import type { FC, ReactNode } from "react"
3
+
4
+ interface IProps {
5
+ children?: ReactNode
6
+ }
7
+
8
+ const <%= name %>: FC<IProps> = memo(() => {
9
+ return (<div> <%= name %> </div>)
10
+ })
11
+
12
+ export default <%= name %>
@@ -0,0 +1,13 @@
1
+ <script setup>
2
+
3
+ </script>
4
+
5
+ <template>
6
+ <div class="<%= lowername %>">
7
+ <%= name %>
8
+ </div>
9
+ </template>
10
+
11
+ <style lang="scss" scoped>
12
+ .<%=lowername %> {}
13
+ </style>
@@ -0,0 +1,16 @@
1
+ import { createSlice } from '@reduxjs/toolkit'
2
+
3
+ const <%= name %>SliceModule = createSlice({
4
+ name: '<%= name %>',
5
+ initialState:{
6
+ count: 100,
7
+ },
8
+ reducers: {
9
+ changeCountAction(state, { payload }) {
10
+ state.message = payload
11
+ },
12
+ },
13
+ })
14
+
15
+ export const { changeCountAction } = <%= name %>SliceModule.actions
16
+ export default <%= name %>SliceModule.reducer
@@ -0,0 +1,22 @@
1
+ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
2
+
3
+ interface IState {
4
+ count: number
5
+ }
6
+
7
+ const initialState: IState = {
8
+ count: 100,
9
+ }
10
+
11
+ const <%= name %>SliceModule = createSlice({
12
+ name: '<%= name %>',
13
+ initialState,
14
+ reducers: {
15
+ changeCountAction(state, { payload }: PayloadAction<number>) {
16
+ state.count = payload
17
+ },
18
+ },
19
+ })
20
+
21
+ export const { changeCountAction } = <%= name %>SliceModule.actions
22
+ export default <%= name %>SliceModule.reducer
@@ -0,0 +1,21 @@
1
+ const path = require('path')
2
+ const ejs = require('ejs')
3
+
4
+ function compileEjs(tempName, data) {
5
+ return new Promise((resolve, reject) => {
6
+ const tempPath = `../template/${tempName}`
7
+ const absolutePath = path.resolve(__dirname, tempPath)
8
+
9
+ ejs.renderFile(absolutePath, data, (err, result) => {
10
+ if (err) {
11
+ console.log('error:', err)
12
+ reject(err)
13
+ return
14
+ }
15
+
16
+ resolve(result)
17
+ })
18
+ })
19
+ }
20
+
21
+ module.exports = compileEjs
@@ -0,0 +1,10 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ async function writeFile(filePath, content) {
5
+ const dir = path.dirname(filePath)
6
+ await fs.promises.mkdir(dir, { recursive: true })
7
+ return fs.promises.writeFile(filePath, content)
8
+ }
9
+
10
+ module.exports = writeFile
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@ansstory/hias",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "创建项目模板",
6
+ "author": "AnsStory story <story0809@163.com>",
7
+ "main": "index.js",
8
+ "bin": {
9
+ "hias": "/lib/index.js"
10
+ },
11
+ "keywords": [
12
+ "hias ansstory"
13
+ ],
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "chalk": "^4.1.2",
20
+ "commander": "^14.0.0",
21
+ "download-git-repo": "^3.0.2",
22
+ "ejs": "^3.1.10",
23
+ "inquirer": "^8.2.6",
24
+ "ora": "^5.4.1"
25
+ }
26
+ }