makepack 1.7.11 → 1.7.13
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/README.md +122 -122
- package/package.json +62 -62
- package/src/actions/build/bundler.js +114 -114
- package/src/actions/build/index.js +74 -74
- package/src/actions/create/files/gitignore.js +9 -9
- package/src/actions/create/files/main.js +36 -36
- package/src/actions/create/files/package-json.js +49 -49
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +50 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +50 -50
- package/src/actions/create/files/readme.md.js +62 -62
- package/src/actions/create/files/tsconfig.js +33 -33
- package/src/actions/create/index.js +95 -95
- package/src/actions/create/makeFiles.js +65 -65
- package/src/actions/release/index.js +19 -19
- package/src/actions/start/index.js +215 -176
- package/src/actions/start/vite.js +68 -61
- package/src/helpers.js +52 -52
- package/src/index.js +39 -39
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import fs from 'fs-extra'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import ora from 'ora'
|
|
4
|
-
import { concolor, logger } from '../../helpers.js'
|
|
5
|
-
import bundler from './bundler.js'
|
|
6
|
-
|
|
7
|
-
const build = async (args) => {
|
|
8
|
-
/* args
|
|
9
|
-
--format=both
|
|
10
|
-
--bundle=true,
|
|
11
|
-
--minify=false,
|
|
12
|
-
--sourcemap=true,
|
|
13
|
-
--declaration=true,
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
|
|
17
|
-
|
|
18
|
-
const outdir = path.join(process.cwd(), '.mpack');
|
|
19
|
-
const rootdir = path.join(process.cwd(), 'src');
|
|
20
|
-
|
|
21
|
-
let entry = '';
|
|
22
|
-
let entryts = path.join(rootdir, 'index.ts');
|
|
23
|
-
let entryjs = path.join(rootdir, 'index.js');
|
|
24
|
-
let entrytsx = path.join(rootdir, 'index.tsx');
|
|
25
|
-
let entryjsx = path.join(rootdir, 'index.jsx');
|
|
26
|
-
|
|
27
|
-
if (fs.existsSync(entryts)) {
|
|
28
|
-
entry = "index.ts";
|
|
29
|
-
} else if (fs.existsSync(entryjs)) {
|
|
30
|
-
entry = "index.js";
|
|
31
|
-
} else if (fs.existsSync(entrytsx)) {
|
|
32
|
-
entry = "index.tsx";
|
|
33
|
-
} else if (fs.existsSync(entryjsx)) {
|
|
34
|
-
entry = "index.jsx";
|
|
35
|
-
} else {
|
|
36
|
-
throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
args = {
|
|
40
|
-
format: args.format || "both",
|
|
41
|
-
bundle: printBool('bundle'),
|
|
42
|
-
minify: printBool('minify'),
|
|
43
|
-
sourcemap: printBool('sourcemap'),
|
|
44
|
-
declaration: printBool('declaration'),
|
|
45
|
-
outdir,
|
|
46
|
-
rootdir,
|
|
47
|
-
entry: path.join(rootdir, entry),
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (fs.existsSync(outdir)) {
|
|
51
|
-
fs.rmSync(outdir, { recursive: true, force: true });
|
|
52
|
-
}
|
|
53
|
-
fs.mkdirSync(outdir)
|
|
54
|
-
const spinner = ora("✨ Bundling your package..\n").start();
|
|
55
|
-
await bundler(args, spinner);
|
|
56
|
-
spinner.text = "Copying package.json and readme.md files..."
|
|
57
|
-
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
58
|
-
if (fs.existsSync(pkgPath)) {
|
|
59
|
-
const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
60
|
-
delete pkgjson.scripts
|
|
61
|
-
delete pkgjson.type
|
|
62
|
-
fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
|
|
63
|
-
} else {
|
|
64
|
-
logger.error("package.json not found!");
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
|
|
69
|
-
spinner.succeed(concolor.bold(concolor.green(`Build successfully completed\n`)));
|
|
70
|
-
console.log(concolor.bold(`To publish your package to npm run:`));
|
|
71
|
-
console.log(`${concolor.yellow(`\`npm run release\``)} Or navigate to \`.mpack\` and run: ${concolor.yellow(`\`npm publish\`\n`)}`);
|
|
72
|
-
spinner.stop();
|
|
73
|
-
}
|
|
74
|
-
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import ora from 'ora'
|
|
4
|
+
import { concolor, logger } from '../../helpers.js'
|
|
5
|
+
import bundler from './bundler.js'
|
|
6
|
+
|
|
7
|
+
const build = async (args) => {
|
|
8
|
+
/* args
|
|
9
|
+
--format=both
|
|
10
|
+
--bundle=true,
|
|
11
|
+
--minify=false,
|
|
12
|
+
--sourcemap=true,
|
|
13
|
+
--declaration=true,
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
|
|
17
|
+
|
|
18
|
+
const outdir = path.join(process.cwd(), '.mpack');
|
|
19
|
+
const rootdir = path.join(process.cwd(), 'src');
|
|
20
|
+
|
|
21
|
+
let entry = '';
|
|
22
|
+
let entryts = path.join(rootdir, 'index.ts');
|
|
23
|
+
let entryjs = path.join(rootdir, 'index.js');
|
|
24
|
+
let entrytsx = path.join(rootdir, 'index.tsx');
|
|
25
|
+
let entryjsx = path.join(rootdir, 'index.jsx');
|
|
26
|
+
|
|
27
|
+
if (fs.existsSync(entryts)) {
|
|
28
|
+
entry = "index.ts";
|
|
29
|
+
} else if (fs.existsSync(entryjs)) {
|
|
30
|
+
entry = "index.js";
|
|
31
|
+
} else if (fs.existsSync(entrytsx)) {
|
|
32
|
+
entry = "index.tsx";
|
|
33
|
+
} else if (fs.existsSync(entryjsx)) {
|
|
34
|
+
entry = "index.jsx";
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
args = {
|
|
40
|
+
format: args.format || "both",
|
|
41
|
+
bundle: printBool('bundle'),
|
|
42
|
+
minify: printBool('minify'),
|
|
43
|
+
sourcemap: printBool('sourcemap'),
|
|
44
|
+
declaration: printBool('declaration'),
|
|
45
|
+
outdir,
|
|
46
|
+
rootdir,
|
|
47
|
+
entry: path.join(rootdir, entry),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (fs.existsSync(outdir)) {
|
|
51
|
+
fs.rmSync(outdir, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
fs.mkdirSync(outdir)
|
|
54
|
+
const spinner = ora("✨ Bundling your package..\n").start();
|
|
55
|
+
await bundler(args, spinner);
|
|
56
|
+
spinner.text = "Copying package.json and readme.md files..."
|
|
57
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
58
|
+
if (fs.existsSync(pkgPath)) {
|
|
59
|
+
const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
60
|
+
delete pkgjson.scripts
|
|
61
|
+
delete pkgjson.type
|
|
62
|
+
fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
|
|
63
|
+
} else {
|
|
64
|
+
logger.error("package.json not found!");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
|
|
69
|
+
spinner.succeed(concolor.bold(concolor.green(`Build successfully completed\n`)));
|
|
70
|
+
console.log(concolor.bold(`To publish your package to npm run:`));
|
|
71
|
+
console.log(`${concolor.yellow(`\`npm run release\``)} Or navigate to \`.mpack\` and run: ${concolor.yellow(`\`npm publish\`\n`)}`);
|
|
72
|
+
spinner.stop();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
75
|
export default build
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export default async () => {
|
|
3
|
-
return {
|
|
4
|
-
content: `
|
|
5
|
-
node_modules
|
|
6
|
-
.mpack
|
|
7
|
-
`,
|
|
8
|
-
filename: ".gitignore"
|
|
9
|
-
}
|
|
1
|
+
|
|
2
|
+
export default async () => {
|
|
3
|
+
return {
|
|
4
|
+
content: `
|
|
5
|
+
node_modules
|
|
6
|
+
.mpack
|
|
7
|
+
`,
|
|
8
|
+
filename: ".gitignore"
|
|
9
|
+
}
|
|
10
10
|
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export default async ({ template }) => {
|
|
2
|
-
|
|
3
|
-
let ext = 'jsx'
|
|
4
|
-
if (template === 'react with typescript') {
|
|
5
|
-
ext = 'tsx'
|
|
6
|
-
} else if (template === 'typescript') {
|
|
7
|
-
ext = 'ts'
|
|
8
|
-
}
|
|
9
|
-
else if (template === 'javascript') {
|
|
10
|
-
ext = 'js'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const content = `import React from 'react';
|
|
14
|
-
import { createRoot } from 'react-dom/client';
|
|
15
|
-
import ${ext.includes("sx") ? "Count" : "sum"} from './src/index.${ext}';
|
|
16
|
-
|
|
17
|
-
const Main = () => {
|
|
18
|
-
return (
|
|
19
|
-
<div>
|
|
20
|
-
<h1>Welcome to makepack CLI!</h1>
|
|
21
|
-
<p>Edit <code>index.${ext}</code> and save to reload.</p>
|
|
22
|
-
${ext.includes("sx") ? "<Count />" : "<p>The sum is: {sum(5, 5)}</p>"}
|
|
23
|
-
</div>
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const rootEle = document.getElementById('root')
|
|
28
|
-
if (rootEle) {
|
|
29
|
-
const root = createRoot(rootEle);
|
|
30
|
-
root.render(<Main />);
|
|
31
|
-
}
|
|
32
|
-
`
|
|
33
|
-
return {
|
|
34
|
-
content,
|
|
35
|
-
filename: `main.${ext.includes('ts') ? "tsx" : 'jsx'}`
|
|
36
|
-
}
|
|
1
|
+
export default async ({ template }) => {
|
|
2
|
+
|
|
3
|
+
let ext = 'jsx'
|
|
4
|
+
if (template === 'react with typescript') {
|
|
5
|
+
ext = 'tsx'
|
|
6
|
+
} else if (template === 'typescript') {
|
|
7
|
+
ext = 'ts'
|
|
8
|
+
}
|
|
9
|
+
else if (template === 'javascript') {
|
|
10
|
+
ext = 'js'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const content = `import React from 'react';
|
|
14
|
+
import { createRoot } from 'react-dom/client';
|
|
15
|
+
import ${ext.includes("sx") ? "Count" : "sum"} from './src/index.${ext}';
|
|
16
|
+
|
|
17
|
+
const Main = () => {
|
|
18
|
+
return (
|
|
19
|
+
<div>
|
|
20
|
+
<h1>Welcome to makepack CLI!</h1>
|
|
21
|
+
<p>Edit <code>index.${ext}</code> and save to reload.</p>
|
|
22
|
+
${ext.includes("sx") ? "<Count />" : "<p>The sum is: {sum(5, 5)}</p>"}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const rootEle = document.getElementById('root')
|
|
28
|
+
if (rootEle) {
|
|
29
|
+
const root = createRoot(rootEle);
|
|
30
|
+
root.render(<Main />);
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
return {
|
|
34
|
+
content,
|
|
35
|
+
filename: `main.${ext.includes('ts') ? "tsx" : 'jsx'}`
|
|
36
|
+
}
|
|
37
37
|
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
export default async (info) => {
|
|
3
|
-
let dependencies = {}
|
|
4
|
-
let devDependencies = {
|
|
5
|
-
"makepack": "latest",
|
|
6
|
-
"express": "latest"
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (info.template.includes("react")) {
|
|
10
|
-
devDependencies["react"] = "^19.0.0"
|
|
11
|
-
devDependencies["react-dom"] = "^19.0.0"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (info.template.includes("typescript")) {
|
|
15
|
-
devDependencies["typescript"] = "^4.4.2"
|
|
16
|
-
devDependencies["@types/react"] = "^19.0.2"
|
|
17
|
-
devDependencies["@types/react-dom"] = "^19.0.2"
|
|
18
|
-
devDependencies["@types/express"] = "latest"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const json = {
|
|
22
|
-
name: info.pdir,
|
|
23
|
-
version: "1.0.0",
|
|
24
|
-
main: `./index.js`,
|
|
25
|
-
module: `./index.mjs`,
|
|
26
|
-
types: `./index.d.ts`,
|
|
27
|
-
description: "",
|
|
28
|
-
keywords: [],
|
|
29
|
-
sideEffects: false,
|
|
30
|
-
scripts: {
|
|
31
|
-
"start": "makepack start",
|
|
32
|
-
"build": "makepack build",
|
|
33
|
-
"release": "makepack release"
|
|
34
|
-
},
|
|
35
|
-
"exports": {
|
|
36
|
-
".": {
|
|
37
|
-
"import": "./index.mjs",
|
|
38
|
-
"require": "./index.js",
|
|
39
|
-
"types": "./index.d.ts"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
dependencies,
|
|
43
|
-
devDependencies
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
content: JSON.stringify(json, null, 3),
|
|
48
|
-
filename: "package.json"
|
|
49
|
-
}
|
|
1
|
+
|
|
2
|
+
export default async (info) => {
|
|
3
|
+
let dependencies = {}
|
|
4
|
+
let devDependencies = {
|
|
5
|
+
"makepack": "latest",
|
|
6
|
+
"express": "latest"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (info.template.includes("react")) {
|
|
10
|
+
devDependencies["react"] = "^19.0.0"
|
|
11
|
+
devDependencies["react-dom"] = "^19.0.0"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (info.template.includes("typescript")) {
|
|
15
|
+
devDependencies["typescript"] = "^4.4.2"
|
|
16
|
+
devDependencies["@types/react"] = "^19.0.2"
|
|
17
|
+
devDependencies["@types/react-dom"] = "^19.0.2"
|
|
18
|
+
devDependencies["@types/express"] = "latest"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const json = {
|
|
22
|
+
name: info.pdir,
|
|
23
|
+
version: "1.0.0",
|
|
24
|
+
main: `./index.js`,
|
|
25
|
+
module: `./index.mjs`,
|
|
26
|
+
types: `./index.d.ts`,
|
|
27
|
+
description: "",
|
|
28
|
+
keywords: [],
|
|
29
|
+
sideEffects: false,
|
|
30
|
+
scripts: {
|
|
31
|
+
"start": "makepack start",
|
|
32
|
+
"build": "makepack build",
|
|
33
|
+
"release": "makepack release"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"import": "./index.mjs",
|
|
38
|
+
"require": "./index.js",
|
|
39
|
+
"types": "./index.d.ts"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
dependencies,
|
|
43
|
+
devDependencies
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
content: JSON.stringify(json, null, 3),
|
|
48
|
+
filename: "package.json"
|
|
49
|
+
}
|
|
50
50
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `
|
|
3
|
-
function sum(a, b) {
|
|
4
|
-
return a + b;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default sum
|
|
8
|
-
`
|
|
9
|
-
return {
|
|
10
|
-
content,
|
|
11
|
-
filename: `src/index.js`
|
|
12
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `
|
|
3
|
+
function sum(a, b) {
|
|
4
|
+
return a + b;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default sum
|
|
8
|
+
`
|
|
9
|
+
return {
|
|
10
|
+
content,
|
|
11
|
+
filename: `src/index.js`
|
|
12
|
+
}
|
|
13
13
|
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `import React, { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
const Index = () => {
|
|
5
|
-
const [count, setCount] = useState(0);
|
|
6
|
-
const increment = () => setCount(prevCount => prevCount + 1);
|
|
7
|
-
const decrement = () => setCount(prevCount => prevCount - 1);
|
|
8
|
-
const reset = () => setCount(0);
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div style={styles.container}>
|
|
12
|
-
<h1>Count App</h1>
|
|
13
|
-
<div style={styles.counter}>{count}</div>
|
|
14
|
-
<div style={styles.buttonContainer}>
|
|
15
|
-
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
-
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
-
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const styles = {
|
|
24
|
-
container: {
|
|
25
|
-
textAlign: 'center',
|
|
26
|
-
padding: '20px',
|
|
27
|
-
fontFamily: 'Arial, sans-serif'
|
|
28
|
-
},
|
|
29
|
-
counter: {
|
|
30
|
-
fontSize: '2rem',
|
|
31
|
-
margin: '20px 0',
|
|
32
|
-
},
|
|
33
|
-
buttonContainer: {
|
|
34
|
-
display: 'flex',
|
|
35
|
-
justifyContent: 'center',
|
|
36
|
-
gap: '10px',
|
|
37
|
-
},
|
|
38
|
-
button: {
|
|
39
|
-
padding: '10px 20px',
|
|
40
|
-
fontSize: '1rem',
|
|
41
|
-
cursor: 'pointer',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default Index;
|
|
46
|
-
`
|
|
47
|
-
return {
|
|
48
|
-
content,
|
|
49
|
-
filename: `src/index.jsx`
|
|
50
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `import React, { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
const Index = () => {
|
|
5
|
+
const [count, setCount] = useState(0);
|
|
6
|
+
const increment = () => setCount(prevCount => prevCount + 1);
|
|
7
|
+
const decrement = () => setCount(prevCount => prevCount - 1);
|
|
8
|
+
const reset = () => setCount(0);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div style={styles.container}>
|
|
12
|
+
<h1>Count App</h1>
|
|
13
|
+
<div style={styles.counter}>{count}</div>
|
|
14
|
+
<div style={styles.buttonContainer}>
|
|
15
|
+
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
+
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
+
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const styles = {
|
|
24
|
+
container: {
|
|
25
|
+
textAlign: 'center',
|
|
26
|
+
padding: '20px',
|
|
27
|
+
fontFamily: 'Arial, sans-serif'
|
|
28
|
+
},
|
|
29
|
+
counter: {
|
|
30
|
+
fontSize: '2rem',
|
|
31
|
+
margin: '20px 0',
|
|
32
|
+
},
|
|
33
|
+
buttonContainer: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
gap: '10px',
|
|
37
|
+
},
|
|
38
|
+
button: {
|
|
39
|
+
padding: '10px 20px',
|
|
40
|
+
fontSize: '1rem',
|
|
41
|
+
cursor: 'pointer',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default Index;
|
|
46
|
+
`
|
|
47
|
+
return {
|
|
48
|
+
content,
|
|
49
|
+
filename: `src/index.jsx`
|
|
50
|
+
}
|
|
51
51
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `
|
|
3
|
-
function sum(a: number, b: number): number {
|
|
4
|
-
return a + b;
|
|
5
|
-
}
|
|
6
|
-
export default sum`
|
|
7
|
-
return {
|
|
8
|
-
content,
|
|
9
|
-
filename: `src/index.ts`
|
|
10
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `
|
|
3
|
+
function sum(a: number, b: number): number {
|
|
4
|
+
return a + b;
|
|
5
|
+
}
|
|
6
|
+
export default sum`
|
|
7
|
+
return {
|
|
8
|
+
content,
|
|
9
|
+
filename: `src/index.ts`
|
|
10
|
+
}
|
|
11
11
|
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
export default async () => {
|
|
2
|
-
const content = `import React, { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
const Index: React.FC = () => {
|
|
5
|
-
const [count, setCount] = useState<number>(0);
|
|
6
|
-
const increment = (): void => setCount(prevCount => prevCount + 1);
|
|
7
|
-
const decrement = (): void => setCount(prevCount => prevCount - 1);
|
|
8
|
-
const reset = (): void => setCount(0);
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div style={styles.container}>
|
|
12
|
-
<h1>Count App</h1>
|
|
13
|
-
<div style={styles.counter}>{count}</div>
|
|
14
|
-
<div style={styles.buttonContainer}>
|
|
15
|
-
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
-
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
-
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
-
</div>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const styles: { [key: string]: React.CSSProperties } = {
|
|
24
|
-
container: {
|
|
25
|
-
textAlign: 'center',
|
|
26
|
-
padding: '20px',
|
|
27
|
-
fontFamily: 'Arial, sans-serif',
|
|
28
|
-
},
|
|
29
|
-
counter: {
|
|
30
|
-
fontSize: '2rem',
|
|
31
|
-
margin: '20px 0',
|
|
32
|
-
},
|
|
33
|
-
buttonContainer: {
|
|
34
|
-
display: 'flex',
|
|
35
|
-
justifyContent: 'center',
|
|
36
|
-
gap: '10px',
|
|
37
|
-
},
|
|
38
|
-
button: {
|
|
39
|
-
padding: '10px 20px',
|
|
40
|
-
fontSize: '1rem',
|
|
41
|
-
cursor: 'pointer',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default Index;
|
|
46
|
-
`
|
|
47
|
-
return {
|
|
48
|
-
content,
|
|
49
|
-
filename: `src/index.tsx`
|
|
50
|
-
}
|
|
1
|
+
export default async () => {
|
|
2
|
+
const content = `import React, { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
const Index: React.FC = () => {
|
|
5
|
+
const [count, setCount] = useState<number>(0);
|
|
6
|
+
const increment = (): void => setCount(prevCount => prevCount + 1);
|
|
7
|
+
const decrement = (): void => setCount(prevCount => prevCount - 1);
|
|
8
|
+
const reset = (): void => setCount(0);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div style={styles.container}>
|
|
12
|
+
<h1>Count App</h1>
|
|
13
|
+
<div style={styles.counter}>{count}</div>
|
|
14
|
+
<div style={styles.buttonContainer}>
|
|
15
|
+
<button style={styles.button} onClick={increment}>Increment</button>
|
|
16
|
+
<button style={styles.button} onClick={decrement}>Decrement</button>
|
|
17
|
+
<button style={styles.button} onClick={reset}>Reset</button>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const styles: { [key: string]: React.CSSProperties } = {
|
|
24
|
+
container: {
|
|
25
|
+
textAlign: 'center',
|
|
26
|
+
padding: '20px',
|
|
27
|
+
fontFamily: 'Arial, sans-serif',
|
|
28
|
+
},
|
|
29
|
+
counter: {
|
|
30
|
+
fontSize: '2rem',
|
|
31
|
+
margin: '20px 0',
|
|
32
|
+
},
|
|
33
|
+
buttonContainer: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
gap: '10px',
|
|
37
|
+
},
|
|
38
|
+
button: {
|
|
39
|
+
padding: '10px 20px',
|
|
40
|
+
fontSize: '1rem',
|
|
41
|
+
cursor: 'pointer',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default Index;
|
|
46
|
+
`
|
|
47
|
+
return {
|
|
48
|
+
content,
|
|
49
|
+
filename: `src/index.tsx`
|
|
50
|
+
}
|
|
51
51
|
}
|