create-packer 1.13.1 → 1.13.3

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.
@@ -1,5 +1,5 @@
1
- export interface tempInfoType {
2
- name: string;
3
- src: string;
4
- }
5
- export declare function createTemp(dirname: string): Promise<void>;
1
+ export interface tempInfoType {
2
+ name: string;
3
+ src: string;
4
+ }
5
+ export declare function createTemp(dirname: string): Promise<void>;
@@ -1,58 +1,58 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTemp = void 0;
4
- const inquirer = require("inquirer");
5
- const fsExtra = require("fs-extra");
6
- const path = require("path");
7
- const fs = require("fs");
8
- const chalk = require("chalk");
9
- const ora = require("ora");
10
- const child_process_1 = require("child_process");
11
- const utils_1 = require("../utils");
12
- const cwd = process.cwd();
13
- const command = utils_1.onGenCommand();
14
- const excludes = ['node_modules', 'yarn-error.log', 'dist'];
15
- const tempRoot = path.join(__dirname, '../../template');
16
- const tempInfo = utils_1.onGetDir(tempRoot).map(name => {
17
- return {
18
- name,
19
- src: path.join(tempRoot, name)
20
- };
21
- });
22
- function copyTempFile(tempPath, output) {
23
- fsExtra.readdirSync(tempPath).map(name => {
24
- if (!excludes.includes(name)) {
25
- fsExtra.copySync(path.join(tempPath, name), path.join(output, name));
26
- }
27
- });
28
- }
29
- function createTempEnd(output) {
30
- child_process_1.spawnSync(command, ['install'], {
31
- cwd: output,
32
- stdio: 'inherit'
33
- });
34
- }
35
- async function createTemp(dirname) {
36
- const isCurrent = dirname === '.';
37
- const { temp } = await inquirer.prompt([
38
- {
39
- type: 'list',
40
- name: 'temp',
41
- message: 'Select temp.',
42
- choices: tempInfo.map(o => o.name)
43
- }
44
- ]);
45
- const creating = ora(chalk.yellow('Creating...\n')).start();
46
- const output = path.join(cwd, isCurrent ? '' : dirname);
47
- if (!isCurrent && fs.existsSync(output)) {
48
- return console.log(chalk.red(`${dirname} already exists!`));
49
- }
50
- if (!isCurrent) {
51
- fsExtra.mkdirSync(output);
52
- }
53
- const tempPath = path.join(tempRoot, temp);
54
- copyTempFile(tempPath, output);
55
- createTempEnd(output);
56
- creating.succeed();
57
- }
58
- exports.createTemp = createTemp;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTemp = void 0;
4
+ const inquirer = require("inquirer");
5
+ const fsExtra = require("fs-extra");
6
+ const path = require("path");
7
+ const fs = require("fs");
8
+ const chalk = require("chalk");
9
+ const ora = require("ora");
10
+ const child_process_1 = require("child_process");
11
+ const utils_1 = require("../utils");
12
+ const cwd = process.cwd();
13
+ const command = utils_1.onGenCommand();
14
+ const excludes = ['node_modules', 'yarn-error.log', 'dist'];
15
+ const tempRoot = path.join(__dirname, '../../template');
16
+ const tempInfo = utils_1.onGetDir(tempRoot).map(name => {
17
+ return {
18
+ name,
19
+ src: path.join(tempRoot, name)
20
+ };
21
+ });
22
+ function copyTempFile(tempPath, output) {
23
+ fsExtra.readdirSync(tempPath).map(name => {
24
+ if (!excludes.includes(name)) {
25
+ fsExtra.copySync(path.join(tempPath, name), path.join(output, name));
26
+ }
27
+ });
28
+ }
29
+ function createTempEnd(output) {
30
+ child_process_1.spawnSync(command, ['install'], {
31
+ cwd: output,
32
+ stdio: 'inherit'
33
+ });
34
+ }
35
+ async function createTemp(dirname) {
36
+ const isCurrent = dirname === '.';
37
+ const { temp } = await inquirer.prompt([
38
+ {
39
+ type: 'list',
40
+ name: 'temp',
41
+ message: 'Select temp.',
42
+ choices: tempInfo.map(o => o.name)
43
+ }
44
+ ]);
45
+ const creating = ora(chalk.yellow('Creating...\n')).start();
46
+ const output = path.join(cwd, isCurrent ? '' : dirname);
47
+ if (!isCurrent && fs.existsSync(output)) {
48
+ return console.log(chalk.red(`${dirname} already exists!`));
49
+ }
50
+ if (!isCurrent) {
51
+ fsExtra.mkdirSync(output);
52
+ }
53
+ const tempPath = path.join(tempRoot, temp);
54
+ copyTempFile(tempPath, output);
55
+ createTempEnd(output);
56
+ creating.succeed();
57
+ }
58
+ exports.createTemp = createTemp;
package/bin/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/index.js CHANGED
@@ -1,10 +1,10 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const createTemp_1 = require("./clis/createTemp");
5
- const commander_1 = require("commander");
6
- commander_1.program
7
- .option('-c, --create <dirname>', 'Create project.', dirname => {
8
- return createTemp_1.createTemp(dirname);
9
- })
10
- .parse(process.argv);
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const createTemp_1 = require("./clis/createTemp");
5
+ const commander_1 = require("commander");
6
+ commander_1.program
7
+ .option('-c, --create <dirname>', 'Create project.', dirname => {
8
+ return createTemp_1.createTemp(dirname);
9
+ })
10
+ .parse(process.argv);
@@ -1,4 +1,4 @@
1
- export declare function hasPnpm(): boolean;
2
- export declare function hasYarn(): boolean;
3
- export declare function onGenCommand(): "pnpm" | "yarn" | "npm";
4
- export declare function onGetDir(root: string): string[];
1
+ export declare function hasPnpm(): boolean;
2
+ export declare function hasYarn(): boolean;
3
+ export declare function onGenCommand(): "pnpm" | "yarn" | "npm";
4
+ export declare function onGetDir(root: string): string[];
@@ -1,45 +1,45 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onGetDir = exports.onGenCommand = exports.hasYarn = exports.hasPnpm = void 0;
4
- const child_process_1 = require("child_process");
5
- const fs_1 = require("fs");
6
- function hasPnpm() {
7
- try {
8
- child_process_1.execSync('pnpm --version');
9
- return true;
10
- }
11
- catch {
12
- return false;
13
- }
14
- }
15
- exports.hasPnpm = hasPnpm;
16
- function hasYarn() {
17
- try {
18
- child_process_1.execSync('yarnpkg --version');
19
- return true;
20
- }
21
- catch {
22
- return false;
23
- }
24
- }
25
- exports.hasYarn = hasYarn;
26
- function onGenCommand() {
27
- if (hasPnpm()) {
28
- return 'pnpm';
29
- }
30
- if (hasYarn()) {
31
- return 'yarn';
32
- }
33
- return 'npm';
34
- }
35
- exports.onGenCommand = onGenCommand;
36
- function onGetDir(root) {
37
- const dirs = [];
38
- fs_1.readdirSync(root, { withFileTypes: true }).forEach(o => {
39
- if (o.isDirectory()) {
40
- dirs.push(o.name);
41
- }
42
- });
43
- return dirs;
44
- }
45
- exports.onGetDir = onGetDir;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onGetDir = exports.onGenCommand = exports.hasYarn = exports.hasPnpm = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const fs_1 = require("fs");
6
+ function hasPnpm() {
7
+ try {
8
+ child_process_1.execSync('pnpm --version');
9
+ return true;
10
+ }
11
+ catch {
12
+ return false;
13
+ }
14
+ }
15
+ exports.hasPnpm = hasPnpm;
16
+ function hasYarn() {
17
+ try {
18
+ child_process_1.execSync('yarnpkg --version');
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ exports.hasYarn = hasYarn;
26
+ function onGenCommand() {
27
+ if (hasPnpm()) {
28
+ return 'pnpm';
29
+ }
30
+ if (hasYarn()) {
31
+ return 'yarn';
32
+ }
33
+ return 'npm';
34
+ }
35
+ exports.onGenCommand = onGenCommand;
36
+ function onGetDir(root) {
37
+ const dirs = [];
38
+ fs_1.readdirSync(root, { withFileTypes: true }).forEach(o => {
39
+ if (o.isDirectory()) {
40
+ dirs.push(o.name);
41
+ }
42
+ });
43
+ return dirs;
44
+ }
45
+ exports.onGetDir = onGetDir;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -2,8 +2,18 @@
2
2
  "root": true,
3
3
  "parser": "@typescript-eslint/parser",
4
4
  "plugins": ["@typescript-eslint", "prettier"],
5
- "extends": ["eslint:recommended", "plugin:react/recommended", "plugin:react-hooks/recommended"],
5
+ "extends": [
6
+ "eslint:recommended",
7
+ "plugin:react/recommended",
8
+ "plugin:react-hooks/recommended",
9
+ "plugin:import/recommended",
10
+ "plugin:import/typescript"
11
+ ],
6
12
  "settings": {
13
+ "import/resolver": {
14
+ "typescript": true,
15
+ "node": true
16
+ },
7
17
  "react": {
8
18
  "version": "18"
9
19
  }
@@ -23,6 +33,21 @@
23
33
  "useJSXTextNode": true
24
34
  },
25
35
  "rules": {
36
+ "import/order": [
37
+ "error",
38
+ {
39
+ "groups": [
40
+ "builtin",
41
+ "external",
42
+ "internal",
43
+ "parent",
44
+ "sibling",
45
+ "index",
46
+ "object",
47
+ "type"
48
+ ]
49
+ }
50
+ ],
26
51
  "@typescript-eslint/no-var-requires": 0,
27
52
  "@typescript-eslint/explicit-function-return-type": "off",
28
53
  "@typescript-eslint/no-explicit-any": 0,
@@ -48,6 +48,8 @@
48
48
  "commitizen": "4.3.0",
49
49
  "cssnano": "5.1.14",
50
50
  "eslint": "8.34.0",
51
+ "eslint-import-resolver-typescript": "^3.5.3",
52
+ "eslint-plugin-import": "^2.27.5",
51
53
  "eslint-plugin-prettier": "4.2.1",
52
54
  "eslint-plugin-react": "7.32.2",
53
55
  "eslint-plugin-react-hooks": "4.6.0",
@@ -0,0 +1 @@
1
+ export { default as useVisible } from './useVisible'
@@ -2,11 +2,12 @@ import { useState } from 'react'
2
2
  import { isFunction } from 'lodash-es'
3
3
 
4
4
  export interface useVisibleConfigType {
5
+ defaultVisible?: boolean
5
6
  onBeforeShow?: () => Promise<boolean | void>
6
7
  onBeforeHide?: () => Promise<boolean | void>
7
8
  }
8
9
  export default function useVisible(config?: useVisibleConfigType) {
9
- const [visible, setVisible] = useState(false)
10
+ const [visible, setVisible] = useState(config?.defaultVisible ?? false)
10
11
  const onShow = async () => {
11
12
  let isShow: boolean | void = true
12
13
  if (isFunction(config?.onBeforeShow)) {
@@ -1,3 +1,2 @@
1
1
  export * from './defineStore'
2
- export { default as useVisible } from './useVisible'
3
2
  export { default as request } from './request'
@@ -16,8 +16,16 @@
16
16
  "extends": [
17
17
  "eslint:recommended",
18
18
  "plugin:@typescript-eslint/recommended",
19
- "plugin:vue/vue3-recommended"
19
+ "plugin:vue/vue3-recommended",
20
+ "plugin:import/recommended",
21
+ "plugin:import/typescript"
20
22
  ],
23
+ "settings": {
24
+ "import/resolver": {
25
+ "typescript": true,
26
+ "node": true
27
+ }
28
+ },
21
29
  "parser": "vue-eslint-parser",
22
30
  "parserOptions": {
23
31
  "parser": "@typescript-eslint/parser",
@@ -27,6 +35,21 @@
27
35
  }
28
36
  },
29
37
  "rules": {
38
+ "import/order": [
39
+ "error",
40
+ {
41
+ "groups": [
42
+ "builtin",
43
+ "external",
44
+ "internal",
45
+ "parent",
46
+ "sibling",
47
+ "index",
48
+ "object",
49
+ "type"
50
+ ]
51
+ }
52
+ ],
30
53
  "@typescript-eslint/no-var-requires": 0,
31
54
  "@typescript-eslint/explicit-function-return-type": "off",
32
55
  "@typescript-eslint/no-explicit-any": 0,
@@ -35,6 +35,8 @@
35
35
  "commitizen": "4.3.0",
36
36
  "cssnano": "5.1.14",
37
37
  "eslint": "8.34.0",
38
+ "eslint-import-resolver-typescript": "^3.5.3",
39
+ "eslint-plugin-import": "^2.27.5",
38
40
  "eslint-plugin-prettier": "4.2.1",
39
41
  "eslint-plugin-vue": "9.9.0",
40
42
  "husky": "8.0.3",
@@ -0,0 +1,2 @@
1
+ export { default as useVisible } from './useVisible'
2
+ export { default as useList } from './useList'
@@ -0,0 +1,107 @@
1
+ import { ref, reactive, computed, unref } from 'vue'
2
+ import { cloneDeep, concat, assign, pick, isNil, size, map } from 'lodash-es'
3
+
4
+ export interface stateType<ListItem, P> {
5
+ loading: boolean
6
+ total: number
7
+ params: P
8
+ list: ListItem[]
9
+ sum: Record<string, any>
10
+ selected: any[]
11
+ pagination: {
12
+ current: number
13
+ pageSize: number
14
+ total: number
15
+ }
16
+ selectedLen: number
17
+ }
18
+ export interface createListStorePropsType<ListItem, P> {
19
+ /**
20
+ * @description 默认请求参数
21
+ */
22
+ defaultParams: P
23
+ /** 列表请求 */
24
+ fetch: (
25
+ state: Pick<stateType<ListItem, P>, 'pagination' | 'selected' | 'total' | 'params'>
26
+ ) => Promise<{
27
+ list: any[]
28
+ page?: number
29
+ pageSize?: number
30
+ total?: number
31
+ sum?: Record<string, any>
32
+ }>
33
+ /** 初始化列表时的配置 */
34
+ initConfig?: {
35
+ /** 初始化的时候需要保留值的字段 */
36
+ keepParamsKeys?: Array<keyof P>
37
+ }
38
+ }
39
+
40
+ export default function createListStore<
41
+ ListItem extends Record<string, any>,
42
+ P extends { page?: number; pageSize?: number; [key: string]: any }
43
+ >(config: createListStorePropsType<ListItem, P>) {
44
+ const loading = ref<stateType<ListItem, P>['loading']>(true)
45
+ const total = ref<stateType<ListItem, P>['total']>(0)
46
+ const params = reactive<stateType<ListItem, P>['params']>(cloneDeep(config.defaultParams))
47
+ const list = ref<stateType<ListItem, P>['list']>([])
48
+ const sum = reactive<stateType<ListItem, P>['sum']>({})
49
+ const selected = ref<stateType<ListItem, P>['selected']>([])
50
+ const pagination = computed<stateType<ListItem, P>['pagination']>(() => ({
51
+ current: params.page || 0,
52
+ pageSize: params.pageSize || 0,
53
+ total: total.value
54
+ }))
55
+ const selectedLen = computed<stateType<ListItem, P>['selectedLen']>(() => size(selected.value))
56
+ function resetParams() {
57
+ assign(params, cloneDeep(config.defaultParams))
58
+ }
59
+ async function fetchList(arg?: { params?: Partial<P>; isConcat?: boolean; isInit?: boolean }) {
60
+ loading.value = true
61
+ try {
62
+ if (arg?.isInit) {
63
+ assign(
64
+ params,
65
+ cloneDeep(config.defaultParams),
66
+ pick(params, config?.initConfig?.keepParamsKeys || [])
67
+ )
68
+ }
69
+ assign(params, arg?.params)
70
+ const result = await config.fetch({
71
+ pagination: unref(pagination),
72
+ selected: unref(selected),
73
+ total: unref(total),
74
+ params
75
+ })
76
+ const newData = map(result.list, (item: any) => ({
77
+ ...item,
78
+ __active__: {
79
+ campaign: false,
80
+ adGroup: false,
81
+ target: false,
82
+ searchTerm: false
83
+ }
84
+ }))
85
+ list.value = !isNil(result.page) && arg?.isConcat ? concat(list, newData) : newData
86
+ sum.value = result.sum || {}
87
+ total.value = result.total || total.value
88
+ params.page = result.page || params.page
89
+ params.pageSize = result.pageSize || params.pageSize
90
+ } finally {
91
+ loading.value = false
92
+ }
93
+ }
94
+
95
+ return {
96
+ loading,
97
+ total,
98
+ params,
99
+ list,
100
+ sum,
101
+ selected,
102
+ pagination,
103
+ selectedLen,
104
+ resetParams,
105
+ fetchList
106
+ }
107
+ }
@@ -1,4 +1,3 @@
1
1
  export { default as app } from './app'
2
- export { default as useVisible } from './useVisible'
3
2
  export { default as createApiComponent } from './createApiComponent'
4
3
  export { default as request } from './request'