miqro 4.0.1 → 5.0.1

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.
Files changed (41) hide show
  1. package/build/cli.js +1 -1
  2. package/build/cmd-map.d.ts +5 -4
  3. package/build/cmd-map.js +338 -34
  4. package/build/utils/doc/md.js +1 -1
  5. package/build/utils/{index.d.ts → exec.d.ts} +1 -0
  6. package/build/utils/templates.d.ts +19 -0
  7. package/build/utils/templates.js +153 -0
  8. package/build/utils/watch.d.ts +1 -0
  9. package/build/utils/watch.js +35 -0
  10. package/package.json +8 -8
  11. package/build/cmds/config-bash.d.ts +0 -2
  12. package/build/cmds/config-bash.js +0 -14
  13. package/build/cmds/config-env.d.ts +0 -2
  14. package/build/cmds/config-env.js +0 -14
  15. package/build/cmds/config-init.d.ts +0 -2
  16. package/build/cmds/config-init.js +0 -31
  17. package/build/cmds/config.d.ts +0 -2
  18. package/build/cmds/config.js +0 -11
  19. package/build/cmds/doc-json.d.ts +0 -2
  20. package/build/cmds/doc-json.js +0 -13
  21. package/build/cmds/doc-md.d.ts +0 -2
  22. package/build/cmds/doc-md.js +0 -13
  23. package/build/cmds/handler-apiroute-new.d.ts +0 -2
  24. package/build/cmds/handler-apiroute-new.js +0 -66
  25. package/build/cmds/handler-main-new.d.ts +0 -2
  26. package/build/cmds/handler-main-new.js +0 -78
  27. package/build/cmds/help.d.ts +0 -1
  28. package/build/cmds/help.js +0 -5
  29. package/build/cmds/new-test.d.ts +0 -2
  30. package/build/cmds/new-test.js +0 -44
  31. package/build/cmds/new.d.ts +0 -2
  32. package/build/cmds/new.js +0 -125
  33. package/build/cmds/serve.d.ts +0 -2
  34. package/build/cmds/serve.js +0 -78
  35. package/build/cmds/start.d.ts +0 -2
  36. package/build/cmds/start.js +0 -11
  37. package/build/cmds/watch.d.ts +0 -2
  38. package/build/cmds/watch.js +0 -50
  39. package/build/cmds/wc-new.d.ts +0 -2
  40. package/build/cmds/wc-new.js +0 -118
  41. /package/build/utils/{index.js → exec.js} +0 -0
@@ -1,50 +0,0 @@
1
- import { existsSync, statSync, watch, watchFile } from "fs";
2
- import { execSync } from "../utils/index.js";
3
- const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro watch <directory> <cmd>`;
4
- export const usage = usageMessage();
5
- function setupWatch(directory, cmd, timeout = 1000) {
6
- watchFile(directory, () => {
7
- queueRunCMD(cmd, timeout);
8
- });
9
- watch(directory, {
10
- recursive: true
11
- }, () => {
12
- queueRunCMD(cmd, timeout);
13
- });
14
- }
15
- let cmdTimeout = null;
16
- let running = false;
17
- function queueRunCMD(cmd, timeout) {
18
- if (running) {
19
- return;
20
- }
21
- if (cmdTimeout) {
22
- clearTimeout(cmdTimeout);
23
- }
24
- cmdTimeout = setTimeout(() => {
25
- running = true;
26
- try {
27
- execSync(cmd, {
28
- cwd: process.cwd(),
29
- env: process.env
30
- });
31
- }
32
- catch (e) {
33
- console.error(e);
34
- }
35
- running = false;
36
- }, timeout);
37
- }
38
- export const main = () => {
39
- if (process.argv.length < 5) {
40
- throw new Error(usageMessage("invalid number of args"));
41
- }
42
- const directory = process.argv[3];
43
- const cmd = process.argv.slice(4).join(" ");
44
- const timeout = process.env.WATCH_TIMEOUT ? parseInt(process.env.WATCH_TIMEOUT, 10) : undefined;
45
- if (!existsSync(directory) || !statSync(directory).isDirectory()) {
46
- throw new Error(usageMessage("directory not found!"));
47
- }
48
- console.log(`setting up watch on ${directory} with cmd ${cmd}`);
49
- setupWatch(directory, cmd, timeout);
50
- };
@@ -1,2 +0,0 @@
1
- export declare const usageTS = "usage: npx miqro new:front <identifier ex: NEW_APP>";
2
- export declare const mainTS: () => void;
@@ -1,118 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from "fs";
2
- import { resolve } from "path";
3
- import { execSync } from "../utils/index.js";
4
- const indexHTML = {
5
- js: () => `<html>` +
6
- `<script type="text/javascript" src="app.bundle.min.js"></script>` +
7
- `<body>` +
8
- `<app-component></app-component>` +
9
- `</body>` +
10
- `</html>`
11
- };
12
- const indexComponent = {
13
- ts: () => `import WebComponents, {JSX, define, RenderFunctionThis} from "@miqro/web-components"\n` +
14
- `\n` +
15
- `define("app-component", function(this: RenderFunctionThis): JSX.Element {\n` +
16
- ` return (<p>Hello World!</p>);\n` +
17
- `});\n`
18
- };
19
- const webpackconfig = {
20
- ts: () => `const mode = process.env.NODE_ENV ? process.env.NODE_ENV : "development";
21
- console.log("webpack mode [%s]", mode);
22
- module.exports = {` +
23
- ` mode: "production",` +
24
- ` entry: "./dist/index.js",` +
25
- ` output: {` +
26
- ` path: require("path").resolve(__dirname, 'build'),` +
27
- ` filename: "app.bundle.min.js"` +
28
- ` }` +
29
- `};`,
30
- };
31
- const gitignoreTemplate = {
32
- ts: () => `node_modules/
33
- dist/
34
- `
35
- };
36
- const packageTemplate = {
37
- ts: (name) => `{
38
- "name": "${name}",
39
- "version": "1.0.0",
40
- "description": "",
41
- "private": true,
42
- "main": "dist/main.js",
43
- "scripts": {
44
- "prebuild": "rm -Rf build/; rm -Rf dist/; mkdir build && cp -R public/ build/",
45
- "build": "tsc && NODE_ENV=production webpack",
46
- "build:dev": "tsc && webpack",
47
- "prestart": "npm run build:dev",
48
- "start": "miqro serve build/ / --port 3000 & miqro watch src/ \\"npm run build:dev\\""
49
- },
50
- "devDependencies": {
51
- },
52
- "dependencies": {
53
- },
54
- "author": "",
55
- "license": "ISC"
56
- }`
57
- };
58
- export const usageTS = `usage: npx miqro new:front <identifier ex: NEW_APP>`;
59
- export const mainTS = () => {
60
- if (process.argv.length !== 4 || process.argv[3].length < 1) {
61
- throw new Error(usageTS);
62
- }
63
- const identifier = process.argv[3].toLocaleLowerCase();
64
- const appFolder = resolve(process.cwd(), identifier);
65
- if (existsSync(appFolder)) {
66
- throw new Error(`${appFolder} already exists!`);
67
- }
68
- console.log(`creating ${appFolder}`);
69
- mkdirSync(appFolder, {
70
- recursive: true
71
- });
72
- writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
73
- execSync(`npm install miqro --save-dev`, {
74
- cwd: appFolder
75
- });
76
- /*execSync(
77
- `npm install @miqro/web-components --save`,
78
- {
79
- cwd: appFolder
80
- }
81
- );*/
82
- writeFileSync(resolve(appFolder, "tsconfig.json"), `{
83
- "compileOnSave": true,
84
- "compilerOptions": {
85
- "lib": ["es2021", "dom"],
86
- "module": "commonjs",
87
- "moduleResolution": "node",
88
- "target": "es2021",
89
- "strict": false,
90
- "outDir": "./dist/",
91
- "jsx": "react",
92
- "jsxFactory": "WebComponents.jsxFactory",
93
- "jsxFragmentFactory": "WebComponents.jsxFragmentFactory"
94
- },
95
- "exclude": [
96
- "node_modules",
97
- "test"
98
- ],
99
- "include": [
100
- "src"
101
- ]
102
- }`);
103
- execSync(`npm install typescript --save-dev`, {
104
- cwd: appFolder
105
- });
106
- writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
107
- execSync(`npm install webpack-cli --save-dev`, {
108
- cwd: appFolder
109
- });
110
- writeFileSync(resolve(appFolder, "webpack.config.js"), webpackconfig.ts());
111
- mkdirSync(resolve(appFolder, "src"));
112
- mkdirSync(resolve(appFolder, "public"));
113
- writeFileSync(resolve(appFolder, "public", "index.html"), indexHTML.js());
114
- writeFileSync(resolve(appFolder, "src", "index" + (".tsx")), indexComponent.ts());
115
- console.log(`new project created on ${appFolder}`);
116
- console.log(`cd ${identifier}`);
117
- console.log(`npm run start`);
118
- };
File without changes