Commit 794dedd victorsun
committed
1 parent 6258b81 commit 794dedd Copy full SHA for 794dedd
File tree 9 files changed +1324
-52
lines changed
9 files changed +1324
-52
lines changed Original file line number Diff line number Diff line change 2
2
// 引入问答交互模块
3
3
import inquirer from 'inquirer' ;
4
4
import fs from 'fs' ;
5
- import path from 'path' ;
5
+
6
6
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 不可直接使用
7
11
8
12
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' ) ) ;
17
14
18
15
const questions = [
19
16
{
Original file line number Diff line number Diff line change 2
2
3
3
import inquirer from 'inquirer' ;
4
4
import fs from 'fs' ;
5
- import path from 'path' ;
6
- import { createRequire } from "module" ;
7
-
8
5
import chalk from 'chalk' ;
9
6
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
+
10
13
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' ) ) ;
14
15
15
16
const questions = [
16
17
{
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
+ import chalk from 'chalk' ;
2
3
3
- import inquirer from 'inquirer' ;
4
- import fs from 'fs' ;
5
- import path from 'path' ;
6
4
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 不可直接使用
8
9
9
10
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' ) ) ;
13
12
14
13
csxiaoyaoTpls . forEach ( v => {
15
14
console . log ( `模板名称: ${ chalk . green ( v . name ) } , 模板地址: ${ chalk . yellow ( v . url ) } ` ) ;
Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ import { program } from 'commander';
4
4
import download from 'download-git-repo' ;
5
5
import ora from 'ora' ;
6
6
import fs from 'fs' ;
7
- import path from 'path' ;
8
7
import chalk from 'chalk' ;
8
+
9
9
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
+
10
15
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' ) ) ;
14
17
15
18
// 定义 csxiaoyao init <template-name> [project-name]
16
19
program
Original file line number Diff line number Diff line change 2
2
// 引入问答交互模块
3
3
import inquirer from 'inquirer' ;
4
4
import fs from 'fs' ;
5
- import path from 'path' ;
5
+
6
6
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 不可直接使用
7
11
8
12
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' ) ) ;
17
14
18
15
const questions = [
19
16
{
Original file line number Diff line number Diff line change 2
2
3
3
import inquirer from 'inquirer' ;
4
4
import fs from 'fs' ;
5
- import path from 'path' ;
6
- import { createRequire } from "module" ;
7
-
8
5
import chalk from 'chalk' ;
9
6
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
+
10
13
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' ) ) ;
14
15
15
16
const questions = [
16
17
{
Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ import { program } from 'commander';
4
4
import download from 'download-git-repo' ;
5
5
import ora from 'ora' ;
6
6
import fs from 'fs' ;
7
- import path from 'path' ;
8
7
import chalk from 'chalk' ;
8
+
9
9
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
+
10
15
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' ) ) ;
14
17
15
18
// 定义 csxiaoyao init <template-name> [project-name]
16
19
program
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
+ import chalk from 'chalk' ;
2
3
3
- import inquirer from 'inquirer' ;
4
- import fs from 'fs' ;
5
- import path from 'path' ;
6
4
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 不可直接使用
8
9
9
10
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' ) ) ;
13
12
14
13
csxiaoyaoTpls . forEach ( v => {
15
14
console . log ( `模板名称: ${ chalk . green ( v . name ) } , 模板地址: ${ chalk . yellow ( v . url ) } ` ) ;
You can’t perform that action at this time.
0 commit comments