chore: initial

This commit is contained in:
cha0s 2020-12-23 12:46:52 -06:00
commit a9ebd2fcfd
44 changed files with 31615 additions and 0 deletions

116
.gitignore vendored Normal file
View File

@ -0,0 +1,116 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

26
app/.eslint.defaults.js Normal file
View File

@ -0,0 +1,26 @@
const config = {
globals: {
__non_webpack_require__: true,
process: true,
window: true,
},
rules: {
'babel/object-curly-spacing': 'off',
'brace-style': ['error', 'stroustrup'],
'no-bitwise': ['error', {int32Hint: true}],
'no-plusplus': 'off',
'no-shadow': 'off',
'no-underscore-dangle': 'off',
'padded-blocks': ['error', {classes: 'always'}],
yoda: 'off',
},
settings: {
'import/resolver': {
webpack: {
config: `${__dirname}/webpack.config.js`,
},
},
},
};
module.exports = config;

5
app/.eslintrc.js Normal file
View File

@ -0,0 +1,5 @@
const neutrino = require('neutrino');
process.env.LATUS_LINTING = true;
module.exports = neutrino(require('./.neutrinorc')).eslintrc();

119
app/.gitignore vendored Normal file
View File

@ -0,0 +1,119 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
/build
/latus.yml

5
app/.mocharc.js Normal file
View File

@ -0,0 +1,5 @@
const neutrino = require('neutrino');
process.env.NODE_ENV = process.env.NODE_ENV || 'test';
module.exports = neutrino().mocha();

94
app/.neutrinorc.js Normal file
View File

@ -0,0 +1,94 @@
require('dotenv/config');
const {join} = require('path');
const airbnb = require('@neutrinojs/airbnb');
const clean = require('@neutrinojs/clean');
const copy = require('@neutrinojs/copy');
const mocha = require('@neutrinojs/mocha');
const node = require('@neutrinojs/node');
const {EnvironmentPlugin} = require('webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
options: {
root: __dirname,
},
use: [
airbnb({
eslint: {
cache: false,
baseConfig: require('./.eslint.defaults'),
},
}),
clean({
cleanOnceBeforeBuildPatterns: ['**/*.hot-update.*'],
}),
copy({
patterns: [{
from: 'src/assets',
to: 'http',
}],
}),
mocha(),
node(),
(neutrino) => {
[
'components',
'context',
'fonts',
'hooks',
'images',
'scss',
].forEach((path) => {
neutrino.config.resolve.alias
.set(path, `${neutrino.options.source}/react/${path}`);
});
if (process.env.LATUS_LINTING) {
return;
}
neutrino.config.module
.rule('compile')
.use('babel')
.get('options').plugins.push(
[
'babel-plugin-webpack-alias',
{
config: `${__dirname}/webpack.config.js`,
},
],
);
neutrino.config
.plugin('environment')
.use(EnvironmentPlugin, [{
SIDE: 'server',
}]);
neutrino.config
.entry('index')
.prepend('@latus/core/start');
if ('production' !== neutrino.config.get('mode')) {
neutrino.config
.entry('index')
.prepend('dotenv/config');
neutrino.config
.plugin('start-server')
.tap((args) => {
const options = args[0];
const inspectArg = process.argv.find((arg) => -1 !== arg.indexOf('--inspect'));
if (inspectArg) {
options.nodeArgs.push(inspectArg);
}
const profArg = process.argv.find((arg) => -1 !== arg.indexOf('--prof'));
if (profArg) {
options.nodeArgs.push(profArg);
}
options.nodeArgs.push('--experimental-repl-await');
return args;
});
}
neutrino.config
.externals(nodeExternals({
}));
},
],
};

17
app/docker-compose.yml Normal file
View File

@ -0,0 +1,17 @@
version: '2'
services:
redis:
image: redis:6
ports:
- 6380:6379
mysql:
image: mysql:8
command:
- '--default-authentication-plugin=mysql_native_password'
environment:
- MYSQL_DATABASE=db
- MYSQL_ROOT_PASSWORD=UNSAFE_DEV_PASSWORD
ports:
- 32342:3306

47
app/package.json Normal file
View File

@ -0,0 +1,47 @@
{
"name": "persea",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"build": "webpack --mode production",
"dev": "webpack --mode development",
"docker": "yarn run build && docker build",
"forcelatus": "pkgs=$(find node_modules/@latus -maxdepth 1 -mindepth 1 -printf '@latus/%f '); yarn upgrade $pkgs",
"lint": "eslint --cache --format codeframe --ext mjs,jsx,js src",
"repl": "rlwrap -C qmp socat STDIO UNIX:$(ls /tmp/latus-*.sock | tail -n 1)",
"start": "NODE_ENV=production node build/index.js",
"test": "mocha --watch src",
"watch": "webpack --hot --watch --mode development"
},
"dependencies": {
"@latus/core": "^2.0.0",
"@latus/db": "^2.0.0",
"@latus/governor": "^2.0.0",
"@latus/http": "^2.0.0",
"@latus/react": "^2.0.0",
"@latus/redis": "^2.0.0",
"@latus/redux": "^2.0.0",
"@latus/repl": "^2.0.0",
"@latus/socket": "^2.0.0",
"@latus/user": "^2.0.0",
"@persea/core": "^1.0.0",
"@persea/json": "^1.0.0",
"dotenv": "8.2.0",
"react-hot-loader": "4.13.0"
},
"devDependencies": {
"@neutrinojs/airbnb": "^9.4.0",
"@neutrinojs/clean": "^9.1.0",
"@neutrinojs/copy": "^9.4.0",
"@neutrinojs/mocha": "^9.1.0",
"@neutrinojs/node": "^9.1.0",
"babel-plugin-webpack-alias": "^2.1.2",
"eslint": "^6",
"eslint-import-resolver-webpack": "^0.12.1",
"js-yaml": "3.14.0",
"neutrino": "^9.1.0",
"source-map-support": "0.5.19",
"webpack": "^4",
"webpack-cli": "^3"
}
}

1
app/src/index.js Normal file
View File

@ -0,0 +1 @@
process.stdout.write('Your application is starting...\n');

49
app/src/react/index.jsx Normal file
View File

@ -0,0 +1,49 @@
import React from 'react';
import {hot} from 'react-hot-loader';
import Login from '@latus/user/client/components/login';
import {useDispatch} from '@latus/redux/client';
import {
createProject,
createResource,
deleteResource,
renameResource,
} from '@persea/core/client';
import {patchJsonResource} from '@persea/json/client';
const App = () => {
const dispatch = useDispatch();
dispatch(createProject({tree: {}, uuid: 'foobar'}));
dispatch(createResource({
data: {traits: []},
project: 'foobar',
uri: '/test.entity.json',
}));
dispatch(patchJsonResource({
patch: [
{
op: 'add',
path: '/traits/-',
value: {
type: 'existent',
},
},
],
project: 'foobar',
uri: '/test.entity.json',
}));
return (
<div className="app">
<h1>Latus react app</h1>
<p>Yay, you maaaaade it! :)</p>
<Login />
</div>
);
};
export default {
hooks: {
'@latus/react/client/components': () => hot(module)(App),
},
};

28
app/webpack.config.js Normal file
View File

@ -0,0 +1,28 @@
require('source-map-support/register');
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const {Latus} = require('@latus/core');
const neutrino = require('neutrino');
if (process.env.LATUS_LINTING) {
// eslint-disable-next-line global-require
module.exports = neutrino(require('./.neutrinorc')).webpack();
}
else {
module.exports = new Promise((resolve, reject) => {
try {
const latus = Latus.create();
const configs = {
// eslint-disable-next-line global-require
app: require('./.neutrinorc'),
};
latus.invokeFlat('@latus/core/build', configs);
const webpackConfigs = Object.values(configs).map((config) => neutrino(config).webpack());
resolve(webpackConfigs);
}
catch (error) {
reject(error);
}
});
}

9191
app/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
const config = {
globals: {
process: true,
window: true,
},
ignorePatterns: [
'/*',
'!/src',
],
rules: {
'babel/object-curly-spacing': 'off',
'brace-style': ['error', 'stroustrup'],
'no-bitwise': ['error', {int32Hint: true}],
'no-plusplus': 'off',
'no-shadow': 'off',
'no-underscore-dangle': 'off',
'padded-blocks': ['error', {classes: 'always'}],
yoda: 'off',
},
};
module.exports = config;

3
config/.eslintrc.js Normal file
View File

@ -0,0 +1,3 @@
const neutrino = require('neutrino');
module.exports = neutrino(require(`${__dirname}/.neutrinorc`)()).eslintrc();

5
config/.mocharc.js Normal file
View File

@ -0,0 +1,5 @@
const neutrino = require('neutrino');
process.env.NODE_ENV = process.env.NODE_ENV || 'test';
module.exports = neutrino(require(`${__dirname}/.neutrinorc`)()).mocha();

34
config/.neutrinorc.js Normal file
View File

@ -0,0 +1,34 @@
const airbnbBase = require('@neutrinojs/airbnb-base');
const library = require('@neutrinojs/library');
const mocha = require('@neutrinojs/mocha');
module.exports = () => ({
options: {},
use: [
(neutrino) => {
neutrino.options.output = '.';
},
airbnbBase({
eslint: {
cache: false,
baseConfig: require(`${__dirname}/.eslint.defaults`),
},
}),
(neutrino) => {
const {name} = neutrino.options.packageJson;
library({
clean: false,
name,
target: 'node',
})(neutrino);
},
(neutrino) => {
const options = neutrino.config.module
.rule('compile')
.use('babel')
.get('options');
options.presets[0][1].targets = {esmodules: true};
},
mocha(),
],
});

3
config/package/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/*.js
/*.js.map
!/webpack.config.js

View File

@ -0,0 +1,38 @@
{
"name": "@persea/package",
"version": "1.0.0",
"main": "index.js",
"author": "cha0s",
"license": "MIT",
"scripts": {
"build": "NODE_PATH=./node_modules webpack --mode production",
"clean": "rm -f yarn.lock && yarn",
"dev": "NODE_PATH=./node_modules webpack --mode development",
"forcepub": "npm unpublish --force $(node -e 'const {name, version} = require(`./package.json`); process.stdout.write(`${name}@${version}`)') && npm publish",
"link": "node -e \"Object.keys(require('./package.json').dependencies).filter((m) => 0 === m.indexOf('@latus/')).forEach((m) => require('child_process').spawn('yarn', ['link', m]));\"",
"lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .",
"test": "NODE_PATH=./node_modules mocha --config ../../config/.mocharc.js",
"unlink": "node -e \"Object.keys(require('./package.json').dependencies).filter((m) => 0 === m.indexOf('@latus/')).forEach((m) => require('child_process').spawn('yarn', ['unlink', m]));\" && yarn install --force",
"watch": "NODE_PATH=./node_modules webpack --watch --mode development"
},
"files": [
"index.js",
"index.js.map"
],
"dependencies": {
"debug": "4.3.1"
},
"devDependencies": {
"@neutrinojs/airbnb-base": "^9.4.0",
"@neutrinojs/copy": "9.4.0",
"@neutrinojs/mocha": "^9.4.0",
"@neutrinojs/react": "^9.4.0",
"chai": "4.2.0",
"eslint": "^7",
"eslint-import-resolver-webpack": "0.13.0",
"mocha": "^8",
"neutrino": "^9.4.0",
"webpack": "^4",
"webpack-cli": "^3"
}
}

View File

View File

@ -0,0 +1,8 @@
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const neutrino = require('neutrino');
const configOfConfigs = require(`${__dirname}/.neutrinorc`);
const configs = Array.isArray(configOfConfigs) ? configOfConfigs : [configOfConfigs];
module.exports = configs.map((config) => neutrino(config).webpack());

57
config/split-config.js Normal file
View File

@ -0,0 +1,57 @@
const react = require('@neutrinojs/react');
const nodeExternals = require('webpack-node-externals');
const config = require('./.neutrinorc');
module.exports = ({name, files, peerDependencies}, clientMains) => {
const mains = files
.filter((file) => file.match(/\.js$/))
.map((file) => file.slice(0, -3))
.reduce((r, file) => ({...r, [file]: file}), {});
if (clientMains.length > 0) {
const serverMains = Object
.entries(mains)
.filter(([key]) => -1 === clientMains.indexOf(key))
.reduce((r, [k, v]) => ({...r, [k]: v}), {});
const serverConfig = config();
serverConfig.options.mains = serverMains;
const clientConfig = config();
clientConfig.options.mains = clientMains.reduce((r, file) => ({...r, [file]: file}), {});
clientConfig.use[2] = (neutrino) => {
react({
clean: false,
})(neutrino);
Object.keys(clientConfig.options.mains).forEach((main) => {
neutrino.config.plugins.delete(`html-${main}`);
});
neutrino.config
.target('web')
.optimization
.splitChunks(false)
.runtimeChunk(false)
.end()
.output
.filename('[name].js')
.library(name)
.libraryTarget('umd')
.umdNamedDefine(true);
if (peerDependencies) {
neutrino.config.externals(
Object.keys(peerDependencies).reduce((r, path) => ({...r, [path]: path}), {}),
);
}
};
clientConfig.use.push((neutrino) => {
neutrino.config.node.set('Buffer', true);
});
return [serverConfig, clientConfig];
}
else {
const serverConfig = config();
serverConfig.options = {
mains,
};
return [serverConfig];
}
};

8
config/webpack.config.js Normal file
View File

@ -0,0 +1,8 @@
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const neutrino = require('neutrino');
const configOfConfigs = require(`${__dirname}/.neutrinorc`);
const configs = Array.isArray(configOfConfigs) ? configOfConfigs : [configOfConfigs];
module.exports = configs.map((config) => neutrino(config).webpack());

6
lerna.json Normal file
View File

@ -0,0 +1,6 @@
{
"packages": [
"packages/*"
],
"version": "1.0.0"
}

28
package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "@persea/monorepo",
"private": true,
"scripts": {
"build": "lerna run build",
"clean": "lerna run clean",
"dev": "lerna run dev",
"forcepub": "lerna run forcepub",
"link": "lerna run link",
"lint": "lerna run lint",
"test": "lerna run test",
"unlink": "lerna run unlink",
"watch": "lerna run watch --parallel"
},
"devDependencies": {
"@neutrinojs/airbnb-base": "^9.4.0",
"@neutrinojs/library": "^9.4.0",
"@neutrinojs/mocha": "^9.4.0",
"chai": "4.2.0",
"eslint": "^7",
"eslint-import-resolver-webpack": "0.13.0",
"lerna": "^3.22.1",
"mocha": "^8",
"neutrino": "^9.4.0",
"webpack": "^4",
"webpack-cli": "^3"
}
}

3
packages/core/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/*.js
/*.js.map
!/webpack.config.js

View File

@ -0,0 +1,49 @@
{
"name": "@persea/core",
"version": "1.0.0",
"main": "index.js",
"author": "cha0s",
"license": "MIT",
"scripts": {
"build": "NODE_PATH=./node_modules webpack --mode production",
"clean": "rm -f yarn.lock && yarn",
"dev": "NODE_PATH=./node_modules webpack --mode development",
"forcepub": "npm unpublish --force $(node -e 'const {name, version} = require(`./package.json`); process.stdout.write(`${name}@${version}`)') && npm publish",
"link": "node -e \"Object.keys(require('./package.json').dependencies).filter((m) => 0 === m.indexOf('@latus/')).forEach((m) => require('child_process').spawn('yarn', ['link', m]));\"",
"lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .",
"test": "NODE_PATH=./node_modules mocha --config ../../config/.mocharc.js",
"unlink": "node -e \"Object.keys(require('./package.json').dependencies).filter((m) => 0 === m.indexOf('@latus/')).forEach((m) => require('child_process').spawn('yarn', ['unlink', m]));\" && yarn install --force",
"watch": "NODE_PATH=./node_modules webpack --watch --mode development"
},
"files": [
"client.js",
"client.js.map",
"index.js",
"index.js.map"
],
"dependencies": {
"debug": "4.3.1",
"glob": "^7.1.6",
"natsort": "^2.0.2",
"react-sortable-tree": "^2.8.0"
},
"devDependencies": {
"@latus/db": "^2.0.0",
"@latus/redux": "^2.0.0",
"@neutrinojs/airbnb-base": "^9.4.0",
"@neutrinojs/copy": "9.4.0",
"@neutrinojs/mocha": "^9.4.0",
"@neutrinojs/react": "^9.4.0",
"chai": "4.2.0",
"eslint": "^7",
"eslint-import-resolver-webpack": "0.13.0",
"mocha": "^8",
"neutrino": "^9.4.0",
"webpack": "^4",
"webpack-cli": "^3"
},
"peerDependencies": {
"@latus/db": "^2.0.0",
"@latus/redux": "^2.0.0"
}
}

View File

@ -0,0 +1,11 @@
import {projects} from './state';
export * from './state';
export default {
hooks: {
'@latus/redux/slices': () => ({
projects,
}),
},
};

View File

@ -0,0 +1,2 @@
export * from './projects';
export {default as projects} from './projects';

View File

@ -0,0 +1,58 @@
import {
createSelector,
createSlice,
} from '@latus/redux/client';
import {
addPathToTree,
removePathFromTree,
} from '../../tree-utils';
export const projectsSelector = (state) => state.projects;
export const projectSelector = createSelector(
[projectsSelector, (_, uuid) => uuid],
(projects, uuid) => uuid && projects[uuid],
);
const slice = createSlice({
name: 'persea/projects',
initialState: {
projects: {},
resources: {},
},
/* eslint-disable no-param-reassign */
extraReducers: {
},
reducers: {
createProject: ({projects}, {payload: {tree, uuid}}) => {
projects[uuid] = tree;
},
createResource: ({projects, resources}, {payload: {data, project, uri}}) => {
projects[project] = addPathToTree(projects[project], uri);
resources[`${project}${uri}`] = data;
},
deleteResource: ({projects, resources}, {payload: {project, uri}}) => {
projects[project] = removePathFromTree(projects[project], uri);
delete resources[`${project}${uri}`];
},
renameResource: ({projects, resources}, {payload: {project, from, to}}) => {
const tree = removePathFromTree(projects[project], from);
projects[project] = addPathToTree(tree, to);
resources[`${project}${to}`] = resources[`${project}${from}`];
delete resources[`${project}${from}`];
},
},
/* eslint-enable no-param-reassign */
});
slice.reducer.subscription = slice.reducer;
export const {
createProject,
createResource,
deleteResource,
renameResource,
} = slice.actions;
export default slice.reducer;

View File

@ -0,0 +1,14 @@
import Project from './models/project';
import ProjectUser from './models/project-user';
export default {
hooks: {
'@latus/db/models': () => ({
Project,
}),
'@latus/db/models.decorate': (Models) => ({
...Models,
User: ProjectUser(Models.User),
}),
},
};

View File

@ -0,0 +1,8 @@
export default (User) => class ProjectUser extends User {
async projectsStructure() {
return (await this.getProjects())
.reduce(async (r, project) => ({...await r, [project.uuid]: await project.structure()}), {});
}
};

View File

@ -0,0 +1,36 @@
import {join} from 'path';
import {promisify} from 'util';
import {Model, Sequelize, Types} from '@latus/db';
import glob from 'glob';
import {pathsToTree} from '../tree-utils';
class Project extends Model {
static get attributes() {
return {
uuid: {
type: Types.UUID,
defaultValue: Sequelize.UUIDV4,
},
};
}
static associate({User}) {
User.hasMany(this);
this.belongsTo(User);
}
async structure() {
const skipCount = process.cwd().split('/').length + 2;
const paths = (await promisify(glob)(join(process.cwd(), 'projects', this.uuid, '**')))
.map((path) => path.split('/').slice(skipCount).join('/'))
.map((path) => `/${path}`)
.filter((path) => !!path);
return pathsToTree(paths);
}
}
export default Project;

View File

@ -0,0 +1,48 @@
import {basename} from 'path';
import natsort from 'natsort';
import {
getFlatDataFromTree,
getTreeFromFlatData,
removeNodeAtPath,
} from 'react-sortable-tree';
const getKey = ({path}) => path;
const getParentKey = ({path}) => {
const parts = path.split('/');
return parts.length > 0 ? (parts.pop(), parts.join('/')) : '/';
};
export const pathToNode = (path) => ({path, label: basename(path)});
export const treeToPaths = (tree) => (
getFlatDataFromTree({
getKey: ({path}) => path,
treeData: tree,
})
);
export const pathsToTree = (paths) => (
getTreeFromFlatData({
flatData: paths
.sort(natsort({insensitive: true}))
.map(pathToNode),
getKey,
getParentKey,
rootKey: '/',
})
);
export const addPathToTree = (tree, path) => {
const paths = treeToPaths(tree);
return pathsToTree(paths.concat(path));
};
export const removePathFromTree = (tree, path) => (
removeNodeAtPath({
getNodeKey: getKey,
path,
treeData: tree,
})
);

View File

@ -0,0 +1,8 @@
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const neutrino = require('neutrino');
const configOfConfigs = require(`${__dirname}/.neutrinorc`);
const configs = Array.isArray(configOfConfigs) ? configOfConfigs : [configOfConfigs];
module.exports = configs.map((config) => neutrino(config).webpack());

6624
packages/core/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

3
packages/json/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/*.js
/*.js.map
!/webpack.config.js

View File

@ -0,0 +1,45 @@
{
"name": "@persea/json",
"version": "1.0.0",
"main": "index.js",
"author": "cha0s",
"license": "MIT",
"scripts": {
"build": "NODE_PATH=./node_modules webpack --mode production",
"clean": "rm -f yarn.lock && yarn",
"dev": "NODE_PATH=./node_modules webpack --mode development",
"forcepub": "npm unpublish --force $(node -e 'const {name, version} = require(`./package.json`); process.stdout.write(`${name}@${version}`)') && npm publish",
"link": "node -e \"Object.keys(require('./package.json').dependencies).filter((m) => 0 === m.indexOf('@latus/')).forEach((m) => require('child_process').spawn('yarn', ['link', m]));\"",
"lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .",
"test": "NODE_PATH=./node_modules mocha --config ../../config/.mocharc.js",
"unlink": "node -e \"Object.keys(require('./package.json').dependencies).filter((m) => 0 === m.indexOf('@latus/')).forEach((m) => require('child_process').spawn('yarn', ['unlink', m]));\" && yarn install --force",
"watch": "NODE_PATH=./node_modules webpack --watch --mode development"
},
"files": [
"client.js",
"client.js.map",
"index.js",
"index.js.map"
],
"dependencies": {
"debug": "4.3.1",
"fast-json-patch": "^3.0.0-1"
},
"devDependencies": {
"@latus/redux": "^2.0.0",
"@neutrinojs/airbnb-base": "^9.4.0",
"@neutrinojs/copy": "9.4.0",
"@neutrinojs/mocha": "^9.4.0",
"@neutrinojs/react": "^9.4.0",
"chai": "4.2.0",
"eslint": "^7",
"eslint-import-resolver-webpack": "0.13.0",
"mocha": "^8",
"neutrino": "^9.4.0",
"webpack": "^4",
"webpack-cli": "^3"
},
"peerDependencies": {
"@latus/redux": "^2.0.0"
}
}

View File

@ -0,0 +1,20 @@
import {createNextState} from '@latus/redux/client';
import {applyPatch} from 'fast-json-patch';
import {patchJsonResource} from './state';
export * from './state';
export default {
hooks: {
'@latus/redux/reducers': () => (state, {payload, type}) => {
if (type !== patchJsonResource.toString()) {
return state;
}
const {patch, project, uri} = payload;
return createNextState(state, (draft) => {
applyPatch(draft.projects.resources[`${project}${uri}`], patch);
});
},
},
};

View File

@ -0,0 +1 @@
export * from './json';

View File

@ -0,0 +1,5 @@
import {createAction} from '@latus/redux/client';
export const patchJsonResource = createAction('@persea/json/patchResource');
export default () => {};

View File

View File

@ -0,0 +1,8 @@
// Whilst the configuration object can be modified here, the recommended way of making
// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead.
// Neutrino's inspect feature can be used to view/export the generated configuration.
const neutrino = require('neutrino');
const configOfConfigs = require(`${__dirname}/.neutrinorc`);
const configs = Array.isArray(configOfConfigs) ? configOfConfigs : [configOfConfigs];
module.exports = configs.map((config) => neutrino(config).webpack());

6261
packages/json/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

8501
yarn.lock Normal file

File diff suppressed because it is too large Load Diff