@syncify/cli 1.0.0-alpha.1 → 1.0.0-unstable.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ // This script uses conditional logic to work in both CJS and ESM environments
2
+ (async () => {
3
+
4
+ let fs;
5
+ let path;
6
+ let os;
7
+
8
+ if (typeof require === 'function') {
9
+
10
+ // CommonJS environment
11
+ fs = require('fs');
12
+ path = require('path');
13
+ os = require('os');
14
+
15
+ } else {
16
+
17
+ // ES Module environment
18
+ ({ default: fs } = await import('fs'));
19
+ ({ default: path } = await import('path'));
20
+ ({ default: os } = await import('os'));
21
+
22
+ }
23
+
24
+ // Files to be generated
25
+
26
+ const green = (text) => `\x1b[1;32m${text}\x1b[0m`;
27
+ const gray = (text) => `\x1b[0;90m${text}\x1b[0m`;
28
+ const whiteBold = (text) => `\x1b[1;37m${text}\x1b[0m`;
29
+
30
+ const created = 'created' + gray(':');
31
+ const updated = 'updated' + gray(':');
32
+
33
+ const syncifyDir = path.join(os.homedir(), '.syncify');
34
+ const keychainFile = path.join(syncifyDir, '.keychain');
35
+ const versionsFile = path.join(syncifyDir, '.version');
36
+ const notifyIconFile = path.join(syncifyDir, 'icon.png');
37
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
38
+
39
+ let hasLogged = false;
40
+ let hasNewline = 1;
41
+
42
+ const logName = () => {
43
+ if (!hasLogged) {
44
+ console.log(' ');
45
+ console.log(` ${green('@syncify/cli')} ${gray('→')} ${whiteBold('postinstall')}`);
46
+ console.log(' ');
47
+ console.log(` version${gray(':')} ${gray(`v${pkg.version}`)}`);
48
+ hasLogged = true;
49
+ }
50
+ };
51
+
52
+ // First we create the .syncify directory
53
+ if (!fs.existsSync(syncifyDir)) {
54
+ logName();
55
+ fs.mkdirSync(syncifyDir);
56
+ console.log(` ${created} ${gray(syncifyDir)}`);
57
+ hasNewline = 2;
58
+ }
59
+
60
+ // Lets create the .syncify/.keychain file if it does not exist
61
+ if (!fs.existsSync(keychainFile)) {
62
+ logName();
63
+ fs.writeFileSync(keychainFile, '{}');
64
+ console.log(` ${created} ${gray(keychainFile)}`);
65
+ hasNewline = 2;
66
+ }
67
+
68
+ // Lets copy the notifier icon if it does not exist
69
+ if (!fs.existsSync(notifyIconFile)) {
70
+ logName();
71
+ fs.copyFileSync('icon.png', notifyIconFile);
72
+ console.log(` ${created} ${gray(notifyIconFile)}`);
73
+ hasNewline = 2;
74
+ }
75
+
76
+ const cwd = process.cwd();
77
+
78
+ // Lets create the .syncify/.versions file if it does not exist
79
+ if (!fs.existsSync(versionsFile)) {
80
+
81
+ logName();
82
+
83
+ fs.writeFileSync(versionsFile, JSON.stringify({ [cwd]: pkg.version }));
84
+
85
+ console.log(` ${created} ${gray(versionsFile)}`);
86
+ console.log(' ');
87
+ hasNewline = 3;
88
+
89
+ } else {
90
+
91
+ const ver = JSON.parse(fs.readFileSync(versionsFile).toString());
92
+ const hasVer = cwd in ver;
93
+
94
+ if (hasVer === false || (hasVer === true && ver[cwd] !== pkg.version)) {
95
+
96
+ logName();
97
+
98
+ ver[cwd] = pkg.version;
99
+
100
+ fs.writeFileSync(versionsFile, JSON.stringify(ver));
101
+
102
+ console.log(` ${updated} ${gray(versionsFile)}`);
103
+ console.log(' ');
104
+ hasNewline = 3;
105
+ }
106
+ }
107
+
108
+ if (hasNewline === 2) {
109
+ console.log(' ');
110
+ }
111
+
112
+ })().catch(err => {
113
+
114
+ console.error('𐄂 syncify postinstall:', err);
115
+
116
+ });
@@ -0,0 +1,60 @@
1
+ // This script uses conditional logic to work in both CJS and ESM environments
2
+ (async () => {
3
+
4
+ let fs;
5
+ let path;
6
+ let os;
7
+
8
+ if (typeof require === 'function') {
9
+
10
+ // CommonJS environment
11
+ fs = require('fs');
12
+ path = require('path');
13
+ os = require('os');
14
+
15
+ } else {
16
+
17
+ // ES Module environment
18
+ ({ default: fs } = await import('fs'));
19
+ ({ default: path } = await import('path'));
20
+ ({ default: os } = await import('os'));
21
+
22
+ }
23
+
24
+ // Read package.json for version information
25
+ const cwd = process.cwd();
26
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
27
+ const gray = (text) => `\x1b[0;90m${text}\x1b[0m`;
28
+
29
+ // Files to be generated
30
+ const syncifyDir = path.join(os.homedir(), '.syncify');
31
+ const versionsFile = path.join(syncifyDir, '.version');
32
+ const versions = JSON.parse(fs.readFileSync(versionsFile).toString());
33
+
34
+ if (cwd in versions) {
35
+
36
+ const ver = versions[cwd];
37
+
38
+ if (ver !== pkg.version) {
39
+
40
+ console.log(' ');
41
+ console.log(` ${green('@syncify/cli')} ${gray('→')} ${whiteBold('postversion')}`);
42
+ console.log(' ');
43
+ console.log(` version${gray(':')} ${gray(`v${pkg.version}`)}`);
44
+
45
+ versions[cwd] = pkg.version;
46
+
47
+ fs.writeFileSync(versionsFile, JSON.stringify(versions));
48
+
49
+ console.log(` updated${gray(':')}${gray(`${versionsFile}`)}`);
50
+ console.log(' ');
51
+
52
+ }
53
+
54
+ }
55
+
56
+ })().catch(err => {
57
+
58
+ console.error('𐄂 syncify postversion:', err);
59
+
60
+ });