Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27d8720
commit 57d0790
Showing
50 changed files
with
2,984 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ hero | |
website | ||
stream | ||
sql/ast/syntax/compiled | ||
databox/docpage/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as Fs from 'fs'; | ||
import * as Path from 'path'; | ||
import Axios from 'axios'; | ||
import DataboxPackager from '@ulixee/databox-packager'; | ||
import UlixeeMiner from '@ulixee/miner'; | ||
import DataboxApiClient from '@ulixee/databox/lib/DataboxApiClient'; | ||
import UlixeeHostsConfig from '@ulixee/commons/config/hosts'; | ||
import IDataboxManifest from '@ulixee/specification/types/IDataboxManifest'; | ||
|
||
const storageDir = Path.resolve(process.env.ULX_DATA_DIR ?? '.', 'Databox.docpage.test'); | ||
|
||
let dbxFile: Buffer; | ||
let miner: UlixeeMiner; | ||
let manifest: IDataboxManifest; | ||
let client: DataboxApiClient; | ||
|
||
beforeAll(async () => { | ||
jest.spyOn<any, any>(UlixeeHostsConfig.global, 'save').mockImplementation(() => null); | ||
const packager = new DataboxPackager(`${__dirname}/databoxes/docpage.js`); | ||
await packager.build(); | ||
dbxFile = await packager.dbx.asBuffer(); | ||
manifest = packager.manifest.toJSON(); | ||
miner = new UlixeeMiner(); | ||
miner.router.databoxConfiguration = { databoxesDir: storageDir }; | ||
await miner.listen(); | ||
client = new DataboxApiClient(await miner.address); | ||
}); | ||
|
||
afterAll(async () => { | ||
await miner?.close(); | ||
if (Fs.existsSync(storageDir)) { | ||
if (Fs.existsSync(storageDir)) Fs.rmSync(storageDir, { recursive: true }); | ||
} | ||
}); | ||
|
||
test('should be able to load databox documentation', async () => { | ||
await client.upload(dbxFile); | ||
const address = await miner.address; | ||
const res = await Axios.get(`http://${address}/databox/${manifest.versionHash}/`); | ||
expect(res.data.includes('Docpage - Ulixee Datastore')).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Databox, { Table, Function } from '@ulixee/databox'; | ||
import { boolean, string } from '@ulixee/schema'; | ||
|
||
export default new Databox({ | ||
functions: { | ||
test: new Function({ | ||
run(ctx) { | ||
ctx.output = { | ||
testerEcho: ctx.input.shouldTest, | ||
greeting: 'Hello world', | ||
}; | ||
}, | ||
schema: { | ||
input: { | ||
shouldTest: boolean(), | ||
}, | ||
output: { | ||
testerEcho: boolean(), | ||
greeting: string(), | ||
}, | ||
}, | ||
}), | ||
}, | ||
tables: { | ||
testers: new Table({ | ||
schema: { | ||
firstName: string(), | ||
lastName: string(), | ||
isTester: boolean(), | ||
}, | ||
seedlings: [ | ||
{ firstName: 'Caleb', lastName: 'Clark', isTester: true }, | ||
{ firstName: 'Blake', lastName: 'Byrnes' } | ||
] | ||
}), | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
presets: [ | ||
'@vue/cli-plugin-babel/preset' | ||
], | ||
"plugins": [ | ||
["prismjs", { | ||
"languages": ["javascript", "shell"], | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as Fs from 'fs/promises'; | ||
import * as Path from 'path'; | ||
import * as FsExtra from 'fs-extra'; | ||
|
||
const distOutputDir = Path.resolve(__dirname, './dist'); | ||
|
||
export async function buildDocpage(config, outputDir): Promise<void> { | ||
FsExtra.copySync(distOutputDir, outputDir); | ||
const jsDir = `${outputDir}/js`; | ||
const indexJsName = (await Fs.readdir(jsDir)).find(x => x.match(/^index\.[^.]+\.js$/)); | ||
|
||
let indexHtml = await Fs.readFile(`${outputDir}/index.html`, 'utf8'); | ||
indexHtml = indexHtml.replace('Vue App', `${config.name} - Ulixee Datastore`); | ||
await Fs.writeFile(`${outputDir}/index.html`, indexHtml); | ||
|
||
let indexJs = await Fs.readFile(`${jsDir}/${indexJsName}`, 'utf8'); | ||
indexJs = indexJs.replace('["$DATABOX_CONFIG_DATA"]', JSON.stringify(config)); | ||
await Fs.writeFile(`${jsDir}/${indexJsName}`, indexJs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = class ReplaceConfigFile { | ||
constructor(configFile) { | ||
this.configFile = configFile; | ||
} | ||
|
||
apply(compiler) { | ||
const pluginName = this.constructor.name; | ||
|
||
compiler.hooks.compilation.tap(pluginName, compilation => { | ||
const NormalModule = compiler.webpack?.NormalModule; | ||
const isNormalModuleAvailable = Boolean(NormalModule); | ||
if (isNormalModuleAvailable && Boolean(NormalModule.getCompilationHooks)) { | ||
NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(pluginName, this.tapCallback.bind(this)); | ||
} else { | ||
compilation.hooks.normalModuleLoader.tap(pluginName, this.tapCallback.bind(this)); | ||
} | ||
}); | ||
} | ||
|
||
tapCallback(_, normalModule) { | ||
if (!normalModule.resource.endsWith('docpage/src/data.config.json')) return; | ||
const loader = require.resolve('./dataLoader.js'); | ||
normalModule.loaders.push({ | ||
loader, | ||
options: { | ||
data: this.configFile, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function dataLoader(source) { | ||
const options = this.getOptions() || {}; | ||
return JSON.stringify(options.data || {}); | ||
} |
Oops, something went wrong.