oc-template-solid-compiler 0.4.0 → 0.6.0

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
+ export * from './lib/compile';
2
+ export * from 'oc-template-solid';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/compile"), exports);
18
+ __exportStar(require("oc-template-solid"), exports);
@@ -0,0 +1,3 @@
1
+ import { createCompile } from 'oc-generic-template-compiler';
2
+ export type CompilerOptions = ReturnType<typeof createCompile>;
3
+ export declare const compile: CompilerOptions;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.compile = void 0;
7
+ const oc_generic_template_compiler_1 = require("oc-generic-template-compiler");
8
+ const oc_statics_compiler_1 = __importDefault(require("oc-statics-compiler"));
9
+ const oc_template_solid_1 = require("oc-template-solid");
10
+ const oc_vite_compiler_1 = require("oc-vite-compiler");
11
+ const vite_plugin_solid_1 = __importDefault(require("vite-plugin-solid"));
12
+ const solidOCProviderTemplate_1 = __importDefault(require("./solidOCProviderTemplate"));
13
+ const htmlTemplate_1 = __importDefault(require("./htmlTemplate"));
14
+ exports.compile = (0, oc_generic_template_compiler_1.createCompile)({
15
+ compileView: (options, cb) => (0, oc_vite_compiler_1.viteView)({
16
+ ...options,
17
+ plugins: [(0, vite_plugin_solid_1.default)()],
18
+ viewWrapper: ({ viewPath }) => (0, solidOCProviderTemplate_1.default)({ viewPath }),
19
+ htmlTemplate: htmlTemplate_1.default,
20
+ externals: (0, oc_template_solid_1.getInfo)().externals
21
+ }, cb),
22
+ compileServer: oc_vite_compiler_1.viteServer,
23
+ compileStatics: oc_statics_compiler_1.default,
24
+ getInfo: oc_template_solid_1.getInfo
25
+ });
26
+ // OPTIONS
27
+ // =======
28
+ // componentPath
29
+ // componentPackage,
30
+ // logger,
31
+ // minify
32
+ // ocPackage
33
+ // publishPath
34
+ // verbose,
35
+ // watch,
36
+ // production
@@ -0,0 +1,10 @@
1
+ export default function viewTemplate({ templateId, css, bundle, hash }: {
2
+ templateId: string;
3
+ css: string;
4
+ externals: Array<{
5
+ name: string;
6
+ global: string;
7
+ }>;
8
+ bundle: string;
9
+ hash: string;
10
+ }): string;
@@ -1,6 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const escapeCSS = require('cssesc');
2
-
3
- const viewTemplate = ({ templateId, css, bundle, hash }) => `function(model){
4
+ function viewTemplate({ templateId, css, bundle, hash }) {
5
+ return `function(model){
4
6
  oc.solidComponents = oc.solidComponents || {};
5
7
  oc.solidComponents['${hash}'] = oc.solidComponents['${hash}'] || (${bundle});
6
8
  if (!model) return;
@@ -25,5 +27,5 @@ const viewTemplate = ({ templateId, css, bundle, hash }) => `function(model){
25
27
  '});' +
26
28
  '</script>'
27
29
  }`;
28
-
29
- module.exports = viewTemplate;
30
+ }
31
+ exports.default = viewTemplate;
@@ -0,0 +1,3 @@
1
+ export default function solidOCProviderTemplate({ viewPath }: {
2
+ viewPath: string;
3
+ }): string;
@@ -1,9 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const removeExtension = (path) => path.replace(/\.(t|j)sx?$/, '');
2
-
3
- const solidOCProviderTemplate = ({ viewPath }) => `
4
+ function solidOCProviderTemplate({ viewPath }) {
5
+ return `
4
6
  import { render } from 'solid-js/web';
5
7
  import View from '${removeExtension(viewPath)}';
6
- import { DataProvider } from 'oc-template-solid-compiler/utils/useData'
8
+ import { DataProvider } from 'oc-template-solid-compiler/dist/utils/useData'
7
9
 
8
10
  function OCProvider(props: any): any {
9
11
  const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = props;
@@ -20,8 +22,8 @@ const solidOCProviderTemplate = ({ viewPath }) => `
20
22
  if (err) {
21
23
  return cb(err);
22
24
  }
23
- const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = (data.solidComponent.props as any);
24
- cb(null, rest, data.solidComponent.props);
25
+ const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = (data.component.props as any);
26
+ cb(null, rest, data.component.props);
25
27
  });
26
28
  }
27
29
 
@@ -51,5 +53,5 @@ const solidOCProviderTemplate = ({ viewPath }) => `
51
53
 
52
54
  export default renderer;
53
55
  `;
54
-
55
- module.exports = solidOCProviderTemplate;
56
+ }
57
+ exports.default = solidOCProviderTemplate;
@@ -0,0 +1,7 @@
1
+ type PromiseData<T = any> = T & {
2
+ getData<O = any>(parameters?: Partial<T>): Promise<O>;
3
+ getSetting(setting: 'name' | 'version' | 'baseUrl' | 'staticPath'): string;
4
+ };
5
+ export declare const DataProvider: (props: any) => import("solid-js").JSX.Element;
6
+ export declare function useData<T = any>(): PromiseData<T>;
7
+ export {};
@@ -0,0 +1,24 @@
1
+ import { createContext, useContext } from 'solid-js';
2
+ const DataContext = createContext({});
3
+ export const DataProvider = (props) => {
4
+ // @ts-ignore children props
5
+ return <DataContext.Provider value={props.value}>{props.children}</DataContext.Provider>;
6
+ };
7
+ export function useData() {
8
+ const { getData, ...rest } = useContext(DataContext);
9
+ function asyncGetData(data) {
10
+ return new Promise((resolve, reject) => {
11
+ // @ts-ignore
12
+ getData({ ...rest, ...data }, (err, newData) => {
13
+ if (err) {
14
+ reject(err);
15
+ }
16
+ else {
17
+ resolve(newData);
18
+ }
19
+ });
20
+ });
21
+ }
22
+ // @ts-ignore
23
+ return { getData: asyncGetData, ...rest };
24
+ }
package/package.json CHANGED
@@ -1,16 +1,22 @@
1
1
  {
2
2
  "name": "oc-template-solid-compiler",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc && tsc --project tsconfig.solid.json",
9
+ "prepare": "npm run build",
10
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
11
+ },
6
12
  "repository": {
7
13
  "type": "git",
8
- "url": "https://github.com/guestlinelabs/oc-template-solid.git"
14
+ "url": "https://github.com/opencomponents/vite-templates.git"
9
15
  },
10
16
  "bugs": {
11
- "url": "https://github.com/guestlinelabs/oc-template-solid/issues"
17
+ "url": "https://github.com/opencomponents/vite-templates/issues"
12
18
  },
13
- "homepage": "https://github.com/guestlinelabs/oc-template-solid#readme",
19
+ "homepage": "https://github.com/opencomponents/vite-templates#readme",
14
20
  "keywords": [
15
21
  "oc",
16
22
  "opencomponents",
@@ -22,29 +28,23 @@
22
28
  "email": "mkredz@gmail.com"
23
29
  },
24
30
  "license": "MIT",
25
- "types": "./lib/oc-app.d.ts",
26
31
  "dependencies": {
27
32
  "chalk": "^3.0.0",
28
33
  "cssesc": "^3.0.0",
29
34
  "immer": "^9.0.6",
30
- "oc-generic-template-compiler": "2.1.0",
31
- "oc-statics-compiler": "2.0.10",
32
- "oc-template-solid": "0.0.1",
33
- "oc-vite-compiler": "^2.1.0",
35
+ "oc-generic-template-compiler": "2.1.1",
36
+ "oc-statics-compiler": "2.1.1",
37
+ "oc-template-solid": "0.1.0",
38
+ "oc-vite-compiler": "3.0.0",
34
39
  "resolve": "^1.20.0",
35
- "solid-js": "^1.7.8",
36
- "vite-plugin-solid": "^2.7.0"
40
+ "solid-js": "^1.8.7",
41
+ "vite-plugin-solid": "^2.8.0"
37
42
  },
38
43
  "files": [
39
- "index.js",
40
- "lib",
41
- "utils",
42
- "scaffold",
43
- "README.md",
44
- "LICENSE"
44
+ "dist/**",
45
+ "scaffold"
45
46
  ],
46
47
  "devDependencies": {
47
- "fs-extra": "^10.0.0",
48
48
  "lodash": "^4.17.4",
49
49
  "prettier": "^2.3.2",
50
50
  "prettier-config-guestline": "2.0.0"
@@ -5,8 +5,7 @@
5
5
  "scripts": {
6
6
  "lint": "eslint --max-warnings 0 --ext .js,.jsx,.ts,.tsx src",
7
7
  "build": "tsc --noEmit && oc package .",
8
- "test": "vitest",
9
- "start": "oc dev .. --components sold"
8
+ "test": "vitest"
10
9
  },
11
10
  "oc": {
12
11
  "files": {
@@ -34,9 +33,9 @@
34
33
  "@testing-library/jest-dom": "^5.16.5",
35
34
  "@types/testing-library__jest-dom": "^5.14.5",
36
35
  "jsdom": "^21.1.1",
37
- "oc-template-solid": "0.0.1",
36
+ "oc-server": "*",
38
37
  "oc-template-solid-compiler": "0.4.0",
39
- "solid-js": "^1.7.0",
38
+ "solid-js": "^1.8.7",
40
39
  "typescript": "5.0.2",
41
40
  "vitest": "^0.29.7"
42
41
  }
@@ -1,6 +1,6 @@
1
1
  import { describe, it, afterEach, beforeEach, expect, vi } from 'vitest';
2
2
  import { render } from '@solidjs/testing-library';
3
- import { DataProvider } from 'oc-template-solid-compiler/utils/useData';
3
+ import { DataProvider } from 'oc-template-solid-compiler/dist/utils/useData';
4
4
 
5
5
  import App from './App';
6
6
 
@@ -24,7 +24,7 @@ describe('App - Page', () => {
24
24
  lastName: 'lastName',
25
25
  userId: 0,
26
26
  getData,
27
- getSetting,
27
+ getSetting
28
28
  }}
29
29
  >
30
30
  <App />
@@ -1,5 +1,6 @@
1
1
  import { createSignal, Show, For } from 'solid-js';
2
- import { useData } from 'oc-template-solid-compiler/utils/useData';
2
+ import { useData } from 'oc-template-solid-compiler/dist/utils/useData';
3
+ import { serverClient } from 'oc-server';
3
4
  import styles from './styles.css';
4
5
  import type { AdditionalData, ClientProps } from './types';
5
6
 
@@ -8,41 +9,33 @@ interface AppProps extends ClientProps {
8
9
  }
9
10
 
10
11
  const App = () => {
11
- const { firstName, lastName, userId, getData, getSetting } =
12
- useData<AppProps>();
12
+ const { firstName, lastName, userId, getSetting } = useData<AppProps>();
13
13
  const staticPath = getSetting('staticPath');
14
- const [additionalData, setAdditionalData] =
15
- createSignal<AdditionalData | null>(null);
14
+ const [additionalData, setAdditionalData] = createSignal<AdditionalData | null>(null);
16
15
  const [error, setError] = createSignal('');
17
16
 
18
- function handleClick() {
19
- getData({ userId, getMoreData: true })
20
- .then((response) => setAdditionalData(response))
21
- .catch((err) => setError(err));
17
+ async function handleClick() {
18
+ const data = await serverClient.getMoreData({ userId });
19
+
20
+ try {
21
+ setAdditionalData(data);
22
+ } catch (error) {
23
+ setError(String(error));
24
+ }
22
25
  }
23
26
 
24
27
  return (
25
28
  <Show when={!error()} fallback={<div>Something wrong happened!</div>}>
26
29
  <div class={styles.container}>
27
- <img
28
- width="50"
29
- height="50"
30
- src={`${staticPath}/public/logo.png`}
31
- alt="Logo"
32
- />
30
+ <img width="50" height="50" src={`${staticPath}/public/logo.png`} alt="Logo" />
33
31
  <h1 style={{ margin: '0 0 20px 0' }}>
34
- Hello,{' '}
35
- <span style={{ 'text-decoration': 'underline' }}>{firstName}</span>{' '}
36
- {lastName}
32
+ Hello, <span style={{ 'text-decoration': 'underline' }}>{firstName}</span> {lastName}
37
33
  </h1>
38
34
  <Show when={!!additionalData()}>
39
35
  <div class={styles.info}>
40
36
  <div class={styles.block}>Age: {additionalData()!.age}</div>
41
37
  <div class={styles.block}>
42
- Hobbies:{' '}
43
- <For each={additionalData()!.hobbies}>
44
- {(hobby) => <div>{hobby}</div>}
45
- </For>
38
+ Hobbies: <For each={additionalData()!.hobbies}>{(hobby) => <div>{hobby}</div>}</For>
46
39
  </div>
47
40
  </div>
48
41
  </Show>
@@ -1,2 +1 @@
1
- /// <reference types="oc-template-solid" />
2
- /// <reference types="vite/client" />
1
+ /// <reference types="oc-vite/client" />
@@ -1,5 +1,5 @@
1
- import { Context } from 'oc-template-solid-compiler';
2
- import { AdditionalData, ClientProps, OcParameters } from './types';
1
+ import { Server } from 'oc-server';
2
+ import { ClientProps, OcParameters } from './types';
3
3
 
4
4
  const database = [
5
5
  { name: 'John Doe', age: 34, hobbies: ['Swimming', 'Basketball'] },
@@ -10,25 +10,27 @@ async function getUser(userId: number) {
10
10
  return database[userId];
11
11
  }
12
12
 
13
- export async function data(
14
- context: Context<OcParameters>,
15
- callback: (error: any, data: ClientProps | AdditionalData) => void
16
- ) {
17
- const { userId } = context.params;
13
+ export const server = new Server(async (params: OcParameters): Promise<ClientProps> => {
14
+ const { userId } = params;
18
15
  const user = await getUser(userId);
19
- const shouldGetMoreData = context.params.getMoreData;
20
- const [firstName, lastName] = user.name.split(/\s+/);
21
-
22
- if (shouldGetMoreData) {
23
- return callback(null, {
24
- age: user.age,
25
- hobbies: user.hobbies
26
- });
27
- }
28
16
 
29
- return callback(null, {
17
+ const [firstName, lastName] = user.name.split(/\s+/);
18
+ return {
30
19
  userId,
31
20
  firstName,
32
21
  lastName
33
- });
22
+ };
23
+ }).action('getMoreData', async (params: OcParameters) => {
24
+ const { userId } = params;
25
+ const user = await getUser(userId);
26
+ return {
27
+ age: user.age,
28
+ hobbies: user.hobbies
29
+ };
30
+ });
31
+
32
+ declare module 'oc-server' {
33
+ interface Register {
34
+ server: typeof server;
35
+ }
34
36
  }
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- const compile = require('./lib/compile');
4
- const template = require('oc-template-solid');
5
-
6
- module.exports = {
7
- compile,
8
- getCompiledTemplate: template.getCompiledTemplate,
9
- getInfo: template.getInfo,
10
- render: template.render
11
- };
package/lib/compile.js DELETED
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- const createCompile = require('oc-generic-template-compiler').createCompile;
4
- const compileStatics = require('oc-statics-compiler');
5
- const getInfo = require('oc-template-solid').getInfo;
6
- const solid = require('vite-plugin-solid');
7
- const { viteView, viteServer } = require('oc-vite-compiler');
8
-
9
- const verifyTypeScriptSetup = require('./verifyConfig');
10
- const solidOCProviderTemplate = require('./solidOCProviderTemplate');
11
- const htmlTemplate = require('./htmlTemplate');
12
-
13
- const compiler = createCompile({
14
- compileView: (options, cb) =>
15
- viteView(
16
- {
17
- ...options,
18
- plugins: [solid()],
19
- viewWrapper: ({ viewPath }) => solidOCProviderTemplate({ viewPath }),
20
- htmlTemplate,
21
- externals: getInfo().externals
22
- },
23
- cb
24
- ),
25
- compileServer: viteServer,
26
- compileStatics,
27
- getInfo
28
- });
29
-
30
- const hasTsExtension = (file) => !!file.match(/\.tsx?$/);
31
-
32
- // OPTIONS
33
- // =======
34
- // componentPath
35
- // componentPackage,
36
- // logger,
37
- // minify
38
- // ocPackage
39
- // publishPath
40
- // verbose,
41
- // watch,
42
- // production
43
- module.exports = function compile(options, callback) {
44
- const viewFileName = options.componentPackage.oc.files.template.src;
45
- const serverFileName = options.componentPackage.oc.files.data;
46
- const usingTypescript = hasTsExtension(viewFileName) || hasTsExtension(serverFileName);
47
-
48
- if (usingTypescript) {
49
- verifyTypeScriptSetup(options.componentPath);
50
- }
51
-
52
- return compiler(options, callback);
53
- };
package/lib/oc-app.d.ts DELETED
@@ -1,72 +0,0 @@
1
- interface OC {
2
- conf: {
3
- templates: Array<{
4
- type: string;
5
- externals: string[];
6
- }>;
7
- };
8
- cmd: {
9
- push: (cb: (oc: OC) => void) => void;
10
- };
11
- events: {
12
- on: (eventName: string, fn: (...data: any[]) => void) => void;
13
- off: (eventName: string, fn?: (...data: any[]) => void) => void;
14
- fire: (eventName: string, data?: any) => void;
15
- reset: () => void;
16
- };
17
- renderNestedComponent: (ocElement: HTMLElement, cb: () => void) => void;
18
- }
19
-
20
- declare global {
21
- interface Window {
22
- oc: OC;
23
- }
24
-
25
- namespace JSX {
26
- interface IntrinsicElements {
27
- 'oc-component': React.DetailedHTMLProps<
28
- React.HTMLAttributes<HTMLElement> & { href: string },
29
- HTMLElement
30
- >;
31
- }
32
- }
33
- }
34
-
35
- export interface AcceptLanguage {
36
- code: string;
37
- script?: any;
38
- region: string;
39
- quality: number;
40
- }
41
-
42
- export interface Env {
43
- name: string;
44
- }
45
-
46
- export interface Plugins {}
47
-
48
- export interface External {
49
- global: string;
50
- url: string;
51
- name: string;
52
- }
53
-
54
- export interface Template {
55
- type: string;
56
- version: string;
57
- externals: External[];
58
- }
59
-
60
- export interface Context<T = any, E = Env> {
61
- acceptLanguage: AcceptLanguage[];
62
- baseUrl: string;
63
- env: E;
64
- params: T;
65
- plugins: Plugins;
66
- requestHeaders: Record<string, string>;
67
- requestIp: string;
68
- setEmptyResponse: () => void;
69
- setHeader: (header: string, value: string) => void;
70
- staticPath: string;
71
- templates: Template[];
72
- }
@@ -1,214 +0,0 @@
1
- const chalk = require('chalk');
2
- const fs = require('fs');
3
- const resolve = require('resolve');
4
- const path = require('path');
5
- const os = require('os');
6
- const immer = require('immer').produce;
7
-
8
- function writeJson(fileName, object) {
9
- fs.writeFileSync(fileName, JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL);
10
- }
11
-
12
- function verifyTypeScriptSetup(componentPath) {
13
- const paths = {
14
- appTsConfig: path.resolve(componentPath, 'tsconfig.json'),
15
- yarnLockFile: path.resolve(componentPath, 'yarn.lock'),
16
- appNodeModules: path.resolve(componentPath, 'node_modules'),
17
- appTypeDeclarations: path.resolve(componentPath, 'src', 'oc-app.d.ts')
18
- };
19
- let firstTimeSetup = false;
20
-
21
- if (!fs.existsSync(paths.appTsConfig)) {
22
- writeJson(paths.appTsConfig, {});
23
- firstTimeSetup = true;
24
- }
25
-
26
- const isYarn = fs.existsSync(paths.yarnLockFile);
27
-
28
- // Ensure typescript is installed
29
- let ts;
30
- try {
31
- ts = require(resolve.sync('typescript', {
32
- basedir: paths.appNodeModules
33
- }));
34
- } catch (_) {
35
- console.error(
36
- chalk.bold.red(
37
- `It looks like you're trying to use TypeScript but do not have ${chalk.bold(
38
- 'typescript'
39
- )} installed.`
40
- )
41
- );
42
- console.error(
43
- chalk.bold(
44
- 'Please install',
45
- chalk.cyan.bold('typescript'),
46
- 'by running',
47
- chalk.cyan.bold(isYarn ? 'yarn add typescript' : 'npm install typescript') + '.'
48
- )
49
- );
50
- console.error();
51
- process.exit(1);
52
- }
53
-
54
- const compilerOptions = {
55
- // These are suggested values and will be set when not present in the
56
- // tsconfig.json
57
- // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent()
58
- target: {
59
- parsedValue: ts.ScriptTarget.ES5,
60
- suggested: 'es5'
61
- },
62
- lib: { suggested: ['dom', 'dom.iterable', 'esnext'] },
63
- allowJs: { suggested: true },
64
- skipLibCheck: { suggested: true },
65
- esModuleInterop: { suggested: true },
66
- allowSyntheticDefaultImports: { suggested: true },
67
- strict: { suggested: true },
68
- forceConsistentCasingInFileNames: { suggested: true },
69
- // TODO: Enable for v4.0 (#6936)
70
- // noFallthroughCasesInSwitch: { suggested: true },
71
-
72
- // These values are required and cannot be changed by the user
73
- // Keep this in sync with the rollup config
74
- module: {
75
- parsedValue: ts.ModuleKind.ESNext,
76
- value: 'esnext',
77
- reason: 'for import() and import/export'
78
- },
79
- moduleResolution: {
80
- parsedValue: ts.ModuleResolutionKind.NodeJs,
81
- value: 'node',
82
- reason: 'to match rollup resolution'
83
- },
84
- resolveJsonModule: { value: true, reason: 'to match rollup loader' },
85
- isolatedModules: { value: true, reason: 'implementation limitation' },
86
- jsx: {
87
- parsedValue: ts.JsxEmit.Preserve,
88
- suggested: 'preserve'
89
- },
90
- jsxImportSource: {
91
- suggested: 'solid-js'
92
- },
93
- paths: { value: undefined, reason: 'aliased imports are not supported' }
94
- };
95
-
96
- const formatDiagnosticHost = {
97
- getCanonicalFileName: (fileName) => fileName,
98
- getCurrentDirectory: ts.sys.getCurrentDirectory,
99
- getNewLine: () => os.EOL
100
- };
101
-
102
- const messages = [];
103
- let appTsConfig;
104
- let parsedTsConfig;
105
- let parsedCompilerOptions;
106
- try {
107
- const { config: readTsConfig, error } = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile);
108
-
109
- if (error) {
110
- throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));
111
- }
112
-
113
- appTsConfig = readTsConfig;
114
-
115
- // Get TS to parse and resolve any "extends"
116
- // Calling this function also mutates the tsconfig above,
117
- // adding in "include" and "exclude", but the compilerOptions remain untouched
118
- let result;
119
- parsedTsConfig = immer(readTsConfig, (config) => {
120
- result = ts.parseJsonConfigFileContent(config, ts.sys, path.dirname(paths.appTsConfig));
121
- });
122
-
123
- if (result.errors && result.errors.length) {
124
- throw new Error(ts.formatDiagnostic(result.errors[0], formatDiagnosticHost));
125
- }
126
-
127
- parsedCompilerOptions = result.options;
128
- } catch (e) {
129
- if (e && e.name === 'SyntaxError') {
130
- console.error(
131
- chalk.red.bold(
132
- 'Could not parse',
133
- chalk.cyan('tsconfig.json') + '.',
134
- 'Please make sure it contains syntactically correct JSON.'
135
- )
136
- );
137
- }
138
-
139
- console.log(e && e.message ? `${e.message}` : '');
140
- process.exit(1);
141
- }
142
-
143
- if (appTsConfig.compilerOptions == null) {
144
- appTsConfig.compilerOptions = {};
145
- firstTimeSetup = true;
146
- }
147
-
148
- for (const option of Object.keys(compilerOptions)) {
149
- const { parsedValue, value, suggested, reason } = compilerOptions[option];
150
-
151
- const valueToCheck = parsedValue === undefined ? value : parsedValue;
152
- const coloredOption = chalk.cyan('compilerOptions.' + option);
153
-
154
- if (suggested != null) {
155
- if (parsedCompilerOptions[option] === undefined) {
156
- appTsConfig.compilerOptions[option] = suggested;
157
- messages.push(
158
- `${coloredOption} to be ${chalk.bold('suggested')} value: ${chalk.cyan.bold(
159
- suggested
160
- )} (this can be changed)`
161
- );
162
- }
163
- } else if (parsedCompilerOptions[option] !== valueToCheck) {
164
- appTsConfig.compilerOptions[option] = value;
165
- messages.push(
166
- `${coloredOption} ${chalk.bold(valueToCheck == null ? 'must not' : 'must')} be ${valueToCheck == null ? 'set' : chalk.cyan.bold(value)
167
- }` + (reason != null ? ` (${reason})` : '')
168
- );
169
- }
170
- }
171
-
172
- // tsconfig will have the merged "include" and "exclude" by this point
173
- if (parsedTsConfig.include == null) {
174
- appTsConfig.include = ['src'];
175
- messages.push(`${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`);
176
- }
177
-
178
- if (parsedTsConfig.exclude == null) {
179
- appTsConfig.exclude = ['src/_package'];
180
- messages.push(`${chalk.cyan('exclude')} should have ${chalk.cyan.bold('src/_package')}`);
181
- }
182
-
183
- if (messages.length > 0) {
184
- if (firstTimeSetup) {
185
- console.log(
186
- chalk.bold('Your', chalk.cyan('tsconfig.json'), 'has been populated with default values.')
187
- );
188
- console.log();
189
- } else {
190
- console.warn(
191
- chalk.bold(
192
- 'The following changes are being made to your',
193
- chalk.cyan('tsconfig.json'),
194
- 'file:'
195
- )
196
- );
197
- messages.forEach((message) => {
198
- console.warn(' - ' + message);
199
- });
200
- console.warn();
201
- }
202
- writeJson(paths.appTsConfig, appTsConfig);
203
- }
204
-
205
- // Reference `oc-template-solid-compiler` types
206
- if (!fs.existsSync(paths.appTypeDeclarations)) {
207
- fs.writeFileSync(
208
- paths.appTypeDeclarations,
209
- `/// <reference types="oc-template-solid" />${os.EOL}`
210
- );
211
- }
212
- }
213
-
214
- module.exports = verifyTypeScriptSetup;
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["react-app"]
3
- }
@@ -1,13 +0,0 @@
1
- module.exports = {
2
- env: {
3
- commonjs: false
4
- },
5
- parserOptions: {
6
- ecmaVersion: 'latest',
7
- sourceType: 'module',
8
- ecmaFeatures: {
9
- jsx: true
10
- }
11
- },
12
- extends: '../../../.eslintrc.js'
13
- };
package/utils/useData.tsx DELETED
@@ -1,37 +0,0 @@
1
- import { createContext, useContext } from 'solid-js';
2
-
3
- const DataContext = createContext<any>({});
4
-
5
- type Data<T = any> = T & {
6
- getData(parameters: T, cb: (err: Error | null, data: any) => void): void;
7
- getSetting(setting: 'name' | 'version' | 'baseUrl' | 'staticPath'): string;
8
- };
9
-
10
- type PromiseData<T = any> = T & {
11
- getData<O = any>(parameters?: Partial<T>): Promise<O>;
12
- getSetting(setting: 'name' | 'version' | 'baseUrl' | 'staticPath'): string;
13
- };
14
-
15
- export const DataProvider = (props: any) => {
16
- // @ts-ignore children props
17
- return <DataContext.Provider value={props.value}>{props.children}</DataContext.Provider>;
18
- };
19
-
20
- export function useData<T = any>(): PromiseData<T> {
21
- const { getData, ...rest }: Data<T> = useContext(DataContext);
22
- function asyncGetData<O = any, I = any>(data: I) {
23
- return new Promise<O>((resolve, reject) => {
24
- // @ts-ignore
25
- getData({ ...rest, ...data }, (err, newData) => {
26
- if (err) {
27
- reject(err);
28
- } else {
29
- resolve(newData);
30
- }
31
- });
32
- });
33
- }
34
-
35
- // @ts-ignore
36
- return { getData: asyncGetData, ...rest };
37
- }