Skip to content

Commit ed9bae7

Browse files
committed
refactor
1 parent 8c8a781 commit ed9bae7

8 files changed

Lines changed: 27 additions & 26 deletions

File tree

bin/pos-cli-sync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ program
5050
// Continue with watch mode
5151
const { watcher, liveReloadServer } = await watchStart(env, params.directAssetsUpload, params.livereload);
5252

53+
setupGracefulShutdown({ watcher, liveReloadServer, context: 'Sync' });
54+
5355
if (params.open) {
5456
try {
5557
const open = (await import('open')).default;
@@ -62,8 +64,6 @@ program
6264
}
6365
}
6466
}
65-
66-
setupGracefulShutdown({ watcher, liveReloadServer, context: 'Sync' });
6767
});
6868

6969
program.parse(process.argv);

lib/archive.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import logger from './logger.js';
88
import dir from './directories.js';
99
import prepareArchive from './prepareArchive.js';
1010

11-
const isEmpty = d => shell.ls(d).length == 0;
11+
const isEmpty = d => shell.ls(d).length === 0;
1212

1313
const addModulesToArchive = async (archive, withoutAssets) => {
1414
if (!fs.existsSync(dir.MODULES)) {
@@ -27,7 +27,7 @@ const addModuleToArchive = async (module, archive, withoutAssets, pattern = '**/
2727
const moduleTemplateData = loadSettingsFileForModule(module);
2828

2929
for (const f of files) {
30-
if (withoutAssets && (f.startsWith('public/assets/') || f.startsWith('private/assets'))) {
30+
if (withoutAssets && (f.startsWith('public/assets/') || f.startsWith('private/assets/'))) {
3131
continue;
3232
}
3333
const realPath = path.join(dir.MODULES, module, f);
@@ -75,8 +75,7 @@ const makeArchive = async (env, { withoutAssets }) => {
7575
const appFiles = await glob(['**/*', '!**/*.zip'], {
7676
cwd: directory,
7777
onlyFiles: true,
78-
ignore: withoutAssets ? ['assets/**'] : [],
79-
dot: true
78+
ignore: withoutAssets ? ['assets/**'] : []
8079
});
8180

8281
for (const f of appFiles) {

lib/assets/packAssets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const packAssets = async outputPath => {
3636
const archive = prepareArchive(outputPath);
3737

3838
if (fs.existsSync(`${appDirectory}/assets`)) {
39-
const assetFiles = await glob('**/*', { cwd: `${appDirectory}/assets`, onlyFiles: true, dot: true });
39+
const assetFiles = await glob('**/*', { cwd: `${appDirectory}/assets`, onlyFiles: true });
4040
for (const f of assetFiles) {
4141
archive.addFile(path.join(appDirectory, 'assets', f), f);
4242
}

lib/check.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const checkThemeCheck = async () => {
2828
const validatePath = async (checkPath) => {
2929
if (!fs.existsSync(checkPath)) {
3030
await logger.Error(`Path does not exist: ${checkPath}`);
31+
return;
3132
}
3233

3334
const stats = fs.statSync(checkPath);
@@ -367,7 +368,6 @@ const run = async (opts) => {
367368

368369
try {
369370
// Run checks with progress callback
370-
let fileCount = 0;
371371
const result = await themeCheck.themeCheckRun(checkPath, undefined, (message) => {
372372
if (spinner && message) {
373373
spinner.text = message;
@@ -376,10 +376,10 @@ const run = async (opts) => {
376376

377377
offenses = result.offenses;
378378
theme = result.theme;
379-
fileCount = theme.length;
380379

381380
// Update spinner with completion info if it's still running
382381
if (spinner && spinner.isSpinning) {
382+
const fileCount = theme.length;
383383
spinner.text = `Checked ${fileCount} file${fileCount === 1 ? '' : 's'}`;
384384
}
385385

@@ -414,7 +414,7 @@ const run = async (opts) => {
414414
}
415415

416416
if (offenses.length > 0) {
417-
process.exit(1);
417+
process.exitCode = 1;
418418
}
419419
};
420420

lib/deploy/directAssetsUploadStrategy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ const strategy = async ({ env, authData, _params }) => {
3434
spinner.start();
3535

3636
const t0 = performance.now();
37-
await deployAndUploadAssets(authData);
38-
3937
if (numberOfFiles > 0) {
4038
await uploadArchive(env);
4139
} else {
4240
logger.Warn('There are no files in release file, skipping.');
4341
}
4442

43+
await deployAndUploadAssets(authData);
44+
4545
spinner.succeed(`Deploy succeeded after ${duration(t0, performance.now())}`);
4646
} catch (e) {
4747
if (ServerError.isNetworkError(e)) {

lib/modules.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,32 @@ const moduleConfigFilePath = async (moduleName='*') => {
3939
};
4040

4141
const createArchive = async (moduleName) => {
42+
if (!fs.existsSync(moduleConfigFileName) && !fs.existsSync(`modules/${moduleName}/`)) {
43+
throw new Error(`There is no directory modules/${moduleName} - please double check the machine_name property in ${filePath}`);
44+
}
45+
4246
const archive = prepareArchive(archivePath, true);
4347

4448
if (fs.existsSync(moduleConfigFileName) && !fs.existsSync('modules/')) {
4549
logger.Warn(`Cannot find modules/${moduleName}, creating archive with the current directory.`);
4650
const moduleFiles = await glob(['**/**', moduleConfigFileName], {
4751
ignore: ['**/node_modules/**', '**/tmp/**', 'app/**'],
48-
onlyFiles: true,
49-
dot: true
52+
onlyFiles: true
5053
});
5154
for (const f of moduleFiles) {
5255
archive.addFile(f, `${moduleName}/${f}`);
5356
}
54-
} else if (fs.existsSync(`modules/${moduleName}/`)) {
57+
} else {
5558
logger.Info(`Creating archive for modules/${moduleName}`);
5659
const moduleDir = path.join(process.cwd(), 'modules', moduleName);
5760
const moduleFiles = await glob(['**/**', moduleConfigFileName], {
5861
ignore: ['**/node_modules/**', '**/tmp/**'],
5962
cwd: moduleDir,
60-
onlyFiles: true,
61-
dot: true
63+
onlyFiles: true
6264
});
6365
for (const f of moduleFiles) {
6466
archive.addFile(path.join('modules', moduleName, f), `${moduleName}/${f}`);
6567
}
66-
} else {
67-
archive.finalize();
68-
throw new Error(`There is no directory modules/${moduleName} - please double check the machine_name property in ${filePath}`);
6968
}
7069

7170
archive.finalize();

lib/watch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ const pushFile = async (gateway, syncedFilePath) => {
6969
logger.Warn('[Sync] WARNING: Data schema was updated. It will take a while for the change to be applied.');
7070
}
7171

72-
logger.Success(`[Sync] Synced: ${filePath}`);
72+
if (body) {
73+
logger.Success(`[Sync] Synced: ${filePath}`);
74+
}
7375
} catch (e) {
7476
// Handle validation errors (422) with custom formatting
7577
if (e.statusCode === 422 && e.response && e.response.body) {

test/utils/waitForOutput.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
const waitForOutput = (child, pattern, timeout = 15000) => {
1+
const waitForOutput = (child, pattern, { timeout = 15000, stream = 'stdout' } = {}) => {
22
return new Promise((resolve, reject) => {
33
let buffer = '';
4+
const source = child[stream];
45

56
const onData = (chunk) => {
67
buffer += chunk.toString();
78
if (pattern.test(buffer)) {
89
clearTimeout(timer);
9-
child.stdout.off('data', onData);
10+
source.off('data', onData);
1011
resolve();
1112
}
1213
};
1314

1415
const timer = setTimeout(() => {
15-
child.stdout.off('data', onData);
16-
reject(new Error(`Timeout (${timeout}ms) waiting for output: ${pattern}`));
16+
source.off('data', onData);
17+
reject(new Error(`Timeout (${timeout}ms) waiting for ${stream} output: ${pattern}`));
1718
}, timeout);
1819

19-
child.stdout.on('data', onData);
20+
source.on('data', onData);
2021
});
2122
};
2223

0 commit comments

Comments
 (0)