bod 5.17.0 → 5.19.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/dist/commands/CreateCommand.d.ts +7 -1
- package/dist/commands/CreateCommand.js +81 -20
- package/dist/commands/__tests__/CreateCommand.test.js +25 -11
- package/dist/utils/__tests__/index.test.js +15 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +16 -1
- package/package.json +2 -2
|
@@ -4,16 +4,22 @@ interface Action {
|
|
|
4
4
|
value: string;
|
|
5
5
|
command: string;
|
|
6
6
|
args: string[];
|
|
7
|
+
postCommands: {
|
|
8
|
+
command: string;
|
|
9
|
+
args: string[];
|
|
10
|
+
}[];
|
|
7
11
|
}
|
|
8
12
|
declare class CreateCommand extends BaseCommand {
|
|
9
13
|
static readonly TemplateActions: Action[];
|
|
10
14
|
private command;
|
|
11
15
|
private commandArgs;
|
|
16
|
+
private postCommands;
|
|
12
17
|
constructor();
|
|
13
|
-
run(appName: string): Promise<void>;
|
|
18
|
+
run(appName: string, additionalOptions?: string[]): Promise<void>;
|
|
14
19
|
getCommand(): string;
|
|
15
20
|
getCommandArgs(): string[];
|
|
16
21
|
private processTemplateAction;
|
|
22
|
+
private resolvePackageManager;
|
|
17
23
|
private resolveAppPath;
|
|
18
24
|
private execute;
|
|
19
25
|
}
|
|
@@ -10,14 +10,16 @@ class CreateCommand extends BaseCommand_1.default {
|
|
|
10
10
|
description: 'Create a new project powered by @sabertazimi/react-scripts',
|
|
11
11
|
usage: 'create <appName>',
|
|
12
12
|
});
|
|
13
|
-
this.command = '
|
|
13
|
+
this.command = 'npm';
|
|
14
14
|
this.commandArgs = [];
|
|
15
|
+
this.postCommands = [];
|
|
16
|
+
this.resolvePackageManager();
|
|
15
17
|
}
|
|
16
|
-
run(
|
|
17
|
-
return tslib_1.__awaiter(this,
|
|
18
|
+
run(appName_1) {
|
|
19
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (appName, additionalOptions = []) {
|
|
18
20
|
yield this.processTemplateAction();
|
|
19
21
|
this.resolveAppPath(appName);
|
|
20
|
-
this.execute();
|
|
22
|
+
this.execute(additionalOptions);
|
|
21
23
|
});
|
|
22
24
|
}
|
|
23
25
|
getCommand() {
|
|
@@ -36,69 +38,128 @@ class CreateCommand extends BaseCommand_1.default {
|
|
|
36
38
|
choices: [...CreateCommand.TemplateActions],
|
|
37
39
|
},
|
|
38
40
|
]);
|
|
39
|
-
const { command, args } = CreateCommand.TemplateActions.find(({ value }) => value === templateName);
|
|
41
|
+
const { command, args, postCommands } = CreateCommand.TemplateActions.find(({ value }) => value === templateName);
|
|
40
42
|
this.command = command;
|
|
41
43
|
this.commandArgs = [...args];
|
|
44
|
+
this.postCommands = postCommands;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
resolvePackageManager() {
|
|
48
|
+
const packageManager = (0, utils_1.findPackageManager)();
|
|
49
|
+
CreateCommand.TemplateActions.forEach((action) => {
|
|
50
|
+
if (action.command === 'npm')
|
|
51
|
+
action.command = packageManager;
|
|
42
52
|
});
|
|
43
53
|
}
|
|
44
54
|
resolveAppPath(appName) {
|
|
45
55
|
this.commandArgs.push(appName);
|
|
56
|
+
CreateCommand.TemplateActions.forEach(({ postCommands }) => {
|
|
57
|
+
for (const postCommand of postCommands) {
|
|
58
|
+
postCommand.args = postCommand.args.map((arg) => {
|
|
59
|
+
return arg.replace('appPath', appName);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
46
63
|
}
|
|
47
|
-
execute() {
|
|
48
|
-
const proc = utils_1.spawn.sync(this.command, this.commandArgs, {
|
|
64
|
+
execute(additionalOptions) {
|
|
65
|
+
const proc = utils_1.spawn.sync(this.command, [...this.commandArgs, ...additionalOptions], {
|
|
49
66
|
stdio: 'inherit',
|
|
50
67
|
});
|
|
51
68
|
if (proc.status !== 0) {
|
|
52
69
|
throw new Error(`\n\`${this.command} ${this.commandArgs.join(' ')}\` exited.`);
|
|
53
70
|
}
|
|
71
|
+
this.postCommands.forEach((postCommand) => {
|
|
72
|
+
const proc = utils_1.spawn.sync(postCommand.command, postCommand.args, {
|
|
73
|
+
stdio: 'inherit',
|
|
74
|
+
});
|
|
75
|
+
if (proc.status !== 0) {
|
|
76
|
+
throw new Error(`\n\`${postCommand.command} ${postCommand.args.join(' ')}\` exited.`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
54
79
|
}
|
|
55
80
|
}
|
|
56
81
|
CreateCommand.TemplateActions = [
|
|
57
82
|
{
|
|
58
|
-
name: '
|
|
59
|
-
value: '
|
|
83
|
+
name: 'Vanilla',
|
|
84
|
+
value: 'vanilla',
|
|
60
85
|
command: 'git',
|
|
61
|
-
args: [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
args: ['clone', '--depth=1', 'https://github.com/sabertazimi/bod'],
|
|
87
|
+
postCommands: [
|
|
88
|
+
{
|
|
89
|
+
command: 'mv',
|
|
90
|
+
args: ['appPath', 'appPath.bak'],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
command: 'mv',
|
|
94
|
+
args: ['appPath.bak/packages/webpack-template', 'appPath'],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
command: 'rm',
|
|
98
|
+
args: ['-rf', 'appPath.bak'],
|
|
99
|
+
},
|
|
65
100
|
],
|
|
66
101
|
},
|
|
67
102
|
{
|
|
68
103
|
name: 'React JSX',
|
|
69
104
|
value: 'jsx',
|
|
70
|
-
command: '
|
|
105
|
+
command: 'npm',
|
|
71
106
|
args: [
|
|
72
|
-
'create
|
|
107
|
+
'create',
|
|
108
|
+
'react-app@latest',
|
|
73
109
|
'--template',
|
|
74
110
|
'@sabertazimi/cra-template@latest',
|
|
75
111
|
'--scripts-version',
|
|
76
112
|
'@sabertazimi/react-scripts@latest',
|
|
77
113
|
],
|
|
114
|
+
postCommands: [],
|
|
78
115
|
},
|
|
79
116
|
{
|
|
80
117
|
name: 'React TSX',
|
|
81
118
|
value: 'tsx',
|
|
82
|
-
command: '
|
|
119
|
+
command: 'npm',
|
|
83
120
|
args: [
|
|
84
|
-
'create
|
|
121
|
+
'create',
|
|
122
|
+
'react-app@latest',
|
|
85
123
|
'--template',
|
|
86
124
|
'@sabertazimi/cra-template-typescript@latest',
|
|
87
125
|
'--scripts-version',
|
|
88
126
|
'@sabertazimi/react-scripts@latest',
|
|
89
127
|
],
|
|
128
|
+
postCommands: [],
|
|
90
129
|
},
|
|
91
130
|
{
|
|
92
131
|
name: 'React Framework',
|
|
93
|
-
value: '
|
|
94
|
-
command: '
|
|
132
|
+
value: 'react',
|
|
133
|
+
command: 'npm',
|
|
95
134
|
args: [
|
|
96
|
-
'create
|
|
135
|
+
'create',
|
|
136
|
+
'react-app@latest',
|
|
97
137
|
'--template',
|
|
98
138
|
'cra-template-bod@latest',
|
|
99
139
|
'--scripts-version',
|
|
100
140
|
'@sabertazimi/react-scripts@latest',
|
|
101
141
|
],
|
|
142
|
+
postCommands: [],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: 'Vue Framework',
|
|
146
|
+
value: 'vue',
|
|
147
|
+
command: 'npm',
|
|
148
|
+
args: [
|
|
149
|
+
'create',
|
|
150
|
+
'vue@latest',
|
|
151
|
+
],
|
|
152
|
+
postCommands: [],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'Vite Framework',
|
|
156
|
+
value: 'vite',
|
|
157
|
+
command: 'npm',
|
|
158
|
+
args: [
|
|
159
|
+
'create',
|
|
160
|
+
'vite@latest',
|
|
161
|
+
],
|
|
162
|
+
postCommands: [],
|
|
102
163
|
},
|
|
103
164
|
];
|
|
104
165
|
exports.default = CreateCommand;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
5
4
|
const ci_info_1 = require("ci-info");
|
|
6
5
|
const rimraf_1 = require("rimraf");
|
|
7
6
|
const utils_1 = require("../../utils");
|
|
8
7
|
const CreateCommand_1 = tslib_1.__importDefault(require("../CreateCommand"));
|
|
9
|
-
const appPath =
|
|
8
|
+
const appPath = 'bod-unit-tests';
|
|
10
9
|
describe('createCommand', () => {
|
|
11
10
|
beforeEach(() => (0, rimraf_1.sync)(appPath));
|
|
12
11
|
afterEach(() => (0, rimraf_1.sync)(appPath));
|
|
@@ -31,14 +30,19 @@ describe('createCommand', () => {
|
|
|
31
30
|
status: 0,
|
|
32
31
|
};
|
|
33
32
|
});
|
|
33
|
+
const additionalOptions = value === 'vue'
|
|
34
|
+
? ['--default']
|
|
35
|
+
: value === 'vite'
|
|
36
|
+
? ['--template', 'vue']
|
|
37
|
+
: [];
|
|
34
38
|
const createCommand = new CreateCommand_1.default();
|
|
35
|
-
yield expect(createCommand.run(appPath)).resolves.toBeUndefined();
|
|
36
|
-
const { command, args } = CreateCommand_1.default.TemplateActions.find(action => action.value === value);
|
|
39
|
+
yield expect(createCommand.run(appPath, additionalOptions)).resolves.toBeUndefined();
|
|
40
|
+
const { command, args, postCommands } = CreateCommand_1.default.TemplateActions.find(action => action.value === value);
|
|
37
41
|
expect(createCommand.getCommand()).toBe(command);
|
|
38
42
|
expect(createCommand.getCommandArgs()).toHaveLength(args.length + 1);
|
|
39
43
|
expect(createCommand.getCommandArgs()).toStrictEqual(args.concat(appPath));
|
|
40
|
-
expect(mockPrompt).
|
|
41
|
-
expect(mockSpawn).
|
|
44
|
+
expect(mockPrompt).toHaveBeenCalledTimes(1);
|
|
45
|
+
expect(mockSpawn).toHaveBeenCalledTimes(postCommands.length + 1);
|
|
42
46
|
mockPrompt.mockRestore();
|
|
43
47
|
mockSpawn.mockRestore();
|
|
44
48
|
}));
|
|
@@ -56,10 +60,15 @@ describe('createCommand', () => {
|
|
|
56
60
|
status: 1,
|
|
57
61
|
};
|
|
58
62
|
});
|
|
63
|
+
const additionalOptions = value === 'vue'
|
|
64
|
+
? ['--default']
|
|
65
|
+
: value === 'vite'
|
|
66
|
+
? ['--template', 'vue']
|
|
67
|
+
: [];
|
|
59
68
|
const createCommand = new CreateCommand_1.default();
|
|
60
|
-
yield expect(createCommand.run(appPath)).rejects.toThrowError();
|
|
61
|
-
expect(mockPrompt).
|
|
62
|
-
expect(mockSpawn).
|
|
69
|
+
yield expect(createCommand.run(appPath, additionalOptions)).rejects.toThrowError();
|
|
70
|
+
expect(mockPrompt).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(mockSpawn).toHaveBeenCalledTimes(1);
|
|
63
72
|
mockPrompt.mockRestore();
|
|
64
73
|
mockSpawn.mockRestore();
|
|
65
74
|
}));
|
|
@@ -72,10 +81,15 @@ describe('createCommand', () => {
|
|
|
72
81
|
});
|
|
73
82
|
return promise;
|
|
74
83
|
});
|
|
84
|
+
const additionalOptions = value === 'vue'
|
|
85
|
+
? ['--default']
|
|
86
|
+
: value === 'vite'
|
|
87
|
+
? ['--template', 'vue']
|
|
88
|
+
: [];
|
|
75
89
|
const createCommand = new CreateCommand_1.default();
|
|
76
90
|
if (ci_info_1.isCI) {
|
|
77
|
-
yield expect(createCommand.run(appPath)).resolves.toBeUndefined();
|
|
78
|
-
expect(mockPrompt).
|
|
91
|
+
yield expect(createCommand.run(appPath, additionalOptions)).resolves.toBeUndefined();
|
|
92
|
+
expect(mockPrompt).toHaveBeenCalledTimes(1);
|
|
79
93
|
}
|
|
80
94
|
mockPrompt.mockRestore();
|
|
81
95
|
}));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
3
5
|
const index_1 = require("../index");
|
|
4
6
|
describe('utils', () => {
|
|
5
7
|
it('should execute chalk correctly', () => {
|
|
@@ -7,7 +9,19 @@ describe('utils', () => {
|
|
|
7
9
|
});
|
|
8
10
|
it('should execute program correctly', () => {
|
|
9
11
|
const mockParse = jest.spyOn(index_1.program, 'parse').mockImplementation(jest.fn());
|
|
10
|
-
expect(
|
|
12
|
+
expect(node_process_1.default.env.__BOD__).toStrictEqual('__BOD__');
|
|
11
13
|
mockParse.mockRestore();
|
|
12
14
|
});
|
|
15
|
+
it('should return correct package manager', () => {
|
|
16
|
+
node_process_1.default.env.npm_config_user_agent = 'pnpm/8.15.0';
|
|
17
|
+
expect((0, index_1.findPackageManager)()).toStrictEqual('pnpm');
|
|
18
|
+
node_process_1.default.env.npm_config_user_agent = 'yarn/1.22.22';
|
|
19
|
+
expect((0, index_1.findPackageManager)()).toStrictEqual('yarn');
|
|
20
|
+
node_process_1.default.env.npm_config_user_agent = 'yarn/4.2.0';
|
|
21
|
+
expect((0, index_1.findPackageManager)()).toStrictEqual('yarn');
|
|
22
|
+
node_process_1.default.env.npm_config_user_agent = 'bun/0.1.0';
|
|
23
|
+
expect((0, index_1.findPackageManager)()).toStrictEqual('bun');
|
|
24
|
+
node_process_1.default.env.npm_config_user_agent = 'npm/10.0.0';
|
|
25
|
+
expect((0, index_1.findPackageManager)()).toStrictEqual('npm');
|
|
26
|
+
});
|
|
13
27
|
});
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { color, printer } from './console';
|
|
2
2
|
import { inquirer, program } from './core';
|
|
3
3
|
import { envinfo, spawn } from './os';
|
|
4
|
-
|
|
4
|
+
declare function findPackageManager(): string;
|
|
5
|
+
export { color, envinfo, findPackageManager, inquirer, printer, program, spawn };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.spawn = exports.
|
|
3
|
+
exports.spawn = exports.program = exports.printer = exports.inquirer = exports.findPackageManager = exports.envinfo = exports.color = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
4
6
|
const console_1 = require("./console");
|
|
5
7
|
Object.defineProperty(exports, "color", { enumerable: true, get: function () { return console_1.color; } });
|
|
6
8
|
Object.defineProperty(exports, "printer", { enumerable: true, get: function () { return console_1.printer; } });
|
|
@@ -10,3 +12,16 @@ Object.defineProperty(exports, "program", { enumerable: true, get: function () {
|
|
|
10
12
|
const os_1 = require("./os");
|
|
11
13
|
Object.defineProperty(exports, "envinfo", { enumerable: true, get: function () { return os_1.envinfo; } });
|
|
12
14
|
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return os_1.spawn; } });
|
|
15
|
+
function findPackageManager() {
|
|
16
|
+
var _a;
|
|
17
|
+
const userAgent = (_a = node_process_1.default.env.npm_config_user_agent) !== null && _a !== void 0 ? _a : '';
|
|
18
|
+
const packageManager = /pnpm/.test(userAgent)
|
|
19
|
+
? 'pnpm'
|
|
20
|
+
: /yarn/.test(userAgent)
|
|
21
|
+
? 'yarn'
|
|
22
|
+
: /bun/.test(userAgent)
|
|
23
|
+
? 'bun'
|
|
24
|
+
: 'npm';
|
|
25
|
+
return packageManager;
|
|
26
|
+
}
|
|
27
|
+
exports.findPackageManager = findPackageManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bod",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.19.0",
|
|
4
4
|
"description": "Boilerplate CLI App",
|
|
5
5
|
"author": "sabertazimi <sabertazimi@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"rimraf": "^5.0.5",
|
|
69
69
|
"type-fest": "^4.14.0"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "40c7ca4f998d87ae1589b5c0d17c88260f84af48"
|
|
72
72
|
}
|