Files
react-native-devtools-frontend/scripts/build/generate_css_js_files.js
T
Tim van der Lippe 28af9fbe78 Reland "Do not overwrite generated files when contents remains the same"
This reverts commit aaae6b021a.

Reason for revert: always check if tsconfig.json needs to be updated

Original change's description:
> Revert "Do not overwrite generated files when contents remains the same"
>
> This reverts commit c1e414725a.
>
> Reason for revert: Seems to be the cause for CQ compilation errors:
> https://ci.chromium.org/ui/p/devtools-frontend/builders/try/devtools_frontend_linux_blink_light_rel/19852/overview
>
> Original change's description:
> > Do not overwrite generated files when contents remains the same
> >
> > To ensure that build timestamps don't unnecessarily cause full rebuilds,
> > make sure that we only write the generated contents to a file (if it
> > exists already) if it would be the same. This ensures that the file
> > timestamps remain the same, which will lead GN to conclude that the
> > build action is a noop (which it is).
> >
> > On a new year, the file contents would actually be different, so it
> > would cause a proper rebuild. However, in all months between when the
> > timestamp changes, it won't cause is unnecessarily to rebuild all these
> > files, even though the year hasn't changed (but the timestamp it was
> > based on did).
> >
> > R=​jacktfranklin@chromium.org
> >
> > Bug: 1283883
> > Change-Id: I2bdc3a79de710236c1501b21fa505692336cfa82
> > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3377942
> > Auto-Submit: Tim Van der Lippe <tvanderlippe@chromium.org>
> > Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
> > Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
>
> Bug: 1283883
> Change-Id: I938cfe20a7ecf6df6c7becc9fa73a3dcfebe457c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3380583
> Auto-Submit: Simon Zünd <szuend@chromium.org>
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>

Bug: 1283883
Change-Id: Iae23d721bdeb4c8af227903a38255ee9fc1bc49d
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3386675
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2022-01-13 15:20:09 +00:00

63 lines
2.0 KiB
JavaScript

// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const fs = require('fs');
const path = require('path');
const CleanCSS = require('clean-css');
const {writeIfChanged} = require('./ninja/write-if-changed.js');
const [, , buildTimestamp, isDebugString, legacyString, targetName, srcDir, targetGenDir, files] = process.argv;
const filenames = files.split(',');
const configFiles = [];
const cleanCSS = new CleanCSS();
const isDebug = isDebugString === 'true';
const isLegacy = legacyString === 'true';
for (const fileName of filenames) {
let output = fs.readFileSync(path.join(srcDir, fileName), {encoding: 'utf8', flag: 'r'});
output = output.replace(/\`/g, '\\\'');
output = output.replace(/\\/g, '\\\\');
const stylesheetContents = isDebug ? output : cleanCSS.minify(output).styles;
let exportStatement;
if (isLegacy) {
exportStatement = `export default {
cssContent: \`${stylesheetContents}\`
};`;
} else {
exportStatement = `const styles = new CSSStyleSheet();
styles.replaceSync(
\`${stylesheetContents}
/*# sourceURL=${fileName} */
\`);
export default styles;`;
}
const generatedFileName = `${fileName}${isLegacy ? '.legacy' : ''}.js`;
const generatedFileLocation = path.join(targetGenDir, generatedFileName);
const newContents = `// Copyright ${
new Date(Number(buildTimestamp) * 1000).getUTCFullYear()} The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// IMPORTANT: this file is auto generated. Please do not edit this file.
/* istanbul ignore file */
${exportStatement}
`;
writeIfChanged(generatedFileLocation, newContents);
configFiles.push(`\"${generatedFileName}\"`);
}
writeIfChanged(path.join(targetGenDir, `${targetName}-tsconfig.json`), `{
"compilerOptions": {
"composite": true,
"outDir": "."
},
"files": [
${configFiles.join(',\n ')}
]
}
`);