turbo-web 4.2.5 → 4.2.6
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/bin/turbo-charge.js +55 -30
- package/package.json +1 -1
package/bin/turbo-charge.js
CHANGED
|
@@ -5,7 +5,6 @@ import '../dist/turbo.js';
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
|
|
8
|
-
// 1. gets the project name from the terminal command
|
|
9
8
|
const projectName = process.argv[2];
|
|
10
9
|
|
|
11
10
|
if (!projectName) {
|
|
@@ -14,41 +13,67 @@ if (!projectName) {
|
|
|
14
13
|
process.exit(1);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
//
|
|
16
|
+
// defines the target directory path
|
|
18
17
|
const projectPath = path.join(process.cwd(), projectName);
|
|
18
|
+
const srcPath = path.join(projectPath, 'src');
|
|
19
19
|
|
|
20
|
-
//
|
|
20
|
+
// creates the directories
|
|
21
21
|
fs.mkdirSync(projectPath, { recursive: true });
|
|
22
22
|
fs.mkdirSync(path.join(projectPath, 'src'), { recursive: true });
|
|
23
23
|
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
// auto initiating package.json
|
|
25
|
+
const packageJsonContent = {
|
|
26
|
+
name: projectName,
|
|
27
|
+
version: "1.0.0",
|
|
28
|
+
type: "module",
|
|
29
|
+
dependencies: {
|
|
30
|
+
"turbo-web": "latest"
|
|
31
|
+
},
|
|
32
|
+
scripts: {
|
|
33
|
+
"start": "npx serve ."
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
fs.writeFileSync(
|
|
38
|
+
path.join(projectPath, 'package.json'),
|
|
39
|
+
JSON.stringify(packageJsonContent, null, 2)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// defines the boilerplate file contents
|
|
43
|
+
const storeContent = `import { Store } from 'turbo-web';
|
|
44
|
+
export const appStore = new Store({ state: { count: 0 } });`;
|
|
45
|
+
|
|
46
|
+
const routerContent = `import { HashRouter } from 'turbo-web';
|
|
47
|
+
export const router = new HashRouter([{ path: '/', component: null }]);`;
|
|
48
|
+
|
|
49
|
+
const mainContent = `import { createApp, h } from 'turbo-web';
|
|
50
|
+
import { router } from './router.js';
|
|
51
|
+
import { appStore } from './store.js';
|
|
52
|
+
|
|
53
|
+
const App = { render: () => h('div', {}, ['Turbo Power!']) };
|
|
54
|
+
createApp(App, {}, { router, store: appStore }).mount(document.body);`;
|
|
55
|
+
|
|
56
|
+
// write the files to the user's new project directory
|
|
57
|
+
fs.writeFileSync(path.join(srcPath, 'store.js'), storeContent);
|
|
58
|
+
fs.writeFileSync(path.join(srcPath, 'router.js'), routerContent);
|
|
59
|
+
fs.writeFileSync(path.join(srcPath, 'main.js'), mainContent);
|
|
42
60
|
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
// defining HTML
|
|
62
|
+
const htmlContent = `<!DOCTYPE html>
|
|
63
|
+
<html>
|
|
64
|
+
<head><title>${projectName}</title></head>
|
|
65
|
+
<body>
|
|
66
|
+
<script type="module" src="./src/main.js"></script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>`;
|
|
45
69
|
|
|
46
|
-
|
|
47
|
-
`;
|
|
70
|
+
fs.writeFileSync(path.join(projectPath, 'index.html'), htmlContent);
|
|
48
71
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
fs.writeFileSync(path.join(projectPath, 'src', 'router.js'), routerContent);
|
|
52
|
-
fs.writeFileSync(path.join(projectPath, 'src', 'main.js'), mainContent);
|
|
72
|
+
console.log(`
|
|
73
|
+
BUENO! [${projectName}] is TURBO charged for WEB development.
|
|
53
74
|
|
|
54
|
-
|
|
75
|
+
Next steps:
|
|
76
|
+
1. cd ${projectName}
|
|
77
|
+
2. npm install
|
|
78
|
+
"You are ready for development!"
|
|
79
|
+
`);
|