@fc3/mmcadi 0.1.1 → 0.1.3
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.
- package/bin/compile +63 -0
- package/bin/copy-static-files +13 -0
- package/bin/install +5 -0
- package/bin/postpublish +5 -0
- package/bin/precompile +55 -0
- package/bin/prepublish +7 -0
- package/bin/remap-paths +113 -0
- package/bin/test +9 -0
- package/dist/.last-publish-time +1 -1
- package/package.json +5 -3
package/bin/compile
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
if [[ $1 == '--help' ]]; then
|
|
4
|
+
echo "Triggers recompilation of the source code for the current project."
|
|
5
|
+
echo "Supported flags:"
|
|
6
|
+
echo "--force : Bypasses any precompilation checks (cache, mutex, etc)"
|
|
7
|
+
echo " Use this if you want to recompile no matter what."
|
|
8
|
+
echo " "
|
|
9
|
+
exit 0
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
if [[ $1 != '--force' ]]; then
|
|
13
|
+
./bin/precompile
|
|
14
|
+
|
|
15
|
+
case $? in
|
|
16
|
+
1)
|
|
17
|
+
exit 1
|
|
18
|
+
;;
|
|
19
|
+
3)
|
|
20
|
+
exit 0
|
|
21
|
+
;;
|
|
22
|
+
esac
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
echo "Recompiling..."
|
|
26
|
+
mkdir -p dist
|
|
27
|
+
echo $$ > dist/.compile-lock
|
|
28
|
+
rm -f dist/.last-compile-time
|
|
29
|
+
|
|
30
|
+
project_dir="$(dirname $(dirname "$0"))"
|
|
31
|
+
|
|
32
|
+
if [[ $1 == '--force' ]]; then
|
|
33
|
+
rm -rf dist/src
|
|
34
|
+
rm -rf dist/test
|
|
35
|
+
./node_modules/.bin/tsc --declaration --project "$project_dir/config/tsconfig.json"
|
|
36
|
+
else
|
|
37
|
+
./node_modules/.bin/tsc --declaration --incremental --project "$project_dir/config/tsconfig.json"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
exit_status=$?
|
|
41
|
+
|
|
42
|
+
if [[ $exit_status -eq 0 ]]; then
|
|
43
|
+
./bin/remap-paths
|
|
44
|
+
./bin/copy-static-files
|
|
45
|
+
echo $(date +%s) > dist/.last-compile-time
|
|
46
|
+
|
|
47
|
+
./node_modules/.bin/esbuild "$project_dir/src/client/bootstrap.ts" \
|
|
48
|
+
--bundle \
|
|
49
|
+
--tsconfig="$project_dir/config/tsconfig.json" \
|
|
50
|
+
--outfile="$project_dir/dist/client.js" \
|
|
51
|
+
--alias:lib/logger/logger=client/shim/logger.ts \
|
|
52
|
+
--alias:lib/process/execute=client/shim/execute.ts
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
pid=$(cat dist/.compile-lock)
|
|
56
|
+
|
|
57
|
+
if [[ $pid == $$ ]]; then
|
|
58
|
+
rm dist/.compile-lock
|
|
59
|
+
exit $exit_status
|
|
60
|
+
else
|
|
61
|
+
echo "Detected a conflicting compile lock..."
|
|
62
|
+
exit 1
|
|
63
|
+
fi
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
echo "Copying static files to dist..."
|
|
6
|
+
|
|
7
|
+
find "src" -type f ! -name '*.ts' | while read -r file; do
|
|
8
|
+
# Ignore vim swapfiles too:
|
|
9
|
+
if [[ ! "$file" == *"swp"* ]]; then
|
|
10
|
+
echo "$file --> dist/$file"
|
|
11
|
+
cp "$file" "dist/$file"
|
|
12
|
+
fi
|
|
13
|
+
done
|
package/bin/install
ADDED
package/bin/postpublish
ADDED
package/bin/precompile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
mkdir -p dist
|
|
4
|
+
|
|
5
|
+
if [ -f dist/.compile-lock ]; then
|
|
6
|
+
pid=$(cat dist/.compile-lock)
|
|
7
|
+
ticks=0
|
|
8
|
+
max_ticks=10
|
|
9
|
+
|
|
10
|
+
if ! ps -p $pid > /dev/null; then
|
|
11
|
+
echo "Detected a stale compile lock; deleting..."
|
|
12
|
+
rm -f dist/.compile-lock
|
|
13
|
+
else
|
|
14
|
+
echo "Compilation already in progress; waiting up to $max_ticks seconds..."
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
while [ -f dist/.compile-lock ]; do
|
|
18
|
+
sleep 1
|
|
19
|
+
let ticks=ticks+1
|
|
20
|
+
|
|
21
|
+
if [ $ticks -ge $max_ticks ]; then
|
|
22
|
+
echo "Timed out waiting for compilation to clear"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
done
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
if [[ -f ./dist/.last-publish-time ]]; then
|
|
29
|
+
echo "Found publication compile artifact; skipping recompilation."
|
|
30
|
+
exit 3
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
if [ -f dist/.last-compile-time ]; then
|
|
34
|
+
if [ ! -d src ]; then
|
|
35
|
+
# TODO: Confirm we're within a deploy environment
|
|
36
|
+
echo "src folder does not exist; skipping recompilation."
|
|
37
|
+
exit 3
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
typeset -i last_modification_time=$(find src test -type f -print0 |
|
|
41
|
+
xargs -0 stat -c "%X %N" |
|
|
42
|
+
sort -rn |
|
|
43
|
+
head -1 |
|
|
44
|
+
awk '{ print $1 }')
|
|
45
|
+
|
|
46
|
+
typeset -i last_compile_time=$(cat dist/.last-compile-time)
|
|
47
|
+
|
|
48
|
+
if (( $last_compile_time > $last_modification_time )); then
|
|
49
|
+
echo "No changes since last compile; skipping recompilation."
|
|
50
|
+
exit 3
|
|
51
|
+
fi
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# Compilation should occur.
|
|
55
|
+
exit 0
|
package/bin/prepublish
ADDED
package/bin/remap-paths
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const FS = require('fs');
|
|
4
|
+
const Path = require('path');
|
|
5
|
+
|
|
6
|
+
const JAVASCRIPT_EXTENSION = '.js';
|
|
7
|
+
const DECLARATION_EXTENSION = '.d.ts';
|
|
8
|
+
const UTF8_ENCODING = 'utf8';
|
|
9
|
+
const DIST_PATH = Path.resolve(__dirname, '../dist');
|
|
10
|
+
|
|
11
|
+
function processDirectory(directoryPath) {
|
|
12
|
+
const children = FS.readdirSync(directoryPath);
|
|
13
|
+
|
|
14
|
+
children.forEach(function each(child) {
|
|
15
|
+
// Ignore hidden files.
|
|
16
|
+
if (child[0] === '.') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const
|
|
21
|
+
childPath = Path.resolve(directoryPath, child),
|
|
22
|
+
parsedPath = Path.parse(childPath);
|
|
23
|
+
|
|
24
|
+
if (!parsedPath.ext) {
|
|
25
|
+
processDirectory(childPath);
|
|
26
|
+
} else if (parsedPath.ext === JAVASCRIPT_EXTENSION) {
|
|
27
|
+
processSourceFile(childPath);
|
|
28
|
+
} else if (childPath.slice(-5) === DECLARATION_EXTENSION) {
|
|
29
|
+
processDeclarationFile(childPath);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function processSourceFile(filePath) {
|
|
35
|
+
const contents = FS.readFileSync(filePath, UTF8_ENCODING);
|
|
36
|
+
|
|
37
|
+
const lines = contents.split('\n').map(function map(line) {
|
|
38
|
+
return line.replace(/require\("([^"]+)/g, function replacer(match, path) {
|
|
39
|
+
if (path[0] === '.') {
|
|
40
|
+
return match;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let dependencyPath = DIST_PATH + '/src/' + path + '.js';
|
|
44
|
+
|
|
45
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
46
|
+
// Fall back to checking whether there's an index.js in a directory
|
|
47
|
+
// of this name, instead of a toplevel .js source file directly.
|
|
48
|
+
dependencyPath = DIST_PATH + '/src/' + path + '/index.js';
|
|
49
|
+
|
|
50
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
51
|
+
// Well, we tried.
|
|
52
|
+
return match;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const parsedFile = Path.parse(filePath);
|
|
57
|
+
const parsedDependency = Path.parse(dependencyPath);
|
|
58
|
+
|
|
59
|
+
let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
|
|
60
|
+
|
|
61
|
+
if (relativeDirectory === '') {
|
|
62
|
+
relativeDirectory = '.';
|
|
63
|
+
} else {
|
|
64
|
+
relativeDirectory = './' + relativeDirectory;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const relativePath = relativeDirectory + '/' + parsedDependency.base;
|
|
68
|
+
|
|
69
|
+
return 'require("' + relativePath;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function processDeclarationFile(filePath) {
|
|
77
|
+
const contents = FS.readFileSync(filePath, UTF8_ENCODING);
|
|
78
|
+
|
|
79
|
+
const lines = contents.split('\n').map(function map(line) {
|
|
80
|
+
return line.replace(/from '([^']+)/g, function replacer(match, path) {
|
|
81
|
+
if (path[0] === '.') {
|
|
82
|
+
return match;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const dependencyPath = DIST_PATH + '/src/' + path + '.d.ts';
|
|
86
|
+
|
|
87
|
+
if (!FS.existsSync(dependencyPath)) {
|
|
88
|
+
return match;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const parsedFile = Path.parse(filePath);
|
|
92
|
+
const parsedDependency = Path.parse(dependencyPath);
|
|
93
|
+
|
|
94
|
+
let relativeDirectory = Path.relative(parsedFile.dir, parsedDependency.dir);
|
|
95
|
+
|
|
96
|
+
if (relativeDirectory === '') {
|
|
97
|
+
relativeDirectory = '.';
|
|
98
|
+
} else {
|
|
99
|
+
relativeDirectory = './' + relativeDirectory;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let relativePath = relativeDirectory + '/' + parsedDependency.base;
|
|
103
|
+
|
|
104
|
+
relativePath = relativePath.replace(DECLARATION_EXTENSION, '');
|
|
105
|
+
|
|
106
|
+
return "from '" + relativePath;
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
FS.writeFileSync(filePath, lines.join('\n'), UTF8_ENCODING);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
processDirectory('./dist', 0);
|
package/bin/test
ADDED
package/dist/.last-publish-time
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1760931903
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fc3/mmcadi",
|
|
3
3
|
"description": "multimedia calendar + diary",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"author": "fc3",
|
|
6
6
|
"private": false,
|
|
7
7
|
"homepage": "https://0xfc3/software/mmcadi",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"dist/",
|
|
14
14
|
"package.json",
|
|
15
15
|
"README.md",
|
|
16
|
-
"public/.keep"
|
|
16
|
+
"public/.keep",
|
|
17
|
+
"bin/"
|
|
17
18
|
],
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"formidable": "^3.5.2",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"scripts": {
|
|
37
38
|
"install": "./bin/install",
|
|
38
39
|
"test": "./bin/test",
|
|
39
|
-
"prepublishOnly": "./bin/prepublish"
|
|
40
|
+
"prepublishOnly": "./bin/prepublish",
|
|
41
|
+
"postpublish": "./bin/postpublish"
|
|
40
42
|
}
|
|
41
43
|
}
|