Skip to content

Commit 7c0a5d5

Browse files
Gulp for testing configured.
base-form registerForm error text updated.
1 parent 8676504 commit 7c0a5d5

File tree

16 files changed

+572
-290
lines changed

16 files changed

+572
-290
lines changed

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
{
2-
"name": "simplr-forms",
3-
"private": true,
4-
"scripts": {},
5-
"devDependencies": {
6-
"lerna": "2.0.0-rc.1",
7-
"typescript": "2.3.0"
8-
}
9-
}
1+
{
2+
"name": "simplr-forms",
3+
"private": true,
4+
"scripts": {},
5+
"devDependencies": {
6+
"babel-core": "^6.24.1",
7+
"babel-preset-es2015": "^6.24.1",
8+
"gulp": "github:gulpjs/gulp#4.0",
9+
"lerna": "2.0.0-rc.1",
10+
"typescript": "2.3.0",
11+
"webpack-stream": "^3.2.0"
12+
}
13+
}

packages/simplr-forms-core/package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,35 @@
1515
"release": "npm run build && npm run uglifyjs",
1616
"test": "jest",
1717
"test-watch": "jest --watchAll",
18-
"test-coverage": "npm test -- --coverage"
18+
"test-coverage": "npm test -- --coverage",
19+
"gulp-watch": "tsc -p ./tools/tsconfig.gulp.json -w"
1920
},
2021
"license": "AGPL-3.0",
2122
"files": [
22-
"!node_modules",
2323
"**/*.md",
2424
"*.js",
2525
"**/*.d.ts",
26-
"!*.config.js"
26+
"!*.config.js",
27+
"!gulpfile.js",
28+
"!node_modules/**"
2729
],
2830
"devDependencies": {
31+
"@types/chokidar": "^1.6.0",
2932
"@types/enzyme": "^2.7.9",
33+
"@types/gulp": "^4.0.2",
3034
"@types/jest": "^19.2.2",
3135
"@types/sinon": "^2.1.2",
36+
"@types/undertaker": "^0.12.28",
37+
"@types/vinyl-fs": "^2.4.5",
38+
"@types/webpack": "^2.2.15",
3239
"enzyme": "^2.8.2",
40+
"gulp": "github:gulpjs/gulp#4.0",
3341
"jest": "^19.0.2",
3442
"jest-enzyme": "^3.0.1",
3543
"on-build-webpack": "^0.1.0",
3644
"react-dom": "^15.5.4",
3745
"react-test-renderer": "^15.5.4",
46+
"simplr-mvdir": "0.0.1-beta.7",
3847
"sinon": "^2.1.0",
3948
"ts-jest": "^19.0.10",
4049
"ts-loader": "^2.0.3",

packages/simplr-forms-core/src/abstractions/base-form.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ export abstract class BaseForm<TProps extends FormContracts.FormProps, TState> e
7373
* Local helpers
7474
*/
7575
private registerForm(props: FormContracts.FormProps) {
76-
let shouldNotDestroy = !props.destroyOnUnmount;
7776
if (props.formId == null) {
78-
if (shouldNotDestroy) {
79-
throw new Error("simplr-forms-core: destroyOnUnmount cannot be truthy when formId is not set.");
77+
if (!props.destroyOnUnmount) {
78+
throw new Error("simplr-forms-core: destroyOnUnmount cannot be falsy when formId is not set.");
8079
} else {
8180
// props.formId is undefined, therefore this.FormId is generated by registering the form
8281
this.FormId = this.FormStoresHandler.RegisterForm(undefined, props.formStore);
8382
}
8483
} else {
85-
if (shouldNotDestroy) {
84+
if (!props.destroyOnUnmount) {
8685
// props.formId is given AND shouldNotDestroy AND form hasn't yet been registered
8786
if (this.FormStoresHandler.Exists(props.formId)) {
8887
// The form has already been registered and we can use the given id
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as gulp from "gulp";
2+
import * as path from "path";
3+
import * as webpack from "webpack";
4+
import * as webpackConfig from "./webpack.config";
5+
import * as process from "process";
6+
import * as childProcess from "child_process";
7+
import * as simplrMvDir from "simplr-mvdir";
8+
9+
const packageJson = require("./package.json");
10+
11+
const compiler = webpack(webpackConfig);
12+
const paths = {
13+
src: "./src",
14+
dist: "./dist",
15+
root: "."
16+
};
17+
18+
export function webpackTask() {
19+
return new Promise((resolve, reject) => {
20+
compiler.run((err, stats) => {
21+
if (err != null) {
22+
reject(err);
23+
return;
24+
}
25+
resolve();
26+
});
27+
});
28+
}
29+
30+
export async function moveFromDistTask() {
31+
const from = path.resolve(paths.dist);
32+
const to = path.resolve(paths.root);
33+
await simplrMvDir.move(from, to);
34+
}
35+
36+
export async function copyToJspm() {
37+
const jspmPath = `../simplr-forms-test/dist/jspm_packages/npm/simplr-forms-core@${packageJson.version}`;
38+
const outputPath = path.resolve(jspmPath);
39+
gulp.src(packageJson.files)
40+
.pipe(gulp.dest(outputPath));
41+
}
42+
43+
const buildTask = gulp.series(webpackTask, moveFromDistTask);
44+
45+
export function watchStartTask() {
46+
gulp.watch(paths.src, gulp.series(buildTask, copyToJspm));
47+
}
48+
49+
export const build = buildTask;
50+
export const watch = gulp.series(buildTask, copyToJspm, watchStartTask);
51+
52+
53+
54+
// tslint:disable-next-line:no-default-export
55+
export default buildTask;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"removeComments": false,
6+
"rootDir": ".",
7+
"outDir": "../",
8+
"jsx": "react",
9+
"sourceMap": false,
10+
"skipDefaultLibCheck": true,
11+
"declaration": false,
12+
"pretty": true,
13+
"strict": true,
14+
"lib": [
15+
"dom",
16+
"dom.iterable",
17+
"es6"
18+
]
19+
},
20+
"exclude": [
21+
"node_modules",
22+
"dist",
23+
"@types",
24+
"__tests__"
25+
]
26+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import * as path from "path";
2+
import * as childProcess from "child_process";
3+
4+
const packageJson = require("./package.json");
5+
6+
let externals: {
7+
[key: string]: any
8+
} = {};
9+
10+
for (const key in packageJson.dependencies) {
11+
if (packageJson.dependencies.hasOwnProperty(key)) {
12+
externals[key] = key;
13+
}
14+
}
15+
16+
const externalsResolver = [
17+
externals,
18+
function (context: string, request: string, callback: Function) {
19+
const directoriesToTest = [
20+
"abstractions",
21+
"actions",
22+
"stores",
23+
"utils"
24+
];
25+
26+
const tests = directoriesToTest.map(directory => ({
27+
regex: new RegExp(`.*/${directory}/.+$`),
28+
directory: directory
29+
}));
30+
31+
let passingTest;
32+
for (const test of tests) {
33+
if (test.regex.test(request)) {
34+
passingTest = test;
35+
}
36+
}
37+
38+
if (passingTest != null) {
39+
const resolvedPath = path.resolve(context, request);
40+
const shouldReplaceWithCustomResolve =
41+
request.indexOf("src") === -1 &&
42+
resolvedPath.indexOf(path.join(__dirname, `src/${passingTest.directory}`)) !== -1;
43+
44+
if (shouldReplaceWithCustomResolve) {
45+
const customResolve = `./${passingTest.directory}`;
46+
callback(null, customResolve);
47+
return;
48+
}
49+
}
50+
callback();
51+
}
52+
];
53+
54+
module.exports = {
55+
entry: {
56+
main: "./src/index.ts",
57+
abstractions: "./src/abstractions/index.ts",
58+
stores: "./src/stores/index.ts",
59+
actions: "./src/actions/index.ts",
60+
utils: "./src/utils/index.ts"
61+
},
62+
output: {
63+
filename: "./dist/[name].js",
64+
libraryTarget: "umd"
65+
},
66+
module: {
67+
rules: [
68+
{
69+
test: /\.tsx?$/,
70+
loader: "ts-loader",
71+
options: {
72+
}
73+
}
74+
]
75+
},
76+
resolve: {
77+
extensions: [".ts", ".tsx"]
78+
},
79+
externals: externalsResolver
80+
};

packages/simplr-forms-core/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"node_modules",
2222
"dist",
2323
"@types",
24-
"__tests__"
24+
"__tests__",
25+
"tools"
2526
]
26-
}
27+
}
Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,46 @@
1-
const packageJson = require("./package.json");
2-
const path = require("path");
3-
4-
const WebpackOnBuildPlugin = require('on-build-webpack');
5-
const childProcess = require('child_process');
6-
7-
let externals = {};
8-
9-
for (const key in packageJson.dependencies) {
10-
externals[key] = key;
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var path = require("path");
4+
var packageJson = require("./package.json");
5+
var externals = {};
6+
for (var key in packageJson.dependencies) {
7+
if (packageJson.dependencies.hasOwnProperty(key)) {
8+
externals[key] = key;
9+
}
1110
}
12-
13-
const externalsResolver = [
11+
var externalsResolver = [
1412
externals,
1513
function (context, request, callback) {
16-
const directoriesToTest = [
14+
var directoriesToTest = [
1715
"abstractions",
1816
"actions",
1917
"stores",
2018
"utils"
2119
];
22-
23-
const tests = directoriesToTest.map(directory => ({
24-
regex: new RegExp(`.*/${directory}/.+$`),
20+
var tests = directoriesToTest.map(function (directory) { return ({
21+
regex: new RegExp(".*/" + directory + "/.+$"),
2522
directory: directory
26-
}));
27-
28-
let passingTest;
29-
for (const test of tests) {
30-
if (test.regex.test(request)) {
31-
passingTest = test;
23+
}); });
24+
var passingTest;
25+
for (var _i = 0, tests_1 = tests; _i < tests_1.length; _i++) {
26+
var test_1 = tests_1[_i];
27+
if (test_1.regex.test(request)) {
28+
passingTest = test_1;
3229
}
3330
}
34-
3531
if (passingTest != null) {
36-
const resolvedPath = path.resolve(context, request);
37-
const shouldReplaceWithCustomResolve =
38-
request.indexOf("src") === -1 &&
39-
resolvedPath.indexOf(path.join(__dirname, `src/${passingTest.directory}`)) !== -1;
40-
32+
var resolvedPath = path.resolve(context, request);
33+
var shouldReplaceWithCustomResolve = request.indexOf("src") === -1 &&
34+
resolvedPath.indexOf(path.join(__dirname, "src/" + passingTest.directory)) !== -1;
4135
if (shouldReplaceWithCustomResolve) {
42-
const customResolve = `./${passingTest.directory}`;
36+
var customResolve = "./" + passingTest.directory;
4337
callback(null, customResolve);
4438
return;
4539
}
4640
}
4741
callback();
4842
}
4943
];
50-
51-
async function runScript(path, args) {
52-
return new Promise((resolve, reject) => {
53-
let invoked = false;
54-
55-
const process = childProcess.fork(path, args);
56-
57-
process.on("error", err => {
58-
if (invoked) {
59-
return;
60-
}
61-
invoked = true;
62-
reject(err);
63-
});
64-
65-
process.on("exit", code => {
66-
if (invoked) {
67-
return;
68-
}
69-
invoked = true;
70-
if (code === 0) {
71-
resolve();
72-
return;
73-
}
74-
reject(new Error(`Exit code: ${code}`));
75-
});
76-
});
77-
}
78-
7944
module.exports = {
8045
entry: {
8146
main: "./src/index.ts",
@@ -93,18 +58,12 @@ module.exports = {
9358
{
9459
test: /\.tsx?$/,
9560
loader: "ts-loader",
96-
options: {
97-
}
61+
options: {}
9862
}
9963
]
10064
},
10165
resolve: {
10266
extensions: [".ts", ".tsx"]
10367
},
104-
externals: externalsResolver,
105-
plugins: [
106-
new WebpackOnBuildPlugin(async (stats) => {
107-
await runScript("../simplr-mvdir/dist/cli.js", ["--from", "dist", "--to", "."]);
108-
}),
109-
]
110-
};
68+
externals: externalsResolver
69+
};

0 commit comments

Comments
 (0)