This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
/
fuse.ts
159 lines (140 loc) · 3.93 KB
/
fuse.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { IBumpVersionType } from './src/sparky/bumpVersion';
import { npmPublish } from './src/sparky/npmPublish';
import { sparky } from './src/sparky/sparky';
import { tsc } from './src/sparky/tsc';
class Context {
npmTag: string;
versionBumpType: IBumpVersionType;
}
const { exec, rm, src, task } = sparky(Context);
function runTypeChecker() {
const typeChecker = require('fuse-box-typechecker').TypeChecker({
basePath: './',
name: 'typecheck',
throwOnGlobal: true,
throwOnSemantic: true,
throwOnSyntactic: true,
tsConfig: './src/tsconfig.json',
});
// to run it right away
typeChecker.printSettings();
return typeChecker.inspectAndPrint();
}
task('transpile', async c => {
await tsc(
{
declaration: true,
module: 'CommonJS',
skipLibCheck: true,
target: 'ES2017',
outDir: 'dist',
},
['src/index.ts', 'src/threading/worker_threads/ProcessThread.ts'],
);
});
task('clean', async () => {
await rm('dist');
});
task('typecheck', () => {
runTypeChecker();
});
// replacing the path (since we copy everything to dist)
task('fix-env', async () => {
const package_json = require('./dist/package.json');
await src('dist/env.js')
.contentsOf('env.js', str => {
str = str.replace(/FUSE_ROOT\s*=\s*(appRoot.path)/, 'FUSE_ROOT = __dirname;');
str = str.replace(/VERSION\s*=\s*[^;]+/, `VERSION = '${package_json.version}'`);
str = str.replace(
/WORKER_THREAD\s*=\s*[^;]+/,
`WORKER_THREAD = path.resolve(__dirname, 'threading/worker_threads/ProcessThread.js')`,
);
return str;
})
.write()
.exec();
});
// bump version to automate
task('bump-version', async ctx => {
await src('package.json')
.bumpVersion('package.json', { type: ctx.npmTag as any })
.write()
.dest('dist/', __dirname)
.exec();
});
// copy essential modules (will reside alongside with everything else)
task('copy-modules', async () => {
await src('./modules/**/**.*')
.dest('dist/modules', 'modules')
.exec();
});
task('copy-various', async () => {
await src('./src/production/api/production.api.js')
.dest('dist/', 'src')
.exec();
});
task('publish', async ctx => {
await exec('dist');
await npmPublish({ path: 'dist/', tag: ctx.npmTag });
});
task('publish-next', async ctx => {
ctx.npmTag = 'next';
await exec('publish');
});
task('publish-alpha', async ctx => {
ctx.npmTag = 'alpha';
await exec('publish');
});
task('dist-alpha', async ctx => {
ctx.npmTag = 'alpha';
await exec('dist');
});
task('public-alpha', async ctx => {
ctx.npmTag = 'alpha';
await exec('publish');
});
task('dist', async ctx => {
await exec('clean');
//await exec('typecheck');
await exec('transpile');
await exec('copy-modules');
await exec('copy-various');
await exec('bump-version');
await exec('fix-env');
});
task('document', async ctx => {
const TypeDoc = require('typedoc');
const typedocApp = new TypeDoc.Application({
allowJs: false,
exclude: '**/*.test.ts',
excludeExternals: true,
excludePrivate: true,
experimentalDecorators: true,
ignoreCompilerErrors: true,
logger: 'console',
mode: 'modules',
module: 'CommonJS',
target: 'ES6',
});
const typedocProject = typedocApp.convert(typedocApp.expandInputFiles(['src/core/FuseBox.ts']));
if (typedocProject) {
// Project may not have converted correctly
const outputDir = 'docs/api';
// Rendered docs
await typedocApp.generateDocs(typedocProject, outputDir);
}
});
task('dev-thread', async ctx => {
const { fusebox } = require('./dist');
const fuse = fusebox({
cache: { enabled: true },
dependencies: { serverIgnoreExternals: true },
entry: 'src/threading/worker_threads/ProcessThread.ts',
logging: { level: 'succinct' },
target: 'server',
});
await fuse.runDev({
bundles: { app: 'fuse_thread.js', distRoot: 'dist/dev-threads' },
});
//onComplete(({ server }) => server.start());
});