Skip to content

Commit 794dedd

Browse files
author
victorsun
committed
upd
1 parent 6258b81 commit 794dedd

File tree

9 files changed

+1324
-52
lines changed

9 files changed

+1324
-52
lines changed

11-构建工具/05-脚手架/08-add&delete&list命令/bin/csxiaoyao-add.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
// 引入问答交互模块
33
import inquirer from 'inquirer';
44
import fs from 'fs';
5-
import path from 'path';
5+
66
import { createRequire } from "module";
7+
import path, { dirname } from 'path';
8+
import { fileURLToPath } from 'url';
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
711

812
const require = createRequire(import.meta.url);
9-
10-
// 获取模板文件路径
11-
// console.log(import.meta.url);
12-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
13-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
14-
15-
// const csxiaoyaoTpls = await import(tpath);
16-
const csxiaoyaoTpls = require(tpath);
13+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1714

1815
const questions = [
1916
{

11-构建工具/05-脚手架/08-add&delete&list命令/bin/csxiaoyao-delete.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import inquirer from 'inquirer';
44
import fs from 'fs';
5-
import path from 'path';
6-
import { createRequire } from "module";
7-
85
import chalk from 'chalk';
96

7+
import { createRequire } from "module";
8+
import path, { dirname } from 'path';
9+
import { fileURLToPath } from 'url';
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
12+
1013
const require = createRequire(import.meta.url);
11-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
12-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
13-
const csxiaoyaoTpls = require(tpath);
14+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1415

1516
const questions = [
1617
{

11-构建工具/05-脚手架/08-add&delete&list命令/bin/csxiaoyao-list.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env node
2+
import chalk from 'chalk';
23

3-
import inquirer from 'inquirer';
4-
import fs from 'fs';
5-
import path from 'path';
64
import { createRequire } from "module";
7-
import chalk from 'chalk';
5+
import path, { dirname } from 'path';
6+
import { fileURLToPath } from 'url';
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
89

910
const require = createRequire(import.meta.url);
10-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
11-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
12-
const csxiaoyaoTpls = require(tpath);
11+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1312

1413
csxiaoyaoTpls.forEach(v => {
1514
console.log(`模板名称: ${chalk.green(v.name)}, 模板地址: ${chalk.yellow(v.url)}`);

11-构建工具/05-脚手架/09-init命令/bin/csxiaoyao-init.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import { program } from 'commander';
44
import download from 'download-git-repo';
55
import ora from 'ora';
66
import fs from 'fs';
7-
import path from 'path';
87
import chalk from 'chalk';
8+
99
import { createRequire } from "module";
10+
import path, { dirname } from 'path';
11+
import { fileURLToPath } from 'url';
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
14+
1015
const require = createRequire(import.meta.url);
11-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
12-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
13-
const csxiaoyaoTpls = require(tpath);
16+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1417

1518
// 定义 csxiaoyao init <template-name> [project-name]
1619
program

11-构建工具/05-脚手架/10-npm发布/bin/csxiaoyao-add.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
// 引入问答交互模块
33
import inquirer from 'inquirer';
44
import fs from 'fs';
5-
import path from 'path';
5+
66
import { createRequire } from "module";
7+
import path, { dirname } from 'path';
8+
import { fileURLToPath } from 'url';
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
711

812
const require = createRequire(import.meta.url);
9-
10-
// 获取模板文件路径
11-
// console.log(import.meta.url);
12-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
13-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
14-
15-
// const csxiaoyaoTpls = await import(tpath);
16-
const csxiaoyaoTpls = require(tpath);
13+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1714

1815
const questions = [
1916
{

11-构建工具/05-脚手架/10-npm发布/bin/csxiaoyao-delete.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import inquirer from 'inquirer';
44
import fs from 'fs';
5-
import path from 'path';
6-
import { createRequire } from "module";
7-
85
import chalk from 'chalk';
96

7+
import { createRequire } from "module";
8+
import path, { dirname } from 'path';
9+
import { fileURLToPath } from 'url';
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
12+
1013
const require = createRequire(import.meta.url);
11-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
12-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
13-
const csxiaoyaoTpls = require(tpath);
14+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1415

1516
const questions = [
1617
{

11-构建工具/05-脚手架/10-npm发布/bin/csxiaoyao-init.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import { program } from 'commander';
44
import download from 'download-git-repo';
55
import ora from 'ora';
66
import fs from 'fs';
7-
import path from 'path';
87
import chalk from 'chalk';
8+
99
import { createRequire } from "module";
10+
import path, { dirname } from 'path';
11+
import { fileURLToPath } from 'url';
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
14+
1015
const require = createRequire(import.meta.url);
11-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
12-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
13-
const csxiaoyaoTpls = require(tpath);
16+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1417

1518
// 定义 csxiaoyao init <template-name> [project-name]
1619
program

11-构建工具/05-脚手架/10-npm发布/bin/csxiaoyao-list.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env node
2+
import chalk from 'chalk';
23

3-
import inquirer from 'inquirer';
4-
import fs from 'fs';
5-
import path from 'path';
64
import { createRequire } from "module";
7-
import chalk from 'chalk';
5+
import path, { dirname } from 'path';
6+
import { fileURLToPath } from 'url';
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename); // type=module时 __dirname 不可直接使用
89

910
const require = createRequire(import.meta.url);
10-
const __dirname = path.resolve(); // type=module 时不能直接使用 __dirname
11-
const tpath = path.resolve(__dirname, './csxiaoyao-template.json');
12-
const csxiaoyaoTpls = require(tpath);
11+
const csxiaoyaoTpls = require(path.resolve(__dirname, '../csxiaoyao-template.json'));
1312

1413
csxiaoyaoTpls.forEach(v => {
1514
console.log(`模板名称: ${chalk.green(v.name)}, 模板地址: ${chalk.yellow(v.url)}`);

0 commit comments

Comments
 (0)