Skip to content

Commit d4453cb

Browse files
committed
symlink cache
1 parent eb38f59 commit d4453cb

File tree

8 files changed

+16
-5
lines changed

8 files changed

+16
-5
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
node_modules
1+
node_modules
2+
bin/packages/*/
3+
bin/staging/*/
File renamed without changes.

bin/packages/.gitkeep

Whitespace-only changes.

bin/staging/.gitkeep

Whitespace-only changes.

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require('dotenv').config();
33

44
import fs from 'fs';
5+
import path from 'path';
56
import socketio from 'socket.io';
67
import files from './utils/files';
78
import boards from './utils/boards';
@@ -12,7 +13,7 @@ import program from './utils/program';
1213
const io = socketio(process.env.PORT || 3030);
1314

1415
const initFiles = [
15-
{ name: 'arduino-cli.yaml', content: fs.readFileSync(`${__dirname}/bin/arduino-cli.yaml`) },
16+
{ name: 'arduino-cli.yaml', content: fs.readFileSync(path.join(__dirname, '../bin/arduino-cli.yaml')) },
1617
];
1718

1819
io.on('connection', async (socket) => {
@@ -21,7 +22,7 @@ io.on('connection', async (socket) => {
2122
await libs.indexUpdate(socket);
2223

2324
socket.on('files.new', (fileObjects, done) => files.loadTempFiles(fileObjects, socket, 'files', done));
24-
socket.on('files.setSketch', (path, done) => files.setSketch(path, socket, 'files', done));
25+
socket.on('files.setSketch', (sketchPath, done) => files.setSketch(sketchPath, socket, 'files', done));
2526

2627
// socket.on('core.index.new', (indexes, done) => cores.indexNew(indexes, socket, done));
2728
// socket.on('core.index.list', done => cores.indexList(socket, done));

src/utils/arduino-exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (commands, args, socket, options) => new Promise((resolve) => {
1212
if (opts.emit) socket.emit('console.log', data.toString('utf-8'));
1313
};
1414

15-
const exec = spawn(`${__dirname}/../bin/arduino-cli`, [
15+
const exec = spawn(`${__dirname}/../../bin/arduino-cli`, [
1616
...(Array.isArray(commands) ? commands : commands.split('.')),
1717
..._.castArray(args).map(arg => `${`${arg}`.replace(/"/g, '')}`),
1818
'--config-file',

src/utils/files.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ const files = {
1313
}
1414
},
1515

16+
_initTmp: async () => {
17+
const tmpDir = await tmp.dir({ prefix: 'cd-', unsafeCleanup: true });
18+
await fs.mkdir(path.join(tmpDir.path, 'data'));
19+
await fs.symlink(path.join(__dirname, '../../bin/staging'), path.join(tmpDir.path, 'data/staging'));
20+
await fs.symlink(path.join(__dirname, '../../bin/packages'), path.join(tmpDir.path, 'data/packages'));
21+
return tmpDir;
22+
},
23+
1624
loadTempFiles: async (fileItems, socket, sub = '', done) => {
1725
if (typeof sub !== 'string') {
1826
done = sub;
1927
sub = '';
2028
}
2129
// eslint-disable-next-line no-param-reassign
22-
socket.tmpDir = socket.tmpDir || await tmp.dir({ prefix: 'cd-', unsafeCleanup: true });
30+
socket.tmpDir = socket.tmpDir || await files._initTmp();
2331
// const id = socket.tmpDir.path.split('/').pop();
2432
await Promise.all(fileItems.map(async (file) => {
2533
const filepath = path.join(socket.tmpDir.path, sub, file.name);

0 commit comments

Comments
 (0)