Skip to content

Commit 0e01f11

Browse files
committed
feat: stick lastCompiledAt date to the build .adonisrc.json file
This helps some commands critical on always using the latest code to have some idea around how stale the code is
1 parent 5d31f66 commit 0e01f11

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@poppinss/utils": "^2.1.2",
9696
"chokidar": "^3.3.1",
9797
"cpy": "^8.0.1",
98+
"debounce": "^1.2.0",
9899
"emittery": "^0.5.1",
99100
"execa": "^4.0.0",
100101
"fs-extra": "^8.1.0",

src/Compiler/index.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import mem from 'mem'
1111
import slash from 'slash'
1212
import copyfiles from 'cpy'
13+
import debounce from 'debounce'
1314
import tsStatic from 'typescript'
1415
import { join, relative } from 'path'
1516
import { Logger } from '@poppinss/fancy-logs'
@@ -58,6 +59,11 @@ export class Compiler {
5859
*/
5960
public manifest = new Manifest(this.appRoot, this.logger)
6061

62+
/**
63+
* Same as [[this.writeRcFile]] but waits for 2secs
64+
*/
65+
public touchRcFile = debounce(this.writeRcFile.bind(this), 2000)
66+
6167
/**
6268
* Returns relative unix path from the project root. Used for
6369
* display only
@@ -75,6 +81,20 @@ export class Compiler {
7581
}, 'after')
7682
}
7783

84+
/**
85+
* write .adonisrc.json file to the build directory
86+
*/
87+
private async writeRcFile (outDir: string) {
88+
await outputJSON(
89+
join(outDir, RCFILE_NAME),
90+
Object.assign({}, this.rcFile.getDiskContents(), {
91+
typescript: false,
92+
lastCompiledAt: new Date().toISOString(),
93+
}),
94+
{ spaces: 2 },
95+
)
96+
}
97+
7898
/**
7999
* Create the http server
80100
*/
@@ -133,11 +153,7 @@ export class Compiler {
133153
*/
134154
public async copyAdonisRcFile (outDir: string) {
135155
this.logger.info({ message: `copy ${RCFILE_NAME}`, suffix: this.getRelativeUnixPath(outDir) })
136-
await outputJSON(
137-
join(outDir, RCFILE_NAME),
138-
Object.assign({}, this.rcFile.getDiskContents(), { typescript: false }),
139-
{ spaces: 2 },
140-
)
156+
await this.writeRcFile(outDir)
141157
}
142158

143159
/**
@@ -194,9 +210,10 @@ export class Compiler {
194210
}
195211

196212
await this.cleanupBuildDirectory(config.options.outDir!)
197-
await this.copyAdonisRcFile(config.options.outDir!)
198213
await this.copyMetaFiles(config.options.outDir!)
199214
this.buildTypescriptSource(config)
215+
await this.copyAdonisRcFile(config.options.outDir!)
216+
200217
await this.manifest.generate()
201218

202219
/**
@@ -224,9 +241,9 @@ export class Compiler {
224241
: ['package.json', 'yarn.lock']
225242

226243
await this.cleanupBuildDirectory(config.options.outDir!)
227-
await this.copyAdonisRcFile(config.options.outDir!)
228244
await this.copyMetaFiles(config.options.outDir!, pkgFiles)
229245
this.buildTypescriptSource(config)
246+
await this.copyAdonisRcFile(config.options.outDir!)
230247

231248
this.logger.info({ message: 'installing production dependencies', suffix: client })
232249
await new Installer(config.options.outDir!, client).install()

src/Watcher/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export class Watcher {
4848
* Standard build steps
4949
*/
5050
await this.compiler.cleanupBuildDirectory(config.options.outDir!)
51-
await this.compiler.copyAdonisRcFile(config.options.outDir!)
5251
await this.compiler.copyMetaFiles(config.options.outDir!)
5352
this.compiler.buildTypescriptSource(config)
53+
await this.compiler.copyAdonisRcFile(config.options.outDir!)
5454

5555
/**
5656
* Manifest can be generated without blocking the flow
@@ -83,7 +83,7 @@ export class Watcher {
8383
/**
8484
* Subsequent source builds
8585
*/
86-
watcher.on('subsequent:build', ({ path, skipped, diagnostics }) => {
86+
watcher.on('subsequent:build', async ({ path, skipped, diagnostics }) => {
8787
this.clearScreen()
8888
this.logger.compile(path)
8989

@@ -109,6 +109,8 @@ export class Watcher {
109109
if (this.compiler.rcFile.isCommandsPath(path)) {
110110
this.compiler.manifest.generate()
111111
}
112+
113+
await this.compiler.touchRcFile(config.options.outDir!)
112114
})
113115

114116
/**

test/compiler.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ test.group('Compiler', (group) => {
5656
assert.deepEqual(hasFiles, [true, true, true, true, true])
5757
assert.deepEqual(logger.logs, [
5858
'underline(blue(info)) cleaning up build directory dim(yellow(build))',
59-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
6059
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build))',
6160
'underline(magenta(pending)) compiling typescript source files',
6261
'underline(green(success)) built successfully',
62+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
6363
])
6464

6565
assert.isFalse(require(join(fs.basePath, 'build', '.adonisrc.json')).typescript)
@@ -99,10 +99,10 @@ test.group('Compiler', (group) => {
9999
assert.deepEqual(hasFiles, [true, true, true, true])
100100
assert.deepEqual(logger.logs, [
101101
'underline(blue(info)) cleaning up build directory dim(yellow(build))',
102-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
103102
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build))',
104103
'underline(magenta(pending)) compiling typescript source files',
105104
'underline(green(success)) built successfully',
105+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
106106
])
107107
}).timeout(0)
108108

@@ -141,10 +141,10 @@ test.group('Compiler', (group) => {
141141
assert.deepEqual(hasFiles, [true, true, true, true])
142142
assert.deepEqual(logger.logs, [
143143
'underline(blue(info)) cleaning up build directory dim(yellow(build))',
144-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
145144
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build))',
146145
'underline(magenta(pending)) compiling typescript source files',
147146
'underline(green(success)) built successfully',
147+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
148148
])
149149
}).timeout(0)
150150

@@ -182,10 +182,10 @@ test.group('Compiler', (group) => {
182182
assert.deepEqual(hasFiles, [true, true, true, true])
183183
assert.deepEqual(logger.logs, [
184184
'underline(blue(info)) cleaning up build directory dim(yellow(build/dist))',
185-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build/dist))',
186185
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build/dist))',
187186
'underline(magenta(pending)) compiling typescript source files',
188187
'underline(green(success)) built successfully',
188+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build/dist))',
189189
])
190190
}).timeout(0)
191191

@@ -224,10 +224,10 @@ test.group('Compiler', (group) => {
224224

225225
assert.deepEqual(logger.logs, [
226226
'underline(blue(info)) cleaning up build directory dim(yellow(build/dist))',
227-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build/dist))',
228227
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build/dist))',
229228
'underline(magenta(pending)) compiling typescript source files',
230229
'underline(red(error)) typescript compiler errors',
230+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build/dist))',
231231
])
232232
}).timeout(0)
233233

@@ -267,11 +267,11 @@ test.group('Compiler', (group) => {
267267

268268
assert.deepEqual(logger.logs, [
269269
'underline(blue(info)) cleaning up build directory dim(yellow(build/dist))',
270-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build/dist))',
271270
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build/dist))',
272271
'underline(magenta(pending)) compiling typescript source files',
273272
'underline(blue(info)) TS emit skipped',
274273
'underline(red(error)) typescript compiler errors',
274+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build/dist))',
275275
])
276276
}).timeout(0)
277277

@@ -321,10 +321,10 @@ test.group('Compiler', (group) => {
321321
assert.deepEqual(hasFiles, [true, true, true, true])
322322
assert.deepEqual(logger.logs, [
323323
'underline(blue(info)) cleaning up build directory dim(yellow(build))',
324-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
325324
'underline(blue(info)) copy public/**/*.(js|css),ace,package.json,package-lock.json dim(yellow(build))',
326325
'underline(magenta(pending)) compiling typescript source files',
327326
'underline(green(success)) built successfully',
327+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
328328
'underline(blue(info)) installing production dependencies dim(yellow(npm))',
329329
])
330330

@@ -368,10 +368,10 @@ test.group('Compiler', (group) => {
368368
assert.deepEqual(hasFiles, [true, true, true, true, true])
369369
assert.deepEqual(logger.logs, [
370370
'underline(blue(info)) cleaning up build directory dim(yellow(build))',
371-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
372371
'underline(blue(info)) copy public/**/*.(js|css),ace dim(yellow(build))',
373372
'underline(magenta(pending)) compiling typescript source files',
374373
'underline(green(success)) built successfully',
374+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
375375
'underline(yellow(warn)) Unable to generate manifest file. Check the following error stack for more info',
376376
])
377377

@@ -410,10 +410,10 @@ test.group('Compiler', (group) => {
410410
assert.deepEqual(hasFiles, [true, false, true])
411411
assert.deepEqual(logger.logs, [
412412
'underline(blue(info)) cleaning up build directory dim(yellow(build))',
413-
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
414413
'underline(blue(info)) copy ace dim(yellow(build))',
415414
'underline(magenta(pending)) compiling typescript source files',
416415
'underline(green(success)) built successfully',
416+
'underline(blue(info)) copy .adonisrc.json dim(yellow(build))',
417417
'underline(yellow(warn)) Unable to generate manifest file. Check the following error stack for more info',
418418
])
419419

0 commit comments

Comments
 (0)