mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: convert to ESM
This commit is contained in:
parent
770a0812aa
commit
3e565109b3
26 changed files with 242 additions and 291 deletions
|
|
@ -1,24 +1,25 @@
|
|||
'use strict';
|
||||
import process from 'node:process';
|
||||
import http from 'node:http';
|
||||
import os from 'node:os';
|
||||
import express from 'express';
|
||||
import {Server} from 'socket.io';
|
||||
import writejson from 'writejson';
|
||||
import readjson from 'readjson';
|
||||
import {promisify} from 'node:util';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {dirname} from 'node:path';
|
||||
import cloudcmd from '../server/cloudcmd.mjs';
|
||||
|
||||
const process = require('node:process');
|
||||
const http = require('node:http');
|
||||
const os = require('node:os');
|
||||
|
||||
const express = require('express');
|
||||
const io = require('socket.io');
|
||||
const writejson = require('writejson');
|
||||
const readjson = require('readjson');
|
||||
const {promisify} = require('node:util');
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
const cloudcmd = require('../server/cloudcmd');
|
||||
const {assign} = Object;
|
||||
|
||||
const pathConfig = os.homedir() + '/.cloudcmd.json';
|
||||
const currentConfig = readjson.sync.try(pathConfig);
|
||||
|
||||
module.exports = before;
|
||||
export default before;
|
||||
|
||||
function before(options, fn = options) {
|
||||
const {
|
||||
|
|
@ -38,7 +39,7 @@ function before(options, fn = options) {
|
|||
server.close(cb);
|
||||
};
|
||||
|
||||
const socket = io(server);
|
||||
const socket = new Server(server);
|
||||
|
||||
app.use(cloudcmd({
|
||||
socket,
|
||||
|
|
@ -54,7 +55,7 @@ function before(options, fn = options) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports.connect = promisify((options, fn = options) => {
|
||||
export const connect = promisify((options, fn = options) => {
|
||||
before(options, (port, done) => {
|
||||
fn(null, {
|
||||
port,
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
'use strict';
|
||||
import serveOnce from 'serve-once';
|
||||
import test from 'supertape';
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
|
||||
const test = require('supertape');
|
||||
|
||||
const cloudcmd = require('../..');
|
||||
const configManager = cloudcmd.createConfigManager();
|
||||
|
||||
const {request} = require('serve-once')(cloudcmd, {
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config: {
|
||||
auth: false,
|
||||
},
|
||||
|
|
@ -1,24 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
const {mkdirSync} = require('node:fs');
|
||||
const {join} = require('node:path');
|
||||
const test = require('supertape');
|
||||
const rimraf = require('rimraf');
|
||||
import {dirname, join} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import serveOnce from 'serve-once';
|
||||
import {mkdirSync} from 'node:fs';
|
||||
import test from 'supertape';
|
||||
import {rimraf} from 'rimraf';
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const config = {
|
||||
root: join(__dirname, '..'),
|
||||
root: new URL('..', import.meta.url).pathname,
|
||||
};
|
||||
|
||||
const cloudcmd = require('../..');
|
||||
const configManager = cloudcmd.createConfigManager();
|
||||
|
||||
configManager('auth', false);
|
||||
|
||||
const {request} = require('serve-once')(cloudcmd, {
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config,
|
||||
configManager,
|
||||
});
|
||||
|
||||
const fixtureDir = join(__dirname, '..', 'fixture') + '/';
|
||||
|
||||
test('cloudcmd: rest: copy', async (t) => {
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
'use strict';
|
||||
import serveOnce from 'serve-once';
|
||||
import test from 'supertape';
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
|
||||
const test = require('supertape');
|
||||
|
||||
const cloudcmd = require('../..');
|
||||
const {request} = require('serve-once')(cloudcmd, {
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config: {
|
||||
auth: false,
|
||||
},
|
||||
|
|
@ -1,28 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
const wait = require('@iocmd/wait');
|
||||
const {EventEmitter} = require('node:events');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const {test, stub} = require('supertape');
|
||||
const {Volume} = require('memfs');
|
||||
const {ufs} = require('unionfs');
|
||||
const serveOnce = require('serve-once');
|
||||
|
||||
const cloudcmd = require('../../server/cloudcmd.js');
|
||||
import wait from '@iocmd/wait';
|
||||
import {EventEmitter} from 'node:events';
|
||||
import {test, stub} from 'supertape';
|
||||
import serveOnce from 'serve-once';
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
|
||||
test('cloudcmd: rest: move', async (t) => {
|
||||
const volume = {
|
||||
'/fixture/move.txt': 'hello',
|
||||
'/fixture/tmp/a.txt': 'a',
|
||||
};
|
||||
|
||||
const vol = Volume.fromJSON(volume, '/');
|
||||
|
||||
const unionFS = ufs
|
||||
.use(vol)
|
||||
.use(fs);
|
||||
|
||||
const move = new EventEmitter();
|
||||
const moveFiles = stub().returns(move);
|
||||
|
||||
|
|
@ -103,4 +85,3 @@ test('cloudcmd: rest: move: no to', async (t) => {
|
|||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
'use strict';
|
||||
import fs from 'node:fs';
|
||||
import {join, dirname} from 'node:path';
|
||||
import {promisify} from 'node:util';
|
||||
import test from 'supertape';
|
||||
import tar from 'tar-stream';
|
||||
import gunzip from 'gunzip-maybe';
|
||||
import pullout from 'pullout';
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
import serveOnce from 'serve-once';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
|
||||
const mockRequire = require('mock-require');
|
||||
const fs = require('node:fs');
|
||||
const {join} = require('node:path');
|
||||
const {promisify} = require('node:util');
|
||||
|
||||
const test = require('supertape');
|
||||
const tar = require('tar-stream');
|
||||
const gunzip = require('gunzip-maybe');
|
||||
const pullout = require('pullout');
|
||||
|
||||
const cloudcmd = require('../../server/cloudcmd.js');
|
||||
const serveOnce = require('serve-once');
|
||||
const {reRequire} = mockRequire;
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const pathZipFixture = join(__dirname, '..', 'fixture/pack.zip');
|
||||
|
||||
const pathTarFixture = join(__dirname, '..', 'fixture/pack.tar.gz');
|
||||
|
|
@ -20,7 +18,7 @@ const pathTarFixture = join(__dirname, '..', 'fixture/pack.tar.gz');
|
|||
const defaultOptions = {
|
||||
config: {
|
||||
auth: false,
|
||||
root: join(__dirname, '..'),
|
||||
root: new URL('..', import.meta.url).pathname,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -38,7 +36,6 @@ const once = promisify((name, extract, fn) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: rest: pack: tar: get', async (t) => {
|
||||
debugger;
|
||||
const config = {
|
||||
packer: 'tar',
|
||||
auth: false,
|
||||
|
|
@ -67,7 +64,9 @@ test('cloudcmd: rest: pack: tar: get', async (t) => {
|
|||
|
||||
t.equal(file, data, 'should pack data');
|
||||
t.end();
|
||||
}, {timeout: 7000});
|
||||
}, {
|
||||
timeout: 7000,
|
||||
});
|
||||
|
||||
test('cloudcmd: rest: pack: tar: put: file', async (t) => {
|
||||
const config = {
|
||||
|
|
@ -233,4 +232,3 @@ function getPackOptions(to, names = ['pack']) {
|
|||
from: '/fixture',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1,17 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
|
||||
const test = require('supertape');
|
||||
const {Volume} = require('memfs');
|
||||
const {ufs} = require('unionfs');
|
||||
|
||||
const serveOnce = require('serve-once');
|
||||
|
||||
const cloudcmd = require('../../server/cloudcmd.js');
|
||||
const cloudcmdPath = '../../';
|
||||
const dir = `${cloudcmdPath}server/`;
|
||||
const restPath = `${dir}rest`;
|
||||
import fs from 'node:fs';
|
||||
import test from 'supertape';
|
||||
import {Volume} from 'memfs';
|
||||
import {ufs} from 'unionfs';
|
||||
import serveOnce from 'serve-once';
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
|
||||
test('cloudcmd: rest: rename', async (t) => {
|
||||
const volume = {
|
||||
|
|
@ -100,4 +92,3 @@ test('cloudcmd: rest: rename: no to', async (t) => {
|
|||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
'use strict';
|
||||
import path, {dirname} from 'node:path';
|
||||
import {once} from 'node:events';
|
||||
import test from 'supertape';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {createRequire} from 'node:module';
|
||||
import io from 'socket.io-client';
|
||||
import {connect} from '../before.mjs';
|
||||
|
||||
const path = require('node:path');
|
||||
const {once} = require('node:events');
|
||||
|
||||
const test = require('supertape');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
const {connect} = require('../before');
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const require = createRequire(import.meta.url);
|
||||
const configPath = path.join(__dirname, '../..', 'server', 'config');
|
||||
const configFn = require(configPath).createConfig();
|
||||
|
||||
|
|
@ -1,16 +1,21 @@
|
|||
'use strict';
|
||||
import {createRequire} from 'node:module';
|
||||
import {dirname, join} from 'node:path';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
|
||||
const {join} = require('node:path');
|
||||
const {test, stub} = require('supertape');
|
||||
import serveOnce from 'serve-once';
|
||||
import {test, stub} from 'supertape';
|
||||
|
||||
import cloudcmd from '../../server/cloudcmd.mjs';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const require = createRequire(import.meta.url);
|
||||
const cloudcmdPath = join(__dirname, '..', '..');
|
||||
|
||||
const modulesPath = join(cloudcmdPath, 'json', 'modules.json');
|
||||
|
||||
const localModules = require(modulesPath);
|
||||
const modulas = require(`${cloudcmdPath}/server/modulas`);
|
||||
|
||||
const cloudcmd = require(cloudcmdPath);
|
||||
const {request} = require('serve-once')(cloudcmd, {
|
||||
const modulas = require(`../../server/modulas`);
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config: {
|
||||
auth: false,
|
||||
dropbox: false,
|
||||
|
|
@ -1,17 +1,14 @@
|
|||
'use strict';
|
||||
import serveOnce from 'serve-once';
|
||||
import test from 'supertape';
|
||||
import criton from 'criton';
|
||||
import cloudcmd from '../server/cloudcmd.mjs';
|
||||
|
||||
const test = require('supertape');
|
||||
const criton = require('criton');
|
||||
|
||||
const cloudcmd = require('..');
|
||||
const config = {
|
||||
auth: false,
|
||||
};
|
||||
|
||||
const {request} = require('serve-once')(cloudcmd, {
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
config,
|
||||
});
|
||||
|
||||
const configFn = cloudcmd.createConfigManager();
|
||||
|
||||
test('cloudcmd: static', async (t) => {
|
||||
Loading…
Add table
Add a link
Reference in a new issue