소스 검색

[macs] added simple prototype

plusgut 7 년 전
커밋
7c20aee056
14개의 변경된 파일330개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      .gitignore
  2. 89 0
      config/karma.conf.js
  3. 53 0
      config/webpack.base.conf.js
  4. 10 0
      config/webpack.dev.conf.js
  5. 6 0
      config/webpack.prod.conf.js
  6. 22 0
      config/webpack.test.conf.js
  7. 11 0
      public/index.html
  8. 13 0
      src/App.test.tsx
  9. 26 0
      src/App.tsx
  10. 4 0
      src/index.tsx
  11. 27 0
      src/macs.ts
  12. 61 0
      tsconfig.json
  13. 3 0
      tslint.json
  14. 4 0
      yarn.lock

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+node_modules

+ 89 - 0
config/karma.conf.js

@@ -0,0 +1,89 @@
+var webpackConfig = require("./webpack.test.conf.js");
+var path = require('path');
+
+module.exports = function karmaConfig(config) {
+
+  var configuration = {
+
+    // base path that will be used to resolve all patterns (eg. files, exclude)
+    basePath: '../dist/',
+
+    // frameworks to use
+    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
+    frameworks: ['jasmine'],
+
+    // list of files / patterns to load in the browser
+    files: [
+      require.resolve('plusnew'),
+      '../configs/karma/globalEnzyme.ts',
+      '../src/**/*.test.tsx',
+      '../src/**/*.test.ts',
+      { pattern: '**/*', watched: true, included: false, served: true, nocache: false }
+    ],
+
+    // webpack: webpackConfig,
+
+    // list of files to exclude
+    exclude: [],
+
+    // // preprocess matching files before serving them to the browser
+    // // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
+    preprocessors:
+      {
+        '../configs/karma/globalEnzyme.ts': ['webpack'],
+        '../src/**/*.test.tsx': ['webpack', 'sourcemap'],
+        '../src/**/*.test.ts': ['webpack', 'sourcemap'],
+      },
+
+    // test results reporter to use
+    // possible values: 'dots', 'progress'
+    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+    reporters: ['progress', 'coverage-istanbul'],
+
+    coverageIstanbulReporter: {
+      reports: ['html', 'lcov', 'text-summary'],
+      dir: path.join(__dirname, '..', 'coverage'),
+    },
+
+    // web server port
+    port: 9876,
+
+    // enable / disable colors in the output (reporters and logs)
+    colors: true,
+
+    // level of logging
+    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+    logLevel: config.LOG_INFO,
+
+    // enable / disable watching file and executing tests whenever any file changes
+    autoWatch: false,
+
+    // start these browsers
+    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+    browsers: ['ChromeHeadless'],
+
+    // Continuous Integration mode
+    // if true, Karma captures browsers, runs the tests and exits
+    singleRun: true,
+
+    // Concurrency level
+    // how many browser should be started simultaneous
+    concurrency: Infinity,
+
+    plugins: [
+      'karma-webpack',
+      'karma-jasmine',
+      'karma-sourcemap-loader',
+      'karma-coverage-istanbul-reporter',
+      'karma-chrome-launcher',
+    ],
+
+    mime: {
+      'text/x-typescript': ['ts', 'tsx']
+    },
+
+    webpack: webpackConfig,
+  };
+
+  config.set(configuration);
+};

+ 53 - 0
config/webpack.base.conf.js

@@ -0,0 +1,53 @@
+const path = require('path');
+const CopyWebpackPlugin = require('copy-webpack-plugin');
+const CleanWebpackPlugin = require("clean-webpack-plugin")
+const { TsConfigPathsPlugin } = require('awesome-typescript-loader');
+
+module.exports = {
+  entry: ['./src/index.tsx'],
+  mode: 'development',
+  output: {
+      path: __dirname + '/../dist',
+      filename: 'app.js'
+  },
+  resolve: {
+    extensions: ['.ts', '.tsx', '.js', '.jsx'],
+    plugins: [new TsConfigPathsPlugin()],
+  },
+  devtool: 'source-map',
+  module: {
+    rules: [
+      {
+        test: /\.tsx?$/,
+        loader: 'awesome-typescript-loader',
+      },
+    ]
+  },
+  plugins: [
+    new CopyWebpackPlugin([
+      { from: 'public' },
+      {
+        from: require.resolve('plusnew'),
+        to: 'plusnew.js',
+      }
+    ]),
+    new CleanWebpackPlugin('dist', {
+        root: path.join(__dirname, '..'),
+      }
+    ),
+  ],
+  externals: [
+    function (context, request, callback) {
+      const contextParts = path.parse(context);
+      if (request === 'plusnew' || (request === 'enzyme' && contextParts.base !== 'karma')) {
+        return callback(null, request);
+      } else if (request === '__dirname') { // This module creates a string for each module, in what directory it is existent
+        // const dirname = context.slice(path.resolve(__dirname, '../../src').length + 1);
+
+        const lastDir = path.parse(context).name;
+        return callback(null, JSON.stringify({ default: lastDir }));
+      }
+      callback();
+    },
+  ],
+};

+ 10 - 0
config/webpack.dev.conf.js

@@ -0,0 +1,10 @@
+const config = require('./webpack.base.conf.js');
+
+module.exports = {
+  ...config,
+  mode: "development",
+  devServer: {
+    port: 3000,
+    clientLogLevel: "info",
+  }
+}

+ 6 - 0
config/webpack.prod.conf.js

@@ -0,0 +1,6 @@
+const config = require('./webpack.base.conf.js');
+
+module.exports = {
+  ...config,
+  mode: 'production',
+};

+ 22 - 0
config/webpack.test.conf.js

@@ -0,0 +1,22 @@
+const config = require('./webpack.base.conf.js');
+const webpack = require('webpack');
+const path = require('path');
+
+config.externals = {};
+
+config.plugins.push(
+  new webpack.SourceMapDevToolPlugin({
+    filename: null, // if no value is provided the sourcemap is inlined
+    test: /\.(ts|tsx)($|\?)/i // process .js and .ts files only
+  })
+);
+
+config.module.rules.push({
+  enforce: 'post',
+  test: /\.(ts|tsx)$/,
+  loader: 'istanbul-instrumenter-loader',
+  include: path.resolve('src/'),
+  exclude: /\.test\.(ts|tsx)$/,
+});
+
+module.exports = config;

+ 11 - 0
public/index.html

@@ -0,0 +1,11 @@
+<html>
+  <head>
+    <title>plusnew app</title>
+  </head>
+  <body>
+    <div id="app"></div>
+    <script type="text/javascript" src="plusnew.js"></script>
+    <script type="text/javascript" src="app.js"></script>
+  </body>
+
+</html>

+ 13 - 0
src/App.test.tsx

@@ -0,0 +1,13 @@
+import enzymeAdapterPlusnew, { mount } from 'enzyme-adapter-plusnew';
+import { configure } from 'enzyme';
+import plusnew from 'plusnew';
+import App from './App';
+
+configure({ adapter: new enzymeAdapterPlusnew() });
+
+describe('test App.tsx', () => {
+  it('button should be found', () => {
+    const wrapper = mount(<App />);
+    expect(wrapper.containsMatchingElement(<button>count</button>)).toBe(true);
+  });
+});

+ 26 - 0
src/App.tsx

@@ -0,0 +1,26 @@
+import plusnew, { component, store } from 'plusnew';
+import { list, stream } from './macs';
+
+export default component(
+  'App',
+  () => {
+    const local = store(list, (state, action: string) => state.concat(action));
+
+    const reader = stream.getReader();
+
+    reader.read().then(function processData({ value }: { value: string, done: boolean}) {
+      local.dispatch(value);
+      return reader.read().then(processData);
+    });
+
+    return (
+      <ul>
+        <local.Observer render={items =>
+          items.map((item, index) =>
+            <li key={index}>{item}</li>,
+          )
+        } />
+      </ul>
+    );
+  },
+);

+ 4 - 0
src/index.tsx

@@ -0,0 +1,4 @@
+import plusnew from 'plusnew';
+import App from './App';
+
+plusnew.render(<App />,  document.getElementById('app') as HTMLElement);

+ 27 - 0
src/macs.ts

@@ -0,0 +1,27 @@
+const iterator = {
+  [Symbol.iterator]: () => {
+    let index = 0;
+    return {
+      next: () => {
+        index += 1;
+        if (index > 40000) {
+          return { done: true, value: index + '' };
+        }
+        return { done: false, value: index + '' };
+      },
+    };
+  },
+};
+
+const stream = new (ReadableStream as any)({
+  start(controller: any) {
+    let i = 40000;
+    setInterval(() => {
+      i += 1;
+      controller.enqueue(i + '');
+    }, 100);
+  },
+});
+
+const list = Array.from(iterator);
+export { list, stream };

+ 61 - 0
tsconfig.json

@@ -0,0 +1,61 @@
+{
+  "files": [
+    "node_modules/enzyme-adapter-plusnew/src/enzyme.d.ts"
+  ],
+  "include": [
+    "src",
+  ],
+  "compilerOptions": {
+    /* Basic Options */
+    "target": "es6",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
+    "module": "commonjs",                     /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
+    // "lib": [],                             /* Specify library files to be included in the compilation:  */
+    // "allowJs": true,                       /* Allow javascript files to be compiled. */
+    // "checkJs": true,                       /* Report errors in .js files. */
+    "jsx": "react",                           /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
+    "reactNamespace": "plusnew",
+    // "declaration": true,                   /* Generates corresponding '.d.ts' file. */
+    // "sourceMap": true,                     /* Generates corresponding '.map' file. */
+    // "outFile": "./",                       /* Concatenate and emit output to single file. */
+    "outDir": "./dist/",                      /* Redirect output structure to the directory. */
+    // "rootDir": "./",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
+    // "removeComments": true,                /* Do not emit comments to output. */
+    // "noEmit": true,                        /* Do not emit outputs. */
+    // "importHelpers": true,                 /* Import emit helpers from 'tslib'. */
+    // "downlevelIteration": true,            /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
+    // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
+
+    /* Strict Type-Checking Options */
+    "strict": true,                           /* Enable all strict type-checking options. */
+    "noImplicitAny": true,                    /* Raise error on expressions and declarations with an implied 'any' type. */
+    "strictNullChecks": true,                 /* Enable strict null checks. */
+    "noImplicitThis": true,                   /* Raise error on 'this' expressions with an implied 'any' type. */
+    "alwaysStrict": true,                     /* Parse in strict mode and emit "use strict" for each source file. */
+
+    /* Additional Checks */
+    "noUnusedLocals": true,                   /* Report errors on unused locals. */
+    "noUnusedParameters": false,              /* Report errors on unused parameters. */
+    "noImplicitReturns": true,                /* Report error when not all code paths in function return a value. */
+    "noFallthroughCasesInSwitch": true,       /* Report errors for fallthrough cases in switch statement. */
+
+    /* Module Resolution Options */
+    // "moduleResolution": "node",            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
+    "baseUrl": "./src/"                       /* Base directory to resolve non-absolute module names. */
+    // "paths": {},                           /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
+    // "rootDirs": [],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
+    // "typeRoots": [],                       /* List of folders to include type definitions from. */
+    // "types": [],                           /* Type declaration files to be included in compilation. */
+    // "allowSyntheticDefaultImports": true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
+    // "preserveSymlinks": true,              /* Do not resolve the real path of symlinks. */
+
+    /* Source Map Options */
+    // "sourceRoot": "./",                    /* Specify the location where debugger should locate TypeScript files instead of source locations. */
+    // "mapRoot": "./",                       /* Specify the location where debugger should locate map files instead of generated locations. */
+    // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
+    // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
+
+    /* Experimental Options */
+    // "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */
+    // "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */
+  }
+}

+ 3 - 0
tslint.json

@@ -0,0 +1,3 @@
+{
+  "extends": "tslint-config-airbnb"
+}

+ 4 - 0
yarn.lock

@@ -0,0 +1,4 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+