structured-fw 0.7.8 → 0.7.9

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from 'path';
3
+ import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
4
+ const cwd = resolve(import.meta.dirname, '..');
5
+ const projectRoot = resolve('.');
6
+ if (process.argv.length < 3) {
7
+ console.log('Thanks for using the Structured framework.');
8
+ console.log(`To set up a basic boilerplate in ${projectRoot} run:\n npx structured init`);
9
+ process.exit();
10
+ }
11
+ const command = process.argv[2];
12
+ function copyIfNotExists(src, dst) {
13
+ if (typeof dst !== 'string') {
14
+ dst = src;
15
+ }
16
+ if (existsSync(`${cwd}/${src}`) && !existsSync(`${projectRoot}/${dst}`)) {
17
+ console.log(`Creating ${dst}`);
18
+ cpSync(`${cwd}/${src}`, `${projectRoot}/${dst}`);
19
+ }
20
+ }
21
+ function createDir(path) {
22
+ if (!existsSync(`${projectRoot}/${path}`)) {
23
+ console.log(`Creating directory ${projectRoot}/${path}`);
24
+ mkdirSync(`${projectRoot}/${path}`);
25
+ }
26
+ }
27
+ function createTsconfig() {
28
+ const tsconfigPath = `${projectRoot}/tsconfig.json`;
29
+ const exists = existsSync(tsconfigPath);
30
+ const paths = {
31
+ "/assets/ts/*": ["./assets/ts/*"],
32
+ "/assets/client-js/*": ["./system/*"],
33
+ "@structured/*": [
34
+ "./node_modules/structured-fw/build/system/server/*",
35
+ "./node_modules/structured-fw/build/system/client/*",
36
+ "./node_modules/structured-fw/build/system/*",
37
+ "./system/server/*",
38
+ "./system/client/*",
39
+ "./system/*",
40
+ ]
41
+ };
42
+ if (exists) {
43
+ console.log('Updating tsconfig.json, adding @structured to compilerOptions.paths');
44
+ const config = JSON.parse(readFileSync(tsconfigPath).toString());
45
+ if (!config.compilerOptions) {
46
+ config.compilerOptions = {};
47
+ }
48
+ if (!config.compilerOptions.paths) {
49
+ config.compilerOptions.paths = paths;
50
+ }
51
+ writeFileSync(tsconfigPath, JSON.stringify(config, null, 4));
52
+ }
53
+ else {
54
+ console.log('Creating tsconfig.json');
55
+ const config = {
56
+ "compilerOptions": {
57
+ "noImplicitAny": true,
58
+ "noUnusedLocals": true,
59
+ "noImplicitReturns": true,
60
+ "alwaysStrict": true,
61
+ "strictNullChecks": true,
62
+ "strictPropertyInitialization": true,
63
+ "strictBindCallApply": true,
64
+ "moduleResolution": "bundler",
65
+ "outDir": "./build",
66
+ "module": "ES2020",
67
+ "target": "ES2021",
68
+ "allowSyntheticDefaultImports": true,
69
+ "preserveSymlinks": true,
70
+ "removeComments": true,
71
+ "baseUrl": ".",
72
+ "rootDir": ".",
73
+ paths
74
+ },
75
+ "include": ["./system/**/*", "./app/**/*", "./assets/ts/**/*", "index.ts"]
76
+ };
77
+ writeFileSync(tsconfigPath, JSON.stringify(config, null, 4));
78
+ }
79
+ }
80
+ if (command === 'init') {
81
+ console.log('Setting up a basic Structured boilerplate...');
82
+ createDir('app');
83
+ createDir('app/routes');
84
+ createDir('app/views');
85
+ createDir('app/models');
86
+ createDir('app/lib');
87
+ copyIfNotExists('index.ts');
88
+ copyIfNotExists('Config.ts');
89
+ copyIfNotExists('app/Types.ts');
90
+ createTsconfig();
91
+ console.log(`Structured initialized, you can run "tsc" to build`);
92
+ }
93
+ else {
94
+ console.log(`Command "${command}" not recognized`);
95
+ }
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "license": "MIT",
15
15
  "type": "module",
16
16
  "main": "build/index",
17
- "version": "0.7.8",
17
+ "version": "0.7.9",
18
18
  "scripts": {
19
19
  "develop": "tsc --watch",
20
20
  "startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,css index.js",
@@ -23,7 +23,7 @@
23
23
  "postinstall": "echo \"Run npx structured init\" to create application boilerplate"
24
24
  },
25
25
  "bin": {
26
- "structured": "./bin/structured"
26
+ "structured": "./build/system/bin/structured"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/mime-types": "^2.1.4",
@@ -18,7 +18,7 @@ if (process.argv.length < 3) {
18
18
 
19
19
  const command = process.argv[2];
20
20
 
21
- function copyIfNotExists(src, dst) {
21
+ function copyIfNotExists(src: string, dst?: string) {
22
22
  if (typeof dst !== 'string') {
23
23
  dst = src;
24
24
  }
@@ -28,7 +28,7 @@ function copyIfNotExists(src, dst) {
28
28
  }
29
29
  }
30
30
 
31
- function createDir(path) {
31
+ function createDir(path: string) {
32
32
  if (! existsSync(`${projectRoot}/${path}`)) {
33
33
  console.log(`Creating directory ${projectRoot}/${path}`);
34
34
  mkdirSync(`${projectRoot}/${path}`);
@@ -98,14 +98,14 @@ function createTsconfig() {
98
98
 
99
99
  if (command === 'init') {
100
100
  console.log('Setting up a basic Structured boilerplate...');
101
- copyIfNotExists('index.ts');
102
- copyIfNotExists('Config.ts');
103
101
  createDir('app');
104
102
  createDir('app/routes');
105
103
  createDir('app/views');
106
104
  createDir('app/models');
107
105
  createDir('app/lib');
108
-
106
+ copyIfNotExists('index.ts');
107
+ copyIfNotExists('Config.ts');
108
+ copyIfNotExists('app/Types.ts');
109
109
  createTsconfig();
110
110
 
111
111
  console.log(`Structured initialized, you can run "tsc" to build`);