Giter Club home page Giter Club logo

cpany's People

Contributors

yjl9903 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

buggg-hfc

cpany's Issues

Capture CPany website

Describe the solution you'd like

Use this capture-website.

capture-website http://localhost:3000/members --full-page --no-default-background --type webp --output a.webp --overwrite --style "html, body { background-color: white; }" --delay 1

Integrate it into cli, like slidev export.

First, start the dev server. Then, capture the screen.

Refactor core package

Background

At the beginning, the core package is designed to support a more general purpose for loading and transforming the statistic of problem solving. However, during the real process of implementing, the plugins use the path as their names. The following is the example plugins.

Load: Fetch a real file and write to the file corresponding to the plugin name.

https://github.com/yjl9903/CPany/blob/1b8b0b11727a6b8cffd08e400d97c57d32e0b682/packages/codeforces/src/contest.ts#L58-L75

Transform: Fetch data with some parameters and write the file at <plugin name>/<parameter>.<ext>.

https://github.com/yjl9903/CPany/blob/1b8b0b11727a6b8cffd08e400d97c57d32e0b682/packages/codeforces/src/handle.ts#L9-L19

Clear: This is a logic file to get the file lists that need to be remove.

https://github.com/yjl9903/CPany/blob/1b8b0b11727a6b8cffd08e400d97c57d32e0b682/packages/codeforces/src/index.ts#L32-L44

The beginning "general" design does not fit the implement now. First, there are some confusing identifiers when implementing plugins, for example the logic of loading data uses the full name of file to find the handle. Second, the duty of the core package, action package and cli package is ambiguous. Third, there is some thing that is hard to implement, like load order and complex parameter.

As a result, it is time to discard the previous general design to a more concrete one that is suitable for maintaining and user creating plugins.

Design

Config file

At the root directory, there should be a yml config file cpany.yml.

The core package should provide methods to load it, and provide methods to iterate it, while the current load logic has been copied in several places.

Plugins

The plugins should be writen in commonjs with default export.

The CPany plugin is a single JavaScript file or a node package whose name is prefixed with @cpany/plugin- or cpany-plugin- or @*/cpany-plugin-.

Platform

Each plugin should specify a platform, and all the files of a platform should be put in a folder under the root directory.

All the resources in CPany is identified by <platform>/<type>/.... And the platform may be empty, for example, users are located at /user/<user id>.

A new logic plugin called platform should return some meta data of this platform.

The cli will support filter platform (select some platform, or disable some platform) and will overwrite the platform in cpany.yml.

Data load

Now, the logic of loading data depends on much plugin specify logic (like Codeforces). What I want to do is to add a new job to the core instance, that load data and give it to the plugins for processing.

Each fetch (previous load) plugin and query (previous transform) plugin should also has a load methods to load the data to the cache.

Utils

Provide some util function to create plugins. For example, add platform to plugins.

Core

core should be platform independent, that is to say core should not use any node api. All the side effect will be executed by the upper level.

The core has two jobs.

First, it will run data fetching logically, and when it finishes some fetch, it will notify the upper level to write a file or remove a file. The plugin object contains a field to denote its order (pre, null, or post).

Second, it will load data logically. The instance contains a cache to store loaded result, and provide some functions to modify the cache.

Actions

Actions is expected to support user created plugins. However, I will build all the action logic static in a bundled JavaScript file in /dist/.

After the ng version, the previous action package will be moved into cli package. The new action of CPany will only install @cpany/cli and some related plugins. So that fetching data and building site can be done in a single CPany version.

Another advantage is the support of user created plugins. There are two basic cases whether there is a package.json at the root directory.

First, package.json exists. Check whether there is a dependency @cpany/cli (give error and exit if not). Then, install the deps with a right package manager https://github.com/antfu/ni.

Second, package.json does not exist. Then @cpany/cli will be installed globally, and the plugin specified in cpany.yml will also be installed globally if the plugin is resolved failed.

CLI

When using the @cpany/cli, all the deps must be installed.

If plugins field is in cpany.yml. The cli will resolve and import these plugins locally or globally. Exit 1 when resolve failed.

Otherwise, the cli will read the package.json to import all the CPany plugins in it. And if package.json also does not exist, provide a warning message.

Futhermore

Maybe we can integrate a simple blog post system?

Maybe we can provide more freedom to the app?

Maybe we can run fetch action in memory?

Generate log.json to data repo

CLI

Instead of previous .env file, use log.json to store the latest fetch info.

{
  "version": "0.1.4",
  "timetamp": "<UTC Time String>"
}

If --history is enabled (most in a action env), store changelog.

{
  "version": "0.1.4",
  "timetamp": "<UTC Time String>",
  "pred": {
    "ref": "<current commit>",
    "diff": []
  }
}

Here, use ref to find the previous change.

git show <ref>:<path/to/log.json>
git show <ref>:<path/to/cpany.yml>

App

Create a new /history page.

Display the latest 30 logs or latest logs in 30 days (specified in cpany.yml).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.