Skip to content

Commit ca43fe2

Browse files
committed
Build script to setup ESM/CJS module exports
1 parent 7c16709 commit ca43fe2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1413
-693
lines changed

example.js

+102-106
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,110 @@
1-
'use strict';
2-
3-
const { prompt } = require('./');
1+
import { prompt } from './index.js';
42

53
let interval;
64

7-
(async function(){
8-
const questions = [
9-
{
10-
type: 'text',
11-
name: 'twitter',
12-
message: `What's your twitter handle?`,
13-
initial: `terkelg`,
14-
format: v => `@${v}`
15-
},
16-
{
17-
type: 'number',
18-
name: 'age',
19-
message: 'How old are you?',
20-
validate: value => value < 18 ? `Sorry, you have to be 18` : true
21-
},
22-
{
23-
type: 'password',
24-
name: 'secret',
25-
message: 'Tell me a secret'
26-
},
27-
{
28-
type: 'confirm',
29-
name: 'confirmed',
30-
message: 'Can you confirm?'
31-
},
32-
{
33-
type: prev => prev && 'toggle',
34-
name: 'confirmtoggle',
35-
message: 'Can you confirm again?',
36-
active: 'yes',
37-
inactive: 'no'
38-
},
39-
{
40-
type: 'list',
41-
name: 'keywords',
42-
message: 'Enter keywords'
43-
},
44-
{
45-
type: 'select',
46-
name: 'color',
47-
message: 'Pick a color',
48-
choices: [
49-
{ title: 'Red', description: 'This option has a description.', value: '#ff0000' },
50-
{ title: 'Green', value: '#00ff00' },
51-
{ title: 'Yellow', value: '#ffff00', disabled: true },
52-
{ title: 'Blue', value: '#0000ff' }
53-
]
54-
},
55-
{
56-
type: 'multiselect',
57-
name: 'multicolor',
58-
message: 'Pick colors',
59-
hint: false,
60-
choices: [
61-
{ title: 'Red', description: 'This option has a description.', value: '#ff0000' },
62-
{ title: 'Green', value: '#00ff00' },
63-
{ title: 'Yellow', value: '#ffff00', disabled: true },
64-
{ title: 'Blue', value: '#0000ff' }
65-
]
66-
},
67-
{
68-
type: 'autocomplete',
69-
name: 'actor',
70-
message: 'Pick your favorite actor',
71-
initial: 1,
72-
limit: 3,
73-
suggest: (input, choices) => choices.filter(i => i.title.toLowerCase().includes(input.toLowerCase())),
74-
choices: [
75-
{ title: 'Cage' },
76-
{ title: 'Clooney', value: 'silver-fox' },
77-
{ title: 'Gyllenhaal' },
78-
{ title: 'Gibson' },
79-
{ title: 'Grant', description: 'This option has a description.' },
80-
{ title: 'Hanks' },
81-
{ title: 'Downey Jr.' }
82-
],
83-
fallback: {
84-
title: `This is the fallback. Its value is 'fallback'`,
85-
value: 'fallback'
86-
}
87-
},
88-
{
89-
type: 'date',
90-
name: 'birthday',
91-
message: `What's your birthday?`,
92-
validate: date => date > Date.now() ? `Your birth day can't be in the future` : true
93-
},
94-
{
95-
type: 'number',
96-
name: 'prompt',
97-
message: 'This will be overridden',
98-
onRender(color) {
99-
this.no = (this.no || 1);
100-
this.msg = `Enter a number (e.g. ${color.cyan(this.no)})`;
101-
if (!interval) interval = setInterval(() => {
102-
this.no += 1;
103-
this.render();
104-
}, 1000);
105-
}
5+
const questions = [
6+
{
7+
type: 'text',
8+
name: 'twitter',
9+
message: `What's your twitter handle?`,
10+
initial: `terkelg`,
11+
format: v => `@${v}`
12+
},
13+
{
14+
type: 'number',
15+
name: 'age',
16+
message: 'How old are you?',
17+
validate: value => value < 18 ? `Sorry, you have to be 18` : true
18+
},
19+
{
20+
type: 'password',
21+
name: 'secret',
22+
message: 'Tell me a secret'
23+
},
24+
{
25+
type: 'confirm',
26+
name: 'confirmed',
27+
message: 'Can you confirm?'
28+
},
29+
{
30+
type: prev => prev && 'toggle',
31+
name: 'confirmtoggle',
32+
message: 'Can you confirm again?',
33+
active: 'yes',
34+
inactive: 'no'
35+
},
36+
{
37+
type: 'list',
38+
name: 'keywords',
39+
message: 'Enter keywords'
40+
},
41+
{
42+
type: 'select',
43+
name: 'color',
44+
message: 'Pick a color',
45+
choices: [
46+
{ title: 'Red', description: 'This option has a description.', value: '#ff0000' },
47+
{ title: 'Green', value: '#00ff00' },
48+
{ title: 'Yellow', value: '#ffff00', disabled: true },
49+
{ title: 'Blue', value: '#0000ff' }
50+
]
51+
},
52+
{
53+
type: 'multiselect',
54+
name: 'multicolor',
55+
message: 'Pick colors',
56+
hint: false,
57+
choices: [
58+
{ title: 'Red', description: 'This option has a description.', value: '#ff0000' },
59+
{ title: 'Green', value: '#00ff00' },
60+
{ title: 'Yellow', value: '#ffff00', disabled: true },
61+
{ title: 'Blue', value: '#0000ff' }
62+
]
63+
},
64+
{
65+
type: 'autocomplete',
66+
name: 'actor',
67+
message: 'Pick your favorite actor',
68+
initial: 1,
69+
limit: 3,
70+
suggest: (input, choices) => choices.filter(i => i.title.toLowerCase().includes(input.toLowerCase())),
71+
choices: [
72+
{ title: 'Cage' },
73+
{ title: 'Clooney', value: 'silver-fox' },
74+
{ title: 'Gyllenhaal' },
75+
{ title: 'Gibson' },
76+
{ title: 'Grant', description: 'This option has a description.' },
77+
{ title: 'Hanks' },
78+
{ title: 'Downey Jr.' }
79+
],
80+
fallback: {
81+
title: `This is the fallback. Its value is 'fallback'`,
82+
value: 'fallback'
83+
}
84+
},
85+
{
86+
type: 'date',
87+
name: 'birthday',
88+
message: `What's your birthday?`,
89+
validate: date => date > Date.now() ? `Your birth day can't be in the future` : true
90+
},
91+
{
92+
type: 'number',
93+
name: 'prompt',
94+
message: 'This will be overridden',
95+
onRender(color) {
96+
this.no = (this.no || 1);
97+
this.msg = `Enter a number (e.g. ${color.cyan(this.no)})`;
98+
if (!interval) interval = setInterval(() => {
99+
this.no += 1;
100+
this.render();
101+
}, 1000);
106102
}
107-
];
103+
}
104+
];
108105

109-
const answers = await prompt(questions, {onCancel:cleanup, onSubmit:cleanup});
110-
console.log(answers);
111-
})();
106+
const answers = await prompt(questions, {onCancel:cleanup, onSubmit:cleanup});
107+
console.log(answers);
112108

113109
function cleanup() {
114110
clearInterval(interval);

index.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const prompts = require("./dist/index.js").default;
2+
3+
module.exports = prompts;

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
module.exports = require('./lib/index.js');
1+
import { default as prompts } from './lib/index.js';
2+
3+
export * from './lib/index.js';
4+
export default prompts;

lib/dateparts/datepart.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
class DatePart {
42
constructor({token, date, parts, locales}) {
53
this.token = token;
@@ -30,6 +28,6 @@ class DatePart {
3028
}
3129
}
3230

33-
module.exports = DatePart;
31+
export default DatePart;
3432

3533

lib/dateparts/day.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
const pos = n => {
64
n = n % 10;
@@ -39,4 +37,4 @@ class Day extends DatePart {
3937
}
4038
}
4139

42-
module.exports = Day;
40+
export default Day;

lib/dateparts/hours.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Hours extends DatePart {
64
constructor(opts={}) {
@@ -27,4 +25,4 @@ class Hours extends DatePart {
2725
}
2826
}
2927

30-
module.exports = Hours;
28+
export default Hours;

lib/dateparts/index.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
'use strict';
1+
import DatePart from './datepart.js';
2+
import Meridiem from './meridiem.js';
3+
import Day from './day.js';
4+
import Hours from './hours.js';
5+
import Milliseconds from './milliseconds.js';
6+
import Minutes from './minutes.js';
7+
import Month from './month.js';
8+
import Seconds from './seconds.js';
9+
import Year from './year.js';
210

3-
module.exports = {
4-
DatePart: require('./datepart'),
5-
Meridiem: require('./meridiem'),
6-
Day: require('./day'),
7-
Hours: require('./hours'),
8-
Milliseconds: require('./milliseconds'),
9-
Minutes: require('./minutes'),
10-
Month: require('./month'),
11-
Seconds: require('./seconds'),
12-
Year: require('./year'),
11+
export {
12+
DatePart,
13+
Meridiem,
14+
Day,
15+
Hours,
16+
Milliseconds,
17+
Minutes,
18+
Month,
19+
Seconds,
20+
Year,
1321
}

lib/dateparts/meridiem.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Meridiem extends DatePart {
64
constructor(opts={}) {
@@ -21,4 +19,4 @@ class Meridiem extends DatePart {
2119
}
2220
}
2321

24-
module.exports = Meridiem;
22+
export default Meridiem;

lib/dateparts/milliseconds.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Milliseconds extends DatePart {
64
constructor(opts={}) {
@@ -25,4 +23,4 @@ class Milliseconds extends DatePart {
2523
}
2624
}
2725

28-
module.exports = Milliseconds;
26+
export default Milliseconds;

lib/dateparts/minutes.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Minutes extends DatePart {
64
constructor(opts={}) {
@@ -25,4 +23,4 @@ class Minutes extends DatePart {
2523
}
2624
}
2725

28-
module.exports = Minutes;
26+
export default Minutes;

lib/dateparts/month.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Month extends DatePart {
64
constructor(opts={}) {
@@ -30,4 +28,4 @@ class Month extends DatePart {
3028
}
3129
}
3230

33-
module.exports = Month;
31+
export default Month;

lib/dateparts/seconds.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Seconds extends DatePart {
64
constructor(opts={}) {
@@ -25,4 +23,4 @@ class Seconds extends DatePart {
2523
}
2624
}
2725

28-
module.exports = Seconds;
26+
export default Seconds;

lib/dateparts/year.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const DatePart = require('./datepart');
1+
import DatePart from './datepart.js';
42

53
class Year extends DatePart {
64
constructor(opts={}) {
@@ -25,4 +23,4 @@ class Year extends DatePart {
2523
}
2624
}
2725

28-
module.exports = Year;
26+
export default Year;

0 commit comments

Comments
 (0)