1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Chore: Automatically build migration index

This commit is contained in:
Laurent Cozic 2024-01-04 17:18:57 +00:00
parent 9aa7240d5e
commit a281163353
15 changed files with 69 additions and 41 deletions

View File

@ -781,6 +781,7 @@ packages/lib/services/database/migrations/42.js
packages/lib/services/database/migrations/43.js
packages/lib/services/database/migrations/44.js
packages/lib/services/database/migrations/45.js
packages/lib/services/database/migrations/index.js
packages/lib/services/database/sqlStringToLines.js
packages/lib/services/database/types.js
packages/lib/services/debug/populateDatabase.js

1
.gitignore vendored
View File

@ -761,6 +761,7 @@ packages/lib/services/database/migrations/42.js
packages/lib/services/database/migrations/43.js
packages/lib/services/database/migrations/44.js
packages/lib/services/database/migrations/45.js
packages/lib/services/database/migrations/index.js
packages/lib/services/database/sqlStringToLines.js
packages/lib/services/database/types.js
packages/lib/services/debug/populateDatabase.js

View File

@ -13,7 +13,7 @@
},
"scripts": {
"buildApiDoc": "yarn workspace joplin start apidoc ../../readme/api/references/rest_api.md",
"buildCommandIndex": "node packages/tools/gulp/tasks/buildCommandIndexRun.js",
"buildScriptIndexes": "node packages/tools/gulp/tasks/buildScriptIndexesRun.js",
"buildParallel": "yarn workspaces foreach --verbose --interlaced --parallel --jobs 2 --topological run build && yarn run tsc",
"buildPluginDoc": "cd packages/generate-plugin-doc && yarn run buildPluginDoc_",
"buildSequential": "yarn workspaces foreach --verbose --interlaced --topological run build && yarn run tsc",

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as copyDevCommand from './copyDevCommand';
import * as editProfileConfig from './editProfileConfig';
import * as exportFolders from './exportFolders';
@ -36,4 +36,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as addProfile from './addProfile';
import * as commandPalette from './commandPalette';
import * as deleteFolder from './deleteFolder';
@ -92,4 +92,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as focusElementNoteBody from './focusElementNoteBody';
import * as focusElementNoteTitle from './focusElementNoteTitle';
import * as pasteAsText from './pasteAsText';
@ -14,4 +14,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as focusElementNoteList from './focusElementNoteList';
const index:any[] = [
@ -6,4 +6,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as focusSearch from './focusSearch';
const index:any[] = [
@ -6,4 +6,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as focusElementSideBar from './focusElementSideBar';
const index:any[] = [
@ -6,4 +6,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -39,7 +39,7 @@ const tasks = {
},
tsc: require('@joplin/tools/gulp/tasks/tsc'),
updateIgnoredTypeScriptBuild: require('@joplin/tools/gulp/tasks/updateIgnoredTypeScriptBuild'),
buildCommandIndex: require('@joplin/tools/gulp/tasks/buildCommandIndex'),
buildScriptIndexes: require('@joplin/tools/gulp/tasks/buildScriptIndexes'),
compileSass: {
fn: async () => {
await compileSass(
@ -58,7 +58,7 @@ const buildBeforeStartParallel = [
'copyPluginAssets',
'copyApplicationAssets',
'updateIgnoredTypeScriptBuild',
'buildCommandIndex',
'buildScriptIndexes',
'compileSass',
];

View File

@ -1,13 +1,10 @@
import Resource from './models/Resource';
import shim from './shim';
import Database from './database';
import migration42 from './services/database/migrations/42';
import migration43 from './services/database/migrations/43';
import migration44 from './services/database/migrations/44';
import migration45 from './services/database/migrations/45';
import { SqlQuery, Migration } from './services/database/types';
import { SqlQuery } from './services/database/types';
import addMigrationFile from './services/database/addMigrationFile';
import sqlStringToLines from './services/database/sqlStringToLines';
import migrations from './services/database/migrations';
const { sprintf } = require('sprintf-js');
@ -125,13 +122,6 @@ CREATE TABLE version (
INSERT INTO version (version) VALUES (1);
`;
const migrations: Migration[] = [
migration42,
migration43,
migration44,
migration45,
];
export interface TableField {
name: string;
type: number;

View File

@ -1,4 +1,4 @@
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`
import * as historyBackward from './historyBackward';
import * as historyForward from './historyForward';
import * as openMasterPasswordDialog from './openMasterPasswordDialog';
@ -12,4 +12,4 @@ const index:any[] = [
];
export default index;
// AUTO-GENERATED using `gulp buildCommandIndex`
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -0,0 +1,17 @@
// AUTO-GENERATED using `gulp buildScriptIndexes`
import migration42 from './42';
import migration43 from './43';
import migration44 from './44';
import migration45 from './45';
import { Migration } from '../types';
const index: Migration[] = [
migration42,
migration43,
migration44,
migration45,
];
export default index;
// AUTO-GENERATED using `gulp buildScriptIndexes`

View File

@ -1,11 +1,18 @@
// Takes a directory of TypeScript files and generate an index from it.
const utils = require('../utils');
const glob = require('glob');
const rootDir = utils.rootDir();
async function processDirectory(dir) {
async function processDirectory(dir, indexFilePath = null, typeScriptType = null, imports = null, importNameTemplate = null, exportNameTemplate = null) {
if (!indexFilePath) indexFilePath = `${dir}/index.ts`;
if (!typeScriptType) typeScriptType = 'any';
if (!importNameTemplate) importNameTemplate = '* as FILE_NAME';
if (!exportNameTemplate) exportNameTemplate = 'FILE_NAME';
const tsFiles = glob.sync('{**/*.ts,**/*.tsx}', {
cwd: dir,
}).filter(f => f !== 'index.ts');
}).filter(f => `${dir}/${f}` !== indexFilePath);
tsFiles.sort();
@ -13,16 +20,21 @@ async function processDirectory(dir) {
for (const tsFile of tsFiles) {
const f = utils.getFilename(tsFile);
fileContent.push(`import * as ${f} from './${f}';`);
fileContent.push(`import ${importNameTemplate.replace(/FILE_NAME/g, f)} from './${f}';`);
}
fileContent.push('');
fileContent.push('const index:any[] = [');
if (imports) {
fileContent.push(imports);
fileContent.push('');
}
fileContent.push(`const index:${typeScriptType}[] = [`);
for (const tsFile of tsFiles) {
const f = utils.getFilename(tsFile);
fileContent.push(`\t${f},`);
fileContent.push(`\t${exportNameTemplate.replace(/FILE_NAME/g, f)},`);
}
fileContent.push('];');
@ -31,13 +43,11 @@ async function processDirectory(dir) {
fileContent.push('export default index;');
const destFile = `${dir}/index.ts`;
console.info(`Generating ${destFile}...`);
console.info(`Generating ${indexFilePath}...`);
await utils.insertContentIntoFile(
destFile,
'// AUTO-GENERATED using `gulp buildCommandIndex`',
indexFilePath,
'// AUTO-GENERATED using `gulp buildScriptIndexes`',
fileContent.join('\n'),
true,
);
@ -53,5 +63,14 @@ module.exports = {
await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteListControls/commands`);
await processDirectory(`${rootDir}/packages/app-desktop/gui/Sidebar/commands`);
await processDirectory(`${rootDir}/packages/lib/commands`);
await processDirectory(
`${rootDir}/packages/lib/services/database/migrations`,
null,
'Migration',
'import { Migration } from \'../types\';',
'migrationFILE_NAME',
'migrationFILE_NAME',
);
},
};

View File

@ -1,6 +1,6 @@
// Allow running that task "buildCommandIndex" without gulp
// Allow running that task "buildScriptIndexes" without gulp
const task = require('./buildCommandIndex.js');
const task = require('./buildScriptIndexes.js');
const main = async () => {
await task.fn();